-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
217 lines (167 loc) · 6.19 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#
# Datadog custom variables
#
BUILDINFOPKG=github.com/DataDog/extendeddaemonset/pkg/version
GIT_TAG?=$(shell git tag -l --contains HEAD | tail -1)
TAG_HASH=$(shell git tag | tail -1)_$(shell git rev-parse --short HEAD)
VERSION?=$(if $(GIT_TAG),$(GIT_TAG),$(TAG_HASH))
BUNDLE_VERSION?=$(VERSION:v%=%)
GIT_COMMIT?=$(shell git rev-parse HEAD)
DATE=$(shell date +%Y-%m-%d/%H:%M:%S )
LDFLAGS=-w -s -X ${BUILDINFOPKG}.Commit=${GIT_COMMIT} -X ${BUILDINFOPKG}.Version=${VERSION} -X ${BUILDINFOPKG}.BuildTime=${DATE}
GOARCH?=amd64
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
KUSTOMIZE = bin/kustomize
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(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 ?= datadog/extendeddaemonset:latest
IMG_CHECK ?= datadog/extendeddaemonset-check:latest
# 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: build test
build: manager kubectl-eds
# Run tests
test: build manifests verify-license gotest
gotest:
go test ./... -coverprofile cover.out
e2e: build manifests verify-license goe2e
# Runs e2e tests (expects a configured cluster)
goe2e: bin/kubebuilder-tools
go test --tags=e2e ./controllers -ginkgo.progress -ginkgo.v -test.v
# Build manager binary
manager: generate lint
go build -ldflags '${LDFLAGS}' -o bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate lint 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 && $(ROOT_DIR)/bin/kustomize edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
manifests: generate-manifests patch-crds
generate-manifests: controller-gen
$(CONTROLLER_GEN) crd rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases/v1
$(CONTROLLER_GEN) crd rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases/v1beta1
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Generate code
generate: controller-gen generate-openapi
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
# For use locally
docker-build: generate docker-build-ci docker-build-check-ci
# For use locally
docker-build-ci:
docker build . -t ${IMG} --build-arg LDFLAGS="${LDFLAGS}" --build-arg GOARCH="${GOARCH}"
# For use locally
docker-build-check-ci:
docker build . -t ${IMG_CHECK} -f check-eds.Dockerfile --build-arg LDFLAGS="${LDFLAGS}" --build-arg GOARCH="${GOARCH}"
# For use in Gitlab
docker-build-push-ci:
docker buildx build . -t ${IMG} --build-arg LDFLAGS="${LDFLAGS}" --build-arg GOARCH="${GOARCH}" --platform=linux/${GOARCH} --push
# For use in Gitlab
docker-build-push-check-ci:
docker buildx build . -t ${IMG_CHECK} -f check-eds.Dockerfile --build-arg LDFLAGS="${LDFLAGS}" --build-arg GOARCH="${GOARCH}" --platform=linux/${GOARCH} --push
# Push the docker images
docker-push: docker-push-img docker-push-check-img
docker-push-img:
docker push ${IMG}
docker-push-check-img:
docker push ${IMG_CHECK}
# find or download controller-gen
# download controller-gen if necessary
controller-gen: install-tools
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests bin/kustomize
./bin/operator-sdk generate kustomize manifests -q
cd config/manager && $(ROOT_DIR)/bin/kustomize edit set image controller=$(IMG)
./bin/kustomize build config/manifests | ./bin/operator-sdk generate bundle -q --overwrite --version $(BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS)
./bin/operator-sdk bundle validate ./bundle
# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
#
# Datadog Custom part
#
.PHONY: install-tools
install-tools: bin/golangci-lint bin/operator-sdk bin/yq bin/kubebuilder bin/kubebuilder-tools
.PHONY: generate-openapi
generate-openapi: bin/openapi-gen
./bin/openapi-gen --logtostderr --output-dir api/v1alpha1 --output-file zz_generated.openapi.go --output-pkg api/v1alpha1 --go-header-file hack/boilerplate.go.txt ./api/v1alpha1
.PHONY: patch-crds
patch-crds: bin/yq
./hack/patch-crds.sh
.PHONY: lint
lint: bin/golangci-lint fmt vet
./bin/golangci-lint run ./...
.PHONY: license
license: bin/wwhrd vendor
./hack/license.sh
.PHONY: verify-license
verify-license: bin/wwhrd vendor
./hack/verify-license.sh
.PHONY: tidy
tidy:
go mod tidy -v
.PHONY: vendor
vendor:
go work vendor
kubectl-eds: fmt vet lint
CGO_ENABLED=1 go build -ldflags '${LDFLAGS}' -o bin/kubectl-eds ./cmd/kubectl-eds/main.go
check-eds: fmt vet lint
go build -ldflags '${LDFLAGS}' -o bin/check-eds ./cmd/check-eds/main.go
bin/kubebuilder:
./hack/install-kubebuilder.sh 3.4.0 ./bin
bin/kubebuilder-tools:
./hack/install-kubebuilder-tools.sh 1.24.1
bin/openapi-gen:
go build -o ./bin/openapi-gen k8s.io/kube-openapi/cmd/openapi-gen
bin/yq:
./hack/install-yq.sh 3.3.0
bin/golangci-lint:
hack/install-golangci-lint.sh v1.61.0
bin/operator-sdk:
./hack/install-operator-sdk.sh v1.5.0
bin/wwhrd:
./hack/install-wwhrd.sh 0.2.4
bin/kustomize:
./hack/install-kustomize.sh ./bin