22IMG ?= ghcr.io/kcl-lang/flux-kcl-controller:v0.1.0
33# Produce CRDs that work back to Kubernetes 1.16
44CRD_OPTIONS ?= crd:crdVersions=v1
5+ SOURCE_VER ?= $(shell go list -m all | grep github.com/fluxcd/source-controller/api | awk '{print $$2}')
6+
7+ # Use the same version of SOPS already referenced on go.mod
8+ SOPS_VER := $(shell go list -m all | grep github.com/getsops/sops | awk '{print $$2}')
59
610# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
711ifeq (,$(shell go env GOBIN) )
1014GOBIN =$(shell go env GOBIN)
1115endif
1216
17+ # Allows for defining additional Go test args, e.g. '-tags integration'.
18+ GO_TEST_ARGS ?=
1319# Allows for defining additional Docker buildx arguments, e.g. '--push'.
1420BUILD_ARGS ?=
1521# Architectures to build images for.
1622BUILD_PLATFORMS ?= linux/amd64
17-
1823# Architecture to use envtest with
1924ENVTEST_ARCH ?= amd64
25+ # Paths to download the CRD dependencies at.
26+ GITREPO_CRD ?= config/crd/bases/gitrepositories.yaml
27+ BUCKET_CRD ?= config/crd/bases/buckets.yaml
28+ OCIREPO_CRD ?= config/crd/bases/ocirepositories.yaml
29+
30+ # Keep a record of the version of the downloaded source CRDs. It is used to
31+ # detect and download new CRDs when the SOURCE_VER changes.
32+ SOURCE_CRD_VER =bin/.src-crd-$(SOURCE_VER )
33+
34+ PACKAGE ?= github.com/kcl-lang/flux-kcl-controller
35+ INPUT_DIRS := $(PACKAGE ) /api/v1alpha1
36+ BOILERPLATE_PATH := ${PWD}/hack/boilerplate.go.txt
37+
38+ # API (doc) generation utilities
39+ GEN_API_REF_DOCS_VERSION ?= e327d0730470cbd61b06300f81c5fcf91c23c113
2040
2141all : manager
2242
2343# Run tests
2444KUBEBUILDER_ASSETS? ="$(shell $(ENVTEST ) --arch=$(ENVTEST_ARCH ) use -i $(ENVTEST_KUBERNETES_VERSION ) --bin-dir=$(ENVTEST_ASSETS_DIR ) -p path) "
25- test : generate tidy fmt vet manifests install-envtest
45+ test : generate tidy fmt vet manifests download-crd-deps install-envtest $( SOPS )
2646 KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS ) go test ./... -coverprofile cover.out
2747
2848# Build manager binary
@@ -33,6 +53,24 @@ manager: generate fmt vet
3353run : generate fmt vet manifests
3454 go run ./cmd/main.go
3555
56+ # Delete previously downloaded CRDs and record the new version of the source
57+ # CRDs.
58+ $(SOURCE_CRD_VER ) :
59+ rm -f bin/.src-crd*
60+ $(MAKE ) cleanup-crd-deps
61+ if ! test -d " bin" ; then mkdir -p bin; fi
62+ touch $(SOURCE_CRD_VER )
63+
64+ # Download the CRDs the controller depends on FluxCD GitRepo, OCIRepo and Bucket.
65+ download-crd-deps : $(SOURCE_CRD_VER )
66+ curl -s https://raw.githubusercontent.com/fluxcd/source-controller/${SOURCE_VER} /config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml -o $(GITREPO_CRD )
67+ curl -s https://raw.githubusercontent.com/fluxcd/source-controller/${SOURCE_VER} /config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml -o $(BUCKET_CRD )
68+ curl -s https://raw.githubusercontent.com/fluxcd/source-controller/${SOURCE_VER} /config/crd/bases/source.toolkit.fluxcd.io_ocirepositories.yaml -o $(OCIREPO_CRD )
69+
70+ # Delete the downloaded CRD dependencies.
71+ cleanup-crd-deps :
72+ rm -f $(GITREPO_CRD ) $(BUCKET_CRD ) $(OCIREPO_CRD )
73+
3674# Install CRDs into a cluster
3775install : manifests
3876 kustomize build config/crd | kubectl apply -f -
@@ -46,14 +84,22 @@ deploy: manifests
4684 cd config/manager && kustomize edit set image kcl-controller=${IMG}
4785 kustomize build config/default | kubectl apply -f -
4886
87+ # Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
88+ dev-deploy : manifests
89+ mkdir -p config/dev && cp config/default/* config/dev
90+ cd config/dev && kustomize edit set image fluxcd/kustomize-controller=${IMG}
91+ kustomize build config/dev | kubectl apply -f -
92+ rm -rf config/dev
93+
4994# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
5095undeploy :
5196 cd config/manager && kustomize edit set image kcl-controller=${IMG}
5297 kustomize build config/default | kubectl delete -f -
5398
5499# Generate manifests e.g. CRD, RBAC etc.
55- manifests : controller-gen
100+ manifests : controller-gen deepcopy-gen
56101 $(CONTROLLER_GEN ) $(CRD_OPTIONS ) rbac:roleName=source-reader webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
102+ $(DEEPCOPY_GEN ) --input-dirs=$(INPUT_DIRS ) --output-file-base=zz_generated.deepcopy --go-header-file=${BOILERPLATE_PATH}
57103
58104# Run go tidy to cleanup go.mod
59105tidy :
@@ -72,8 +118,9 @@ build:
72118 go build ./...
73119
74120# Generate code
75- generate : controller-gen
121+ generate : controller-gen deepcopy-gen
76122 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
123+ $(DEEPCOPY_GEN ) --input-dirs=$(INPUT_DIRS ) --output-file-base=zz_generated.deepcopy --go-header-file=${BOILERPLATE_PATH}
77124
78125# Build the docker image
79126docker-build :
@@ -101,12 +148,22 @@ CONTROLLER_GEN_VERSION ?= v0.16.1
101148controller-gen : # # Download controller-gen locally if necessary.
102149 $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION ) )
103150
151+ DEEPCOPY_GEN = $(shell pwd) /bin/deepcopy-gen
152+ DEEPCOPY_GEN_VERSION ?= v0.29.0
153+ .PHONY : deepcopy-gen
154+ deepcopy-gen : # # Download controller-gen locally if necessary.
155+ $(call go-install-tool,$(DEEPCOPY_GEN ) ,k8s.io/code-generator/cmd/deepcopy-gen@$(DEEPCOPY_GEN_VERSION ) )
156+
104157ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
105158ENVTEST_KUBERNETES_VERSION? =latest
106159install-envtest : setup-envtest
107160 mkdir -p ${ENVTEST_ASSETS_DIR}
108161 $(ENVTEST ) use $(ENVTEST_KUBERNETES_VERSION ) --arch=$(ENVTEST_ARCH ) --bin-dir=$(ENVTEST_ASSETS_DIR )
109162
163+ SOPS = $(GOBIN ) /sops
164+ $(SOPS ) : # # Download latest sops binary if none is found.
165+ $(call go-install-tool,$(SOPS ) ,github.com/getsops/sops/v3/cmd/sops@$(SOPS_VER ) )
166+
110167ENVTEST = $(shell pwd) /bin/setup-envtest
111168.PHONY : envtest
112169setup-envtest : # # Download envtest-setup locally if necessary.
0 commit comments