Skip to content

Commit 38eb90d

Browse files
committed
add tilt-cleanup make target
Signed-off-by: Artem Bortnikov <artem.bortnikov@telekom.com>
1 parent c814e14 commit 38eb90d

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

Makefile

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ else
1313
GOBIN=$(shell go env GOBIN)
1414
endif
1515

16+
GOARCH := $(shell go env GOARCH)
17+
GOOS := $(shell go env GOOS)
18+
1619
# CONTAINER_TOOL defines the container tool to be used for building images.
1720
# Be aware that the target commands are only tested with Docker which is
1821
# scaffolded by default. However, you might want to replace it to use other
@@ -174,25 +177,25 @@ ifndef ignore-not-found
174177
endif
175178

176179
.PHONY: install
177-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
180+
install: manifests kustomize kubectl ## Install CRDs into the K8s cluster specified in ~/.kube/config.
178181
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
179182

180183
.PHONY: uninstall
181-
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.
184+
uninstall: manifests kustomize kubectl ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
182185
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete -n $(NAMESPACE) --ignore-not-found=$(ignore-not-found) -f -
183186

184187
.PHONY: deploy
185-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
188+
deploy: manifests kustomize kubectl ## Deploy controller to the K8s cluster specified in ~/.kube/config.
186189
cd config/manager && $(KUSTOMIZE) edit set image ghcr.io/aenix-io/etcd-operator=${IMG}
187190
$(KUSTOMIZE) build config/default | $(KUBECTL) -n $(NAMESPACE) apply -f -
188191
$(KUBECTL) wait deployment.apps/etcd-operator-controller-manager --for condition=Available --namespace $(NAMESPACE) --timeout 5m
189192

190193
.PHONY: undeploy
191-
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.
194+
undeploy: kustomize kubectl ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
192195
$(KUSTOMIZE) build config/default | $(KUBECTL) delete -n $(NAMESPACE) --ignore-not-found=$(ignore-not-found) -f -
193196

194197
.PHONY: redeploy
195-
redeploy: deploy ## Redeploy controller with new docker image.
198+
redeploy: deploy kubectl ## Redeploy controller with new docker image.
196199
# force recreate pods
197200
$(KUBECTL) rollout restart -n $(NAMESPACE) deploy/etcd-operator-controller-manager
198201

@@ -216,7 +219,7 @@ kind-delete: kind ## Create kubernetes cluster using Kind.
216219
fi
217220

218221
.PHONY: kind-prepare
219-
kind-prepare: kind-create
222+
kind-prepare: kind-create kubectl
220223
# Install prometheus operator
221224
$(KUBECTL) apply --server-side -f "https://github.com/prometheus-operator/prometheus-operator/releases/download/$(PROMETHEUS_OPERATOR_VERSION)/bundle.yaml"
222225
$(KUBECTL) wait deployment.apps/prometheus-operator --for condition=Available --namespace default --timeout 5m
@@ -237,7 +240,7 @@ $(HELM_PLUGINS):
237240
mkdir -p $(HELM_PLUGINS)
238241

239242
## Tool Binaries
240-
KUBECTL ?= kubectl
243+
KUBECTL ?= $(LOCALBIN)/kubectl
241244
KUSTOMIZE ?= $(LOCALBIN)/kustomize
242245
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
243246
ENVTEST ?= $(LOCALBIN)/setup-envtest
@@ -277,6 +280,13 @@ TILT_VERSION ?= 0.33.21
277280
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
278281
HELM_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3"
279282

283+
CURL_RETRIES=3
284+
.PHONY: kubectl
285+
kubectl: $(LOCALBIN)
286+
@test -x $(KUBECTL) && ! $(KUBECTL) version 2>/dev/null | grep -q $(K8S_VERSION) || \
287+
curl --retry $(CURL_RETRIES) -fsL https://dl.k8s.io/release/$(K8S_VERSION)/bin/$(GOOS)/$(GOARCH)/kubectl -o $(KUBECTL) && \
288+
chmod +x $(KUBECTL)
289+
280290
.PHONY: kustomize
281291
kustomize: $(LOCALBIN)
282292
@if test -x $(KUSTOMIZE) && ! $(KUSTOMIZE) version | grep -q $(KUSTOMIZE_VERSION); then \
@@ -341,24 +351,32 @@ ctlptl: $(LOCALBIN)
341351
@test -x $(CTLPTL) && $(CTLPTL) version | grep -q $(CTLPTL_VERSION) || \
342352
GOBIN=$(LOCALBIN) go install github.com/tilt-dev/ctlptl/cmd/ctlptl@$(CTLPTL_VERSION)
343353

344-
ifeq (darwin,$(shell go env GOOS))
354+
ifeq (darwin,$(GOOS))
345355
TILT_OS=mac
346356
else
347-
TILT_OS=$(shell go env GOOS)
357+
TILT_OS=$(GOOS)
348358
endif
349359

350-
TILT_ARCH ?= $(shell go env GOARCH)
360+
TILT_ARCH ?= $(GOARCH)
351361

