mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
163 lines
4.7 KiB
Makefile
163 lines
4.7 KiB
Makefile
# Current Operator version
|
|
VERSION ?= 0.0.1
|
|
# Default bundle image tag
|
|
BUNDLE_IMG ?= controller-bundle:$(VERSION)
|
|
# Options for 'bundle-build'
|
|
ifneq ($(origin CHANNELS), undefined)
|
|
BUNDLE_CHANNELS := --channels=$(CHANNELS)
|
|
endif
|
|
ifneq ($(origin DEFAULT_CHANNEL), undefined)
|
|
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
|
|
endif
|
|
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
|
|
|
|
# Image URL to use all building/pushing image targets
|
|
IMG ?= controller:latest
|
|
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
|
|
CRD_OPTIONS ?= "crd:trivialVersions=true"
|
|
|
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
|
ifeq (,$(shell go env GOBIN))
|
|
GOBIN=$(shell go env GOPATH)/bin
|
|
else
|
|
GOBIN=$(shell go env GOBIN)
|
|
endif
|
|
|
|
all: manager
|
|
|
|
# Run tests
|
|
test: generate fmt vet manifests
|
|
go test ./... -coverprofile cover.out
|
|
|
|
# Build manager binary
|
|
manager: generate fmt vet
|
|
go build -o bin/manager main.go
|
|
|
|
# Run against the configured Kubernetes cluster in ~/.kube/config
|
|
run: generate fmt vet manifests
|
|
go run ./main.go
|
|
|
|
# Install CRDs into a cluster
|
|
install: manifests kustomize
|
|
$(KUSTOMIZE) build config/crd | kubectl apply -f -
|
|
|
|
# Uninstall CRDs from a cluster
|
|
uninstall: manifests kustomize
|
|
$(KUSTOMIZE) build config/crd | kubectl delete -f -
|
|
|
|
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
|
|
deploy: manifests kustomize
|
|
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
|
|
$(KUSTOMIZE) build config/default | kubectl apply -f -
|
|
|
|
# Generate manifests e.g. CRD, RBAC etc.
|
|
manifests: controller-gen
|
|
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
|
|
|
|
# Run go fmt against code
|
|
fmt:
|
|
go fmt ./...
|
|
|
|
# Run go vet against code
|
|
vet:
|
|
go vet ./...
|
|
|
|
# Generate code
|
|
generate: controller-gen
|
|
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
|
|
|
|
# Build the docker image
|
|
docker-build: test
|
|
docker build . -t ${IMG}
|
|
|
|
# Push the docker image
|
|
docker-push:
|
|
docker push ${IMG}
|
|
|
|
# Build kk binary
|
|
SHELL = /usr/bin/env bash
|
|
|
|
GIT_COMMIT = $(shell git rev-parse HEAD)
|
|
GIT_SHA = $(shell git rev-parse --short HEAD)
|
|
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
|
|
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
|
|
|
|
VERSION_METADATA = unreleased
|
|
VERSION = latest
|
|
# Clear the "unreleased" string in BuildMetadata
|
|
ifneq ($(GIT_TAG),)
|
|
VERSION_METADATA =
|
|
VERSION = ${GIT_TAG}
|
|
endif
|
|
|
|
LDFLAGS += -X github.com/kubesphere/kubekey/version.version=${VERSION}
|
|
LDFLAGS += -X github.com/kubesphere/kubekey/version.metadata=${VERSION_METADATA}
|
|
LDFLAGS += -X github.com/kubesphere/kubekey/version.gitCommit=${GIT_COMMIT}
|
|
LDFLAGS += -X github.com/kubesphere/kubekey/version.gitTreeState=${GIT_DIRTY}
|
|
|
|
binary:
|
|
docker run --rm \
|
|
-v $(shell pwd):/usr/src/myapp \
|
|
-e GOOS=linux \
|
|
-e GOARCH=amd64 \
|
|
-e CGO_ENABLED=0 \
|
|
-e GO111MODULE=on \
|
|
-w /usr/src/myapp golang:1.14 \
|
|
go build -ldflags '$(LDFLAGS)' -v -o output/linux/amd64/kk ./main.go # linux
|
|
sha256sum output/linux/amd64/kk || shasum -a 256 output/linux/amd64/kk
|
|
|
|
docker run --rm \
|
|
-v $(shell pwd):/usr/src/myapp \
|
|
-e GOOS=linux \cd out
|
|
-e GOARCH=arm64 \
|
|
-e CGO_ENABLED=0 \
|
|
-e GO111MODULE=on \
|
|
-w /usr/src/myapp golang:1.14 \
|
|
go build -ldflags '$(LDFLAGS)' -v -o output/linux/arm64/kk ./main.go # linux
|
|
sha256sum output/linux/arm64/kk || shasum -a 256 output/linux/arm64/kk
|
|
|
|
# find or download controller-gen
|
|
# download controller-gen if necessary
|
|
controller-gen:
|
|
ifeq (, $(shell which controller-gen))
|
|
@{ \
|
|
set -e ;\
|
|
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
|
|
cd $$CONTROLLER_GEN_TMP_DIR ;\
|
|
go mod init tmp ;\
|
|
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\
|
|
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
|
|
}
|
|
CONTROLLER_GEN=$(GOBIN)/controller-gen
|
|
else
|
|
CONTROLLER_GEN=$(shell which controller-gen)
|
|
endif
|
|
|
|
kustomize:
|
|
ifeq (, $(shell which kustomize))
|
|
@{ \
|
|
set -e ;\
|
|
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
|
|
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
|
|
go mod init tmp ;\
|
|
go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\
|
|
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
|
|
}
|
|
KUSTOMIZE=$(GOBIN)/kustomize
|
|
else
|
|
KUSTOMIZE=$(shell which kustomize)
|
|
endif
|
|
|
|
# Generate bundle manifests and metadata, then validate generated files.
|
|
.PHONY: bundle
|
|
bundle: manifests
|
|
operator-sdk generate kustomize manifests -q
|
|
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
|
|
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
|
|
operator-sdk bundle validate ./bundle
|
|
|
|
# Build the bundle image.
|
|
.PHONY: bundle-build
|
|
bundle-build:
|
|
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
|