Skip to content

Commit 3e172b5

Browse files
authored
Evolve Makefile, improve developer experience, update documentation (#101)
1 parent 4f114fe commit 3e172b5

File tree

5 files changed

+68
-56
lines changed

5 files changed

+68
-56
lines changed

.github/workflows/make-test-e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
- uses: helm/kind-action@v1.9.0
2121
with:
2222
cluster_name: kind
23-
- run: make test-e2e
23+
- run: make test-e2e KIND_CLUSTER_NAME=kind

HOW-TO-START-DEVELOPMENT.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,29 @@
66
## Build your develop environment
77

88
### Easy way
9-
1. Download and install [kind](https://kind.sigs.k8s.io/docs/user/quick-start/#creating-a-cluster).
10-
2. Create lind cluster `kind create cluster --name etcd-operator-kind`.
11-
3. Switch kubectl context to kind `kubectl config use-context kind-etcd-operator-kind`. Be attentive to avoid damaging your production environment.
12-
4. Install cert-manager (it creates certificate k8s secrets). Refer to the [docs](https://cert-manager.io/docs/installation/helm/#4-install-cert-manager).
13-
5. Build docker image *controller:latest* `make docker-build`.
14-
6. Retag image to upload to kind cluster with correct name `docker tag controller:latest ghcr.io/aenix-io/etcd-operator:latest`.
15-
7. Load image to kind cluster `kind load docker-image --name etcd-operator-kind ghcr.io/aenix-io/etcd-operator:latest`.
16-
8. Install CRDs `make install`.
17-
9. Deploy operator, RBAC, webhook certs `make deploy`.
18-
19-
To deploy your code changes
20-
1. Rebuild the image `make docker-build`.
21-
2. Retag image to upload to kind cluster with correct name `docker tag controller:latest ghcr.io/aenix-io/etcd-operator:latest`.
22-
3. Load image to kind cluster `kind load docker-image --name etcd-operator-kind ghcr.io/aenix-io/etcd-operator:latest`.
23-
4. Redeploy yaml manifests if necessary `make deploy`.
24-
5. Restart etcd-operator `kubectl rollout restart -n etcd-operator-system deploy/etcd-operator-controller-manager`.
9+
1. Create and prepare kind cluster:
10+
```shell
11+
make kind-prepare
12+
```
13+
2. Install CRDs into kind cluster
14+
```shell
15+
make install
16+
```
17+
18+
3. Build image and load it into kind cluster, deploy etcd-operator, RBAC, webhook certs
19+
```shell
20+
make deploy
21+
```
22+
23+
4. To deploy your code changes, redeploy etcd-operator:
24+
```shell
25+
make redeploy
26+
```
27+
28+
5. To clean up after all, delete kind cluster:
29+
```shell
30+
make kind-delete
31+
```
2532

2633
### Advanced way
2734
Using *easy way* you will not be able to debug golang code locally and every change will be necessary to build as an image, upload to the cluster and then restart operator.

Makefile

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ run: manifests generate fmt vet ## Run a controller from your host.
9494
docker-build: ## Build docker image with the manager.
9595
$(CONTAINER_TOOL) build -t ${IMG} .
9696

97-
.PHONY: docker-push
98-
docker-push: ## Push docker image with the manager.
99-
$(CONTAINER_TOOL) push ${IMG}
100-
10197
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
10298
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
10399
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
@@ -127,6 +123,12 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi
127123

128124
##@ Deployment
129125

126+
KIND_CLUSTER_NAME ?= etcd-operator-kind
127+
NAMESPACE ?= etcd-operator-system
128+
129+
PROMETHEUS_OPERATOR_VERSION ?= v0.72.0
130+
CERT_MANAGER_VERSION ?= v1.14.4
131+
130132
ifndef ignore-not-found
131133
ignore-not-found = false
132134
endif
@@ -137,30 +139,44 @@ install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~
137139

138140
.PHONY: uninstall
139141
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.
140-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
142+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete -n $(NAMESPACE) --ignore-not-found=$(ignore-not-found) -f -
141143

142144
.PHONY: deploy
143-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
145+
deploy: manifests kustomize kind-load ## Deploy controller to the K8s cluster specified in ~/.kube/config.
144146
cd config/manager && $(KUSTOMIZE) edit set image ghcr.io/aenix-io/etcd-operator=${IMG}
145-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
147+
$(KUSTOMIZE) build config/default | $(KUBECTL) -n $(NAMESPACE) apply -f -
146148

147149
.PHONY: undeploy
148150
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
149-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
151+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete -n $(NAMESPACE) --ignore-not-found=$(ignore-not-found) -f -
150152

151-
# Build and upload docker image to the local Kind cluster
152-
.PHONY: docker-load
153-
docker-load: docker-build
154-
kind load docker-image ${IMG} --name etcd-operator-kind
155-
156-
# Redeploy controller with new docker image
157153
.PHONY: redeploy
158-
redeploy: manifests kustomize docker-build docker-load
159-
$(KUBECTL) config use-context kind-etcd-operator-kind
160-
# deploy configs
161-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
154+
redeploy: deploy ## Redeploy controller with new docker image.
162155
# force recreate pods
163-
$(KUBECTL) rollout restart -n etcd-operator-system deploy/etcd-operator-controller-manager
156+
$(KUBECTL) rollout restart -n $(NAMESPACE) deploy/etcd-operator-controller-manager
157+
158+
.PHONY: kind-load
159+
kind-load: docker-build kind ## Build and upload docker image to the local Kind cluster.
160+
$(KIND) load docker-image ${IMG} --name $(KIND_CLUSTER_NAME)
161+
162+
.PHONY: kind-create
163+
kind-create: kind ## Create kubernetes cluster using Kind.
164+
@if ! $(KIND) get clusters | grep -q $(KIND_CLUSTER_NAME); then \
165+
$(KIND) create cluster --name $(KIND_CLUSTER_NAME); \
166+
fi
167+
168+
.PHONY: kind-delete
169+
kind-delete: kind ## Create kubernetes cluster using Kind.
170+
@if $(KIND) get clusters | grep -q $(KIND_CLUSTER_NAME); then \
171+
$(KIND) delete cluster --name $(KIND_CLUSTER_NAME); \
172+
fi
173+
174+
.PHONY: kind-prepare
175+
kind-prepare: kind-create
176+
# Install prometheus operator
177+
$(KUBECTL) apply --server-side -f "https://github.com/prometheus-operator/prometheus-operator/releases/download/$(PROMETHEUS_OPERATOR_VERSION)/bundle.yaml"
178+
# Install cert-manager operator
179+
$(KUBECTL) apply --server-side -f "https://github.com/jetstack/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml"
164180

165181
##@ Dependencies
166182

@@ -175,12 +191,14 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
175191
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
176192
ENVTEST ?= $(LOCALBIN)/setup-envtest
177193
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
194+
KIND ?= $(LOCALBIN)/kind
178195

179196
## Tool Versions
180197
KUSTOMIZE_VERSION ?= v5.3.0
181198
CONTROLLER_TOOLS_VERSION ?= v0.14.0
182199
ENVTEST_VERSION ?= latest
183200
GOLANGCI_LINT_VERSION ?= v1.54.2
201+
KIND_VERSION ?= v0.22.0
184202

185203
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
186204

@@ -204,3 +222,7 @@ envtest: $(LOCALBIN)
204222
golangci-lint: $(LOCALBIN)
205223
@test -x $(GOLANGCI_LINT) && $(GOLANGCI_LINT) version | grep -q $(GOLANGCI_LINT_VERSION) || \
206224
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
225+
226+
kind: $(LOCALBIN)
227+
@test -x $(KIND) && $(KIND) version | grep -q $(KIND_VERSION) || \
228+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION)

test/e2e/e2e_test.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,8 @@ var _ = Describe("controller", Ordered, func() {
5959
var controllerPodName string
6060
var err error
6161

62-
// projectimage stores the name of the image used in the example
63-
var projectimage = "example.com/etcd-operator:v0.0.1"
64-
65-
By("building the manager(Operator) image")
66-
cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectimage))
67-
_, err = utils.Run(cmd)
68-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
69-
70-
By("loading the the manager(Operator) image on Kind")
71-
err = utils.LoadImageToKindClusterWithName(projectimage)
72-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
73-
74-
By("installing CRDs")
75-
cmd = exec.Command("make", "install")
76-
// TODO: Handle CRD installation error
77-
_, _ = utils.Run(cmd)
78-
7962
By("deploying the controller-manager")
80-
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage))
63+
cmd := exec.Command("make", "deploy")
8164
_, err = utils.Run(cmd)
8265
ExpectWithOffset(1, err).NotTo(HaveOccurred())
8366

test/utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
)
2727

2828
const (
29-
prometheusOperatorVersion = "v0.68.0"
29+
prometheusOperatorVersion = "v0.72.0"
3030
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
3131
"releases/download/%s/bundle.yaml"
3232

33-
certmanagerVersion = "v1.5.3"
33+
certmanagerVersion = "v1.14.4"
3434
certmanagerURLTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml"
3535
)
3636

0 commit comments

Comments
 (0)