@@ -4,7 +4,7 @@ FB_IMG ?= kubesphere/fluent-bit:v1.8.3
4
4
OP_IMG ?= kubesphere/fluentbit-operator:$(VERSION )
5
5
AMD64 ?= -amd64
6
6
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
7
- CRD_OPTIONS ?= "crd:trivialVersions=true"
7
+ CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false "
8
8
9
9
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
10
10
ifeq (,$(shell go env GOBIN) )
13
13
GOBIN =$(shell go env GOBIN)
14
14
endif
15
15
16
- all : manager
16
+ # Setting SHELL to bash allows bash commands to be executed by recipes.
17
+ # This is a requirement for 'setup-envtest.sh' in the test target.
18
+ # Options are set to exit when a recipe line exits non-zero or a piped command fails.
19
+ SHELL = /usr/bin/env bash -o pipefail
20
+ .SHELLFLAGS = -ec
17
21
18
- # Run tests
19
- test : generate fmt vet manifests
20
- go test ./... -coverprofile cover.out
22
+ all : build
21
23
22
- # Build manager binary
23
- manager : generate fmt vet
24
- go build -o bin/manager cmd/manager/main.go
25
-
26
- binary :
27
- go build -o bin/manager cmd/manager/main.go
28
- go build -o bin/watcher cmd/fluent-bit-watcher/main.go
29
-
30
- verify : verify-crds
31
-
32
- verify-crds :
33
- sudo chmod a+x ./hack/verify-crds.sh && ./hack/verify-crds.sh
24
+ # #@ General
34
25
35
- # Run against the configured Kubernetes cluster in ~/.kube/config
36
- run : generate fmt vet manifests
37
- go run cmd/manager/main.go
38
-
39
- # Install CRDs into a cluster
40
- install : manifests
41
- kustomize build config/crd | kubectl apply -f -
26
+ # The help target prints out all targets with their descriptions organized
27
+ # beneath their categories. The categories are represented by '##@' and the
28
+ # target descriptions by '##'. The awk commands is responsible for reading the
29
+ # entire set of makefiles included in this invocation, looking for lines of the
30
+ # file as xyz: ## something, and then pretty-format the target and help. Then,
31
+ # if there's a line with ##@ something, that gets pretty-printed as a category.
32
+ # More info on the usage of ANSI control characters for terminal formatting:
33
+ # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
34
+ # More info on the awk command:
35
+ # http://linuxcommand.org/lc3_adv_awk.php
42
36
43
- # Uninstall CRDs from a cluster
44
- uninstall : manifests
45
- kustomize build config/crd | kubectl delete -f -
37
+ help : # # Display this help.
38
+ @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 )
46
39
47
- # Deploy controller in the configured Kubernetes cluster in ~/.kube/config
48
- deploy : manifests
49
- cd config/manager && kustomize edit set image controller=${IMG}
50
- kustomize build config/default | kubectl apply -f -
40
+ # #@ Development
51
41
52
- # Generate manifests e.g. CRD, RBAC etc.
53
- manifests : controller-gen
42
+ manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
54
43
$(CONTROLLER_GEN ) $(CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
55
44
kubectl kustomize config/crd | sed -e ' /creationTimestamp/d' > manifests/setup/fluentbit-operator-crd.yaml
56
45
kubectl kustomize manifests/setup | sed -e ' /creationTimestamp/d' > manifests/setup/setup.yaml
57
46
58
- # Run go fmt against code
59
- fmt :
47
+ generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
48
+ $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
49
+ ./hack/update-codegen.sh
50
+
51
+ fmt : # # Run go fmt against code.
60
52
go fmt ./...
61
53
62
- # Run go vet against code
63
- vet :
54
+ vet : # # Run go vet against code.
64
55
go vet ./...
65
56
66
- # Generate code
67
- generate : controller-gen
68
- $(CONTROLLER_GEN ) object:headerFile=./hack/boilerplate.go.txt paths=" ./..."
69
- ./hack/update-codegen.sh
57
+ ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
58
+ test : manifests generate fmt vet # # Run tests.
59
+ mkdir -p ${ENVTEST_ASSETS_DIR}
60
+ 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.8.3/hack/setup-envtest.sh
61
+ source ${ENVTEST_ASSETS_DIR} /setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR ) ; setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; go test ./... -coverprofile cover.out
62
+
63
+ # #@ Build
64
+
65
+ binary :
66
+ go build -o bin/manager cmd/manager/main.go
67
+ go build -o bin/watcher cmd/fluent-bit-watcher/main.go
70
68
71
- # Build all amd64/arm64 docker images
72
- build : test build-op
69
+ verify : verify-crds
70
+
71
+ verify-crds :
72
+ sudo chmod a+x ./hack/verify-crds.sh && ./hack/verify-crds.sh
73
+
74
+ build : generate fmt vet # # Build manager binary.
75
+ go build -o bin/manager cmd/manager/main.go
76
+
77
+ run : manifests generate fmt vet # # Run a controller from your host.
78
+ go run cmd/manager/main.go
73
79
74
80
# Build amd64/arm64 Fluent Bit container image
75
81
build-fb :
76
82
docker buildx build --push --platform linux/amd64,linux/arm64 -f cmd/fluent-bit-watcher/Dockerfile . -t ${FB_IMG}
77
83
78
84
# Build amd64/arm64 Fluent Bit Operator container image
79
- build-op :
85
+ build-op :
80
86
docker buildx build --push --platform linux/amd64,linux/arm64 -f cmd/manager/Dockerfile . -t ${OP_IMG}
81
87
82
88
# Build all amd64 docker images
@@ -87,26 +93,47 @@ build-fb-amd64:
87
93
docker build -f cmd/fluent-bit-watcher/Dockerfile . -t ${FB_IMG}${AMD64}
88
94
89
95
# Build amd64 Fluent Bit Operator container image
90
- build-op-amd64 :
96
+ build-op-amd64 :
91
97
docker build -f cmd/manager/Dockerfile . -t ${OP_IMG}${AMD64}
92
98
93
99
# Push the amd64 docker image
94
100
push-amd64 :
95
101
docker push ${OP_IMG}${AMD64}
96
102
97
- # find or download controller-gen
98
- # download controller-gen if necessary
99
- controller-gen :
100
- ifeq (, $(shell which controller-gen) )
101
- @{ \
102
- set -e ;\
103
- CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
104
- cd $$CONTROLLER_GEN_TMP_DIR ;\
105
- go mod init tmp ;\
106
- go install -v sigs.k8s.io/controller-tools/cmd/
[email protected] ;\
107
- rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
108
- }
109
- CONTROLLER_GEN =$(GOBIN ) /controller-gen
110
- else
111
- CONTROLLER_GEN =$(shell which controller-gen)
112
- endif
103
+ # #@ Deployment
104
+
105
+ install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
106
+ $(KUSTOMIZE ) build config/crd | kubectl apply -f -
107
+
108
+ uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
109
+ $(KUSTOMIZE ) build config/crd | kubectl delete -f -
110
+
111
+ deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
112
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
113
+ $(KUSTOMIZE ) build config/default | kubectl apply -f -
114
+
115
+ undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
116
+ $(KUSTOMIZE ) build config/default | kubectl delete -f -
117
+
118
+
119
+ CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
120
+ controller-gen : # # Download controller-gen locally if necessary.
121
+ $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/[email protected] )
122
+
123
+ KUSTOMIZE = $(shell pwd) /bin/kustomize
124
+ kustomize : # # Download kustomize locally if necessary.
125
+ $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
126
+
127
+ # go-get-tool will 'go get' any package $2 and install it to $1.
128
+ PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
129
+ define go-get-tool
130
+ @[ -f $(1 ) ] || { \
131
+ set -e ;\
132
+ TMP_DIR=$$(mktemp -d ) ;\
133
+ cd $$TMP_DIR ;\
134
+ go mod init tmp ;\
135
+ echo "Downloading $(2 ) " ;\
136
+ GOBIN=$(PROJECT_DIR ) /bin go get $(2 ) ;\
137
+ rm -rf $$TMP_DIR ;\
138
+ }
139
+ endef
0 commit comments