From 7106ebb94361b0c2a7ec4c21bfdbaa0b5d72440f Mon Sep 17 00:00:00 2001 From: Richard Kovacs Date: Wed, 15 Nov 2023 19:11:21 +0100 Subject: [PATCH] Introduce Tilt for local development (#32) Co-authored-by: Richard Kovacs --- .gitignore | 1 + Makefile | 22 ++++++++++++++++++++++ README.md | 12 +++++++++++- Tiltfile | 3 +++ cmd/main.go | 3 ++- ctlptl-config.yaml | 9 +++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Tiltfile create mode 100644 ctlptl-config.yaml diff --git a/.gitignore b/.gitignore index b6023ff33..dbc337bf9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .idea bin/* cover.out +kubeconfig diff --git a/Makefile b/Makefile index 751cdd771..a9e4b923c 100644 --- a/Makefile +++ b/Makefile @@ -125,6 +125,11 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. $(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - +.PHONY: tilt-cluster +tilt-cluster: ctlptl tilt + ctlptl apply -f ctlptl-config.yaml + tilt up + ##@ Build Dependencies ## Location to install dependencies to @@ -135,12 +140,16 @@ $(LOCALBIN): ## Tool Binaries KUBECTL ?= kubectl KUSTOMIZE ?= $(LOCALBIN)/kustomize +CTLPTL ?= $(LOCALBIN)/ctlptl CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen +TILT ?= $(LOCALBIN)/tilt ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions KUSTOMIZE_VERSION ?= v5.1.1 +CTLPTL_VERSION ?= v0.8.22 CONTROLLER_TOOLS_VERSION ?= v0.13.0 +TILT_VERSION ?= 0.33.6 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading. @@ -151,12 +160,25 @@ $(KUSTOMIZE): $(LOCALBIN) fi test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION) +.PHONY: ctlptl +ctlptl: $(CTLPTL) ## Download ctlptl locally if necessary. If wrong version is installed, it will be overwritten. +$(CTLPTL): $(LOCALBIN) + test -s $(LOCALBIN)/ctlptl && $(LOCALBIN)/ctlptl version | grep -q $(CTLPTL_VERSION) || \ + GOBIN=$(LOCALBIN) go install github.com/tilt-dev/ctlptl/cmd/ctlptl@$(CTLPTL_VERSION) + + .PHONY: controller-gen controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten. $(CONTROLLER_GEN): $(LOCALBIN) test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) +.PHONY: tilt +tilt: $(TILT) ## Download tilt locally if necessary. If wrong version is installed, it will be overwritten. +$(TILT): $(LOCALBIN) + test -s $(LOCALBIN)/tilt && $(LOCALBIN)/tilt version | grep -q $(TILT_VERSION) || \ + (cd $(LOCALBIN) ; curl -fsSL https://github.com/tilt-dev/tilt/releases/download/v$(TILT_VERSION)/tilt.$(TILT_VERSION).linux.x86_64.tar.gz | tar -xzv tilt) + .PHONY: envtest envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. $(ENVTEST): $(LOCALBIN) diff --git a/README.md b/README.md index 47c5006d3..50f69daef 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # Cluster API Provider Linode -A [Cluster API](https://cluster-api.sigs.k8s.io/) implementation for the [Linode](https://www.linode.com/) to create kubernetes clusters. \ No newline at end of file +A [Cluster API](https://cluster-api.sigs.k8s.io/) implementation for the [Linode](https://www.linode.com/) to create kubernetes clusters. + +### Local development with Tilt + +For local development execute the following `make` target: + +```bash +make tilt-cluster +``` + +This command creates a Kind cluster, and deploys resources via Tilt. You can freely change the code and wait for Tilt to update provider. diff --git a/Tiltfile b/Tiltfile new file mode 100644 index 000000000..74a838d35 --- /dev/null +++ b/Tiltfile @@ -0,0 +1,3 @@ +docker_build("controller", ".") + +k8s_yaml(kustomize('config/default')) diff --git a/cmd/main.go b/cmd/main.go index c569c8b8d..d339f6a1f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -18,9 +18,10 @@ package main import ( "flag" - controller2 "github.com/linode/cluster-api-provider-linode/controller" "os" + controller2 "github.com/linode/cluster-api-provider-linode/controller" + // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. _ "k8s.io/client-go/plugin/pkg/client/auth" diff --git a/ctlptl-config.yaml b/ctlptl-config.yaml new file mode 100644 index 000000000..bef997e59 --- /dev/null +++ b/ctlptl-config.yaml @@ -0,0 +1,9 @@ +--- +apiVersion: ctlptl.dev/v1alpha1 +kind: Cluster +product: kind +kindV1Alpha4Cluster: + name: tilt + nodes: + - role: control-plane + image: kindest/node:v1.28.0