1
1
2
2
# Image URL to use all building/pushing image targets
3
3
IMG ?= controller:latest
4
- # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5
- CRD_OPTIONS ?= "crd"
4
+ # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5
+ ENVTEST_K8S_VERSION = 1.27.1
6
6
7
7
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8
8
ifeq (,$(shell go env GOBIN) )
11
11
GOBIN =$(shell go env GOBIN)
12
12
endif
13
13
14
- all : manager api-docs seals charts
14
+ # CONTAINER_TOOL defines the container tool to be used for building images.
15
+ # Be aware that the target commands are only tested with Docker which is
16
+ # scaffolded by default. However, you might want to replace it to use other
17
+ # tools. (i.e. podman)
18
+ CONTAINER_TOOL ?= docker
19
+
20
+ # Setting SHELL to bash allows bash commands to be executed by recipes.
21
+ # Options are set to exit when a recipe line exits non-zero or a piped command fails.
22
+ SHELL = /usr/bin/env bash -o pipefail
23
+ .SHELLFLAGS = -ec
24
+
25
+ .PHONY : all
26
+ all : build api-docs charts
27
+
28
+ # #@ General
29
+
30
+ # The help target prints out all targets with their descriptions organized
31
+ # beneath their categories. The categories are represented by '##@' and the
32
+ # target descriptions by '##'. The awk commands is responsible for reading the
33
+ # entire set of makefiles included in this invocation, looking for lines of the
34
+ # file as xyz: ## something, and then pretty-format the target and help. Then,
35
+ # if there's a line with ##@ something, that gets pretty-printed as a category.
36
+ # More info on the usage of ANSI control characters for terminal formatting:
37
+ # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
38
+ # More info on the awk command:
39
+ # http://linuxcommand.org/lc3_adv_awk.php
40
+
41
+ .PHONY : help
42
+ help : # # Display this help.
43
+ @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
44
+
45
+ # #@ Development
46
+
47
+ .PHONY : manifests
48
+ manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
49
+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
50
+
51
+ .PHONY : generate
52
+ generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
53
+ $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
54
+
55
+ .PHONY : fmt
56
+ fmt : # # Run go fmt against code.
57
+ go fmt ./...
58
+
59
+ .PHONY : vet
60
+ vet : # # Run go vet against code.
61
+ go vet ./...
15
62
16
- # Run tests
17
- ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
18
- test : generate fmt vet manifests
19
- mkdir -p ${ENVTEST_ASSETS_DIR}
20
- test -f ${ENVTEST_ASSETS_DIR} /setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR} /setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.14.1/hack/setup-envtest.sh
21
- source ${ENVTEST_ASSETS_DIR} /setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR ) ; setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; go test ./... -coverprofile cover.out
63
+ .PHONY : test
64
+ test : manifests generate fmt vet envtest # # Run tests.
65
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test ./... -coverprofile cover.out
22
66
23
- # Build manager binary
24
- manager : generate fmt vet
25
- go build -o bin/manager main.go
67
+ # #@ Build
26
68
27
- seals :
69
+ .PHONY : build
70
+ build : manifests generate fmt vet # # Build manager binary.
71
+ go build -o bin/manager cmd/main.go
28
72
go build -o bin/seals cmd/seals/main.go
29
73
30
74
cli :
@@ -39,95 +83,105 @@ cli:
39
83
GOOS=linux GOARCH=arm64 go build -o build/linux/arm64/seals cmd/seals/main.go
40
84
cat build/linux/arm64/seals | gzip > build/linux/arm64/seals.gz
41
85
42
- # Run against the configured Kubernetes cluster in ~/.kube/config
43
- run : generate fmt vet manifests
44
- go run ./main.go
45
-
46
- # Install CRDs into a cluster
47
- install : manifests kustomize
48
- $(KUSTOMIZE ) build config/crd | kubectl apply -f -
49
-
50
- # Uninstall CRDs from a cluster
51
- uninstall : manifests kustomize
52
- $(KUSTOMIZE ) build config/crd | kubectl delete -f -
53
-
54
- # Deploy controller in the configured Kubernetes cluster in ~/.kube/config
55
- deploy : manifests kustomize
56
- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
57
- $(KUSTOMIZE ) build config/default | kubectl apply -f -
58
-
59
- # UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
60
- undeploy :
61
- $(KUSTOMIZE ) build config/default | kubectl delete -f -
62
-
63
- # Generate manifests e.g. CRD, RBAC etc.
64
- manifests : controller-gen
65
- $(CONTROLLER_GEN ) $(CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
66
-
67
- # Generate API reference documentation
68
- api-docs : gen-crd-api-reference-docs
69
- $(API_REF_GEN ) -api-dir=./apis/secrets/v1beta1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/SealedSecret.md
70
-
71
- # Run go fmt against code
72
- fmt :
73
- go fmt ./...
74
-
75
- # Run go vet against code
76
- vet :
77
- go vet ./...
78
-
79
- # Generate code
80
- generate : controller-gen
81
- $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
82
-
83
- # Build the docker image
84
- docker-build : test
85
- docker build -t ${IMG} .
86
-
87
- # Push the docker image
88
- docker-push :
89
- docker push ${IMG}
90
-
91
- # Download controller-gen locally if necessary
92
- controller-gen :
93
- ifeq (, $(shell which controller-gen) )
94
- @{ \
95
- set -e ;\
96
- CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
97
- cd $$CONTROLLER_GEN_TMP_DIR ;\
98
- go mod init tmp ;\
99
- go install sigs.k8s.io/controller-tools/cmd/
[email protected] ;\
100
- rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
101
- }
102
- CONTROLLER_GEN =$(GOBIN ) /controller-gen
103
- else
104
- CONTROLLER_GEN =$(shell which controller-gen)
86
+ .PHONY : run
87
+ run : manifests generate fmt vet # # Run a controller from your host.
88
+ go run ./cmd/main.go
89
+
90
+ # If you wish built the manager image targeting other platforms you can use the --platform flag.
91
+ # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
92
+ # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
93
+ .PHONY : docker-build
94
+ docker-build : test # # Build docker image with the manager.
95
+ $(CONTAINER_TOOL ) build -t ${IMG} .
96
+
97
+ .PHONY : docker-push
98
+ docker-push : # # Push docker image with the manager.
99
+ $(CONTAINER_TOOL ) push ${IMG}
100
+
101
+ # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
102
+ # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
103
+ # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
104
+ # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
105
+ # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
106
+ # To properly provided solutions that supports more than one platform you should use this option.
107
+ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
108
+ .PHONY : docker-buildx
109
+ docker-buildx : test # # Build and push docker image for the manager for cross-platform support
110
+ # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
111
+ sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
112
+ - $(CONTAINER_TOOL ) buildx create --name project-v3-builder
113
+ $(CONTAINER_TOOL ) buildx use project-v3-builder
114
+ - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
115
+ - $(CONTAINER_TOOL ) buildx rm project-v3-builder
116
+ rm Dockerfile.cross
117
+
118
+ # #@ Deployment
119
+
120
+ ifndef ignore-not-found
121
+ ignore-not-found = false
105
122
endif
106
123
124
+ .PHONY : install
125
+ install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
126
+ $(KUSTOMIZE ) build config/crd | $(KUBECTL ) apply -f -
107
127
128
+ .PHONY : uninstall
129
+ uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
130
+ $(KUSTOMIZE ) build config/crd | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
108
131
132
+ .PHONY : deploy
133
+ deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
134
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
135
+ $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
136
+
137
+ .PHONY : undeploy
138
+ undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
139
+ $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
140
+
141
+ # #@ Build Dependencies
142
+
143
+ # # Location to install dependencies to
144
+ LOCALBIN ?= $(shell pwd) /bin
145
+ $(LOCALBIN ) :
146
+ mkdir -p $(LOCALBIN )
147
+
148
+ # # Tool Binaries
149
+ KUBECTL ?= kubectl
150
+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
151
+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
152
+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
153
+
154
+ # # Tool Versions
155
+ KUSTOMIZE_VERSION ?= v5.0.1
156
+ CONTROLLER_TOOLS_VERSION ?= v0.12.0
157
+
158
+ .PHONY : kustomize
159
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
160
+ $(KUSTOMIZE ) : $(LOCALBIN )
161
+ @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
162
+ echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
163
+ rm -rf $(LOCALBIN ) /kustomize; \
164
+ fi
165
+ test -s $(LOCALBIN ) /kustomize || GOBIN=$(LOCALBIN ) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION )
166
+
167
+ .PHONY : controller-gen
168
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
169
+ $(CONTROLLER_GEN ) : $(LOCALBIN )
170
+ test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
171
+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
172
+
173
+ .PHONY : envtest
174
+ envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
175
+ $(ENVTEST ) : $(LOCALBIN )
176
+ test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
109
177
110
- # Download kustomize locally if necessary
111
- KUSTOMIZE = $(shell pwd) /bin/kustomize
112
- kustomize :
113
- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
114
178
115
179
charts : manifests
116
180
cp config/crd/bases/* charts/k8s-gitops-secrets-controller/crds
117
181
118
- # go-get-tool will 'go get' any package $2 and install it to $1.
119
- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
120
- define go-get-tool
121
- @[ -f $(1 ) ] || { \
122
- set -e ;\
123
- TMP_DIR=$$(mktemp -d ) ;\
124
- cd $$TMP_DIR ;\
125
- go mod init tmp ;\
126
- echo "Downloading $(2 ) " ;\
127
- GOBIN=$(PROJECT_DIR ) /bin go get $(2 ) ;\
128
- rm -rf $$TMP_DIR ;\
129
- }
130
- endef
182
+ # Generate API reference documentation
183
+ api-docs : gen-crd-api-reference-docs
184
+ $(API_REF_GEN ) -api-dir=./api/secrets/v1beta1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/SealedSecret.md
131
185
132
186
# Find or download gen-crd-api-reference-docs
133
187
gen-crd-api-reference-docs :
0 commit comments