1313GOBIN =$(shell go env GOBIN)
1414endif
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
174177endif
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
241244KUSTOMIZE ?= $(LOCALBIN ) /kustomize
242245CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
243246ENVTEST ?= $(LOCALBIN ) /setup-envtest
@@ -277,6 +280,13 @@ TILT_VERSION ?= 0.33.21
277280KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
278281HELM_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
281291kustomize : $(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 ) )
345355TILT_OS =mac
346356else
347- TILT_OS =$(shell go env GOOS)
357+ TILT_OS =$(GOOS )
348358endif
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
354364tilt : $(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
362375tilt-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
0 commit comments