352-
TILT_ARCHIVE=tilt.$(TILT_VERSION).$(TILT_OS).$(TILT_ARCH).tar.gz
362+
TILT_ARCHIVE_NAME=tilt.$(TILT_VERSION).$(TILT_OS).$(TILT_ARCH).tar.gz
353363
.PHONY: tilt
354364
tilt: $(LOCALBIN)
355-
@test -x $(TILT) && $(TILT) version | grep -q $(TILT_VERSION) || \
356-
rm -f $(TILT) && \
357-
curl -sL https://github.com/tilt-dev/tilt/releases/download/v$(TILT_VERSION)/$(TILT_ARCHIVE) -o /tmp/$(TILT_ARCHIVE) && \
358-
tar xzf /tmp/$(TILT_ARCHIVE) -C $(LOCALBIN) && \
359-
rm -f /tmp/$(TILT_ARCHIVE)
365+
@if ! test -x $(TILT) || ! $(TILT) version | grep -q $(TILT_VERSION); then \
366+
TMPDIR=$$(mktemp -d) && \
367+
trap 'rm -rf "$$TMPDIR"' EXIT && \
368+
curl -sL https://github.com/tilt-dev/tilt/releases/download/v$(TILT_VERSION)/$(TILT_ARCHIVE_NAME) -o "$$TMPDIR/$(TILT_ARCHIVE_NAME)" && \
369+
curl -sL https://github.com/tilt-dev/tilt/releases/download/v$(TILT_VERSION)/$(TILT_ARCHIVE_NAME).sha256 -o "$$TMPDIR/$(TILT_ARCHIVE_NAME).sha256" && \
370+
cd "$$TMPDIR" && sha256sum -c "$(TILT_ARCHIVE_NAME).sha256" && \
371+
tar xzf "$(TILT_ARCHIVE_NAME)" -C $(LOCALBIN) || exit 1; \
372+
fi
360373

361374
.PHONY: tilt-up
362375
tilt-up: kustomize kind ctlptl tilt
363376
$(CTLPTL) apply -f config/dev/ctlptl-kind.yaml
364377
$(TILT) up
378+
379+
.PHONY: tilt-cleanup
380+
tilt-cleanup: ctlptl
381+
$(TILT) down
382+
$(CTLPTL) delete -f config/dev/ctlptl-kind.yaml

Tiltfile

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
1-
#!/usr/bin/env bash
2-
31
update_settings(k8s_upsert_timeout_secs=60) # on first tilt up, often can take longer than 30 seconds
42

53
# tilt settings
64
settings = {
75
"allowed_contexts": [
86
"kind-etcd-operator-dev"
97
],
10-
"kubectl": "/usr/local/bin/kubectl",
11-
"kustomize": "./bin/kustomize",
8+
"kubectl": "bin/kubectl",
9+
"kustomize": "bin/kustomize",
1210
"cert_manager_version": "v1.15.3",
1311
}
1412

1513
# define variables and functions
16-
kubectl = settings.get("kubectl")
17-
kustomize_binary = settings.get("kustomize")
14+
base_path = config.main_dir
15+
kubectl_binary = "{}/{}".format(base_path, settings.get("kubectl"))
16+
kustomize_binary = "{}/{}".format(base_path, settings.get("kustomize"))
1817

1918
if "allowed_contexts" in settings:
2019
allow_k8s_contexts(settings.get("allowed_contexts"))
2120

2221
def deploy_cert_manager():
2322
version = settings.get("cert_manager_version")
2423
print("Installing cert-manager")
25-
local("{} apply -f https://github.com/cert-manager/cert-manager/releases/download/{}/cert-manager.yaml".format(kubectl, version), quiet=True, echo_off=True)
24+
local("{} apply -f https://github.com/cert-manager/cert-manager/releases/download/{}/cert-manager.yaml".format(kubectl_binary, version), quiet=True, echo_off=True)
2625

2726
print("Waiting for cert-manager to start")
28-
local("{} wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager".format(kubectl), quiet=True, echo_off=True)
29-
local("{} wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-cainjector".format(kubectl), quiet=True, echo_off=True)
30-
local("{} wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-webhook".format(kubectl), quiet=True, echo_off=True)
27+
local("{} wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager".format(kubectl_binary), quiet=True, echo_off=True)
28+
local("{} wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-cainjector".format(kubectl_binary), quiet=True, echo_off=True)
29+
local("{} wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-webhook".format(kubectl_binary), quiet=True, echo_off=True)
3130

32-
def waitforsystem():
33-
print("Waiting for metal-operator to start")
34-
local("{} wait --for=condition=ready --timeout=300s -n etcd-operator-system pod --all".format(kubectl), quiet=False, echo_off=True)
31+
def prepare_etcd_operator():
32+
docker_build('ghcr.io/aenix-io/etcd-operator', '.')
33+
return kustomize("./config/dev", kustomize_bin=kustomize_binary)
3534

3635
# deploy everything
3736
deploy_cert_manager()
3837

39-
docker_build('ghcr.io/aenix-io/etcd-operator', '.')
40-
41-
yaml = kustomize("./config/dev", kustomize_bin=kustomize_binary)
42-
38+
yaml = prepare_etcd_operator()
4339
k8s_yaml(yaml)

0 commit comments

Comments
 (0)