-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
executable file
·246 lines (203 loc) · 9.37 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# 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 ?= localhost:32000/sumologic/tailing-sidecar-operator:latest
DOCKERFILE ?= Dockerfile
# Image URL for tailing sidecar
TAILING_SIDECAR_IMG ?= localhost:32000/sumologic/tailing-sidecar:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:crdVersions={v1}"
# 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
# UBI image variables
RELEASE_NUMBER ?= "1"
# Run tests
# Set default shell as bash
SHELL := /bin/bash
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
all: docker-build docker-push deploy
test: generate fmt vet manifests
mkdir -p $(ENVTEST_ASSETS_DIR)
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.6.3/hack/setup-envtest.sh
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
clean:
git checkout -- config/default/manager_patch.yaml
rm -f config/default/manager_patch.yaml.backup
rm -rf testbin
# Build manager binary
manager: generate fmt vet
go build -o bin/manager main.go ./config.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run ./main.go ./config.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
sed -i.backup "s#sumologic/tailing-sidecar:latest#${TAILING_SIDECAR_IMG}#g" config/default/manager_patch.yaml
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
kubectl wait --for=condition=ready --timeout 300s pod -l control-plane=tailing-sidecar-operator -n tailing-sidecar-system
# Remove resources created with make deploy
teardown:
$(KUSTOMIZE) build config/default | kubectl delete -f -
# Deploy examples
deploy-examples:
kubectl apply -f examples/pod_with_annotations.yaml
kubectl apply -f examples/statefulset_with_annotations.yaml
kubectl apply -f examples/deployment_with_annotations.yaml
kubectl apply -f examples/daemonset_with_annotations.yaml
kubectl apply -f examples/pod_without_annotations.yaml
kubectl apply -f examples/cr_with_resources.yaml
kubectl apply -f examples/pod_with_tailing_sidecar_config_resources.yaml
# Deploy examples update
deploy-examples-update:
kubectl apply -f examples/pod_with_annotations_update.yaml --force
kubectl apply -f examples/deployment_with_annotations_update.yaml --force
deploy-example-with-cr:
kubectl apply -f config/samples/tailing-sidecar_v1_tailingsidecar.yaml -n tailing-sidecar-system
kubectl apply -f examples/pod_with_tailing_sidecar_config.yaml
deploy-example-with-cr-update:
kubectl apply -f config/samples/tailing-sidecar-update_v1_tailingsidecar.yaml -n tailing-sidecar-system
kubectl apply -f examples/pod_with_tailing_sidecar_config_update.yaml --force
# Remove resources created with make deploy-examples
teardown-examples:
kubectl delete -n tailing-sidecar-system pod pod-without-annotations
kubectl delete -n tailing-sidecar-system pod pod-with-annotations
kubectl delete -n tailing-sidecar-system statefulset statefulset-with-annotations
kubectl delete -n tailing-sidecar-system deployment deployment-with-annotations
kubectl delete -n tailing-sidecar-system daemonset daemonset-with-annotations
kubectl delete -n tailing-sidecar-system TailingSidecarConfig tailingsidecar-sample
kubectl delete -n tailing-sidecar-system pod pod-with-tailing-sidecar-config-resources
kubectl delete -n tailing-sidecar-system TailingSidecarConfig tailingsidecar-sample
# Check if logs from resources created with make deploy-examples have proper content
test-examples:
tests/test.sh
# Check if sidecar has configured resources
test-examples-resources:
tests/test-resources.sh
# Check if logs from resources created with make deploy-examples-update have proper content
test-examples-update:
tests/test-update.sh
# Check resources created with make deploy-examples
check-examples:
kubectl get all -n tailing-sidecar-system
kubectl logs pod-with-annotations tailing-sidecar-0 -n tailing-sidecar-system --tail 5
kubectl logs pod-with-annotations named-container -n tailing-sidecar-system --tail 5
kubectl logs statefulset-with-annotations-0 my-named-sidecar -n tailing-sidecar-system --tail 5
kubectl logs statefulset-with-annotations-0 tailing-sidecar-1 -n tailing-sidecar-system --tail 5
kubectl logs $(shell kubectl get pod -l app=deployment-with-annotations -n tailing-sidecar-system -o jsonpath="{.items[0].metadata.name}") \
tailing-sidecar-0 -n tailing-sidecar-system --tail 5
kubectl logs $(shell kubectl get pod -l app=deployment-with-annotations -n tailing-sidecar-system -o jsonpath="{.items[0].metadata.name}") \
tailing-sidecar-1 -n tailing-sidecar-system --tail 5
kubectl logs $(shell kubectl get pod -l app=deployment-with-annotations -n tailing-sidecar-system -o jsonpath="{.items[1].metadata.name}") \
tailing-sidecar-0 -n tailing-sidecar-system --tail 5
kubectl logs $(shell kubectl get pod -l app=deployment-with-annotations -n tailing-sidecar-system -o jsonpath="{.items[1].metadata.name}") \
tailing-sidecar-1 -n tailing-sidecar-system --tail 5
kubectl logs $(shell kubectl get pod -l app=deployment-with-annotations -n tailing-sidecar-system -o jsonpath="{.items[2].metadata.name}") \
tailing-sidecar-0 -n tailing-sidecar-system --tail 5
kubectl logs $(shell kubectl get pod -l app=deployment-with-annotations -n tailing-sidecar-system -o jsonpath="{.items[2].metadata.name}") \
tailing-sidecar-1 -n tailing-sidecar-system --tail 5
# Check resources created with make deploy-examples-update
check-examples-update:
kubectl get all -n tailing-sidecar-system
kubectl logs pod-with-annotations tailing-sidecar-0 -n tailing-sidecar-system --tail 5
kubectl logs pod-with-annotations named-sidecar -n tailing-sidecar-system --tail 5
kubectl logs pod-with-annotations tailing-sidecar-1 -n tailing-sidecar-system --tail 5
kubectl logs $(shell kubectl get pod -l app=deployment-with-annotations -n tailing-sidecar-system -o jsonpath="{.items[0].metadata.name}") \
tailing-sidecar-0 -n tailing-sidecar-system --tail 5
# Deploy cert-manager
deploy-cert-manager:
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.11.0/cert-manager.yaml
kubectl wait --for=condition=ready --timeout 300s pod -l "app.kubernetes.io/instance=cert-manager" -n cert-manager
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role 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:
docker build . \
--build-arg RELEASE_NUMBER=$(RELEASE_NUMBER) \
--build-arg VERSION=$(VERSION) \
-f ${DOCKERFILE} \
-t ${IMG}
# Push the docker image
docker-push:
docker push ${IMG}
build-push-multiplatform:
docker buildx build \
--push \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--tag ${IMG} \
.
build-push-ubi:
$(MAKE) docker-build DOCKERFILE=${DOCKERFILE}.ubi IMG=${IMG}-ubi
$(MAKE) docker-push DOCKERFILE=${DOCKERFILE}.ubi IMG=${IMG}-ubi
CONTROLLER_TOOLS_VERSION ?= v0.15.0
# 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 install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) ;\
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 install sigs.k8s.io/kustomize/kustomize/[email protected] ;\
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 kustomize
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) .