Skip to content

Commit ec1b1e6

Browse files
committed
Create Makefile target for a fresh kind cluster
Signed-off-by: atheo89 <[email protected]>
1 parent b2bee1d commit ec1b1e6

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

workspaces/controller/Makefile

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endif
1414
# Be aware that the target commands are only tested with Docker which is
1515
# scaffolded by default. However, you might want to replace it to use other
1616
# tools. (i.e. podman)
17-
CONTAINER_TOOL ?= docker
17+
CONTAINER_TOOL ?= podman
1818

1919
# Setting SHELL to bash allows bash commands to be executed by recipes.
2020
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
@@ -63,6 +63,37 @@ vet: ## Run go vet against code.
6363
test: manifests generate fmt vet envtest ## Run tests.
6464
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
6565

66+
# Sets up a local Kubernetes cluster using Kind.
67+
# By default:
68+
# - The cluster name is read from the `name:` field in the Kind config file (CONFIG_FILE).
69+
# - cert-manager is installed automatically.
70+
# - metrics-server is installed automatically (can be disabled).
71+
# Variables you can override:
72+
# - CONFIG_FILE: Path to your Kind config file.
73+
# - CLUSTER_NAME: Cluster name (overrides the name from the config file).
74+
# - INSTALL_METRICS_SERVER: Set to false to skip metrics-server installation.
75+
# Usage examples:
76+
# make setup-kind-cluster
77+
# make setup-kind-cluster CONFIG_FILE=utils/configs/my-config.yaml
78+
# make setup-kind-cluster CLUSTER_NAME=my-cluster
79+
# make setup-kind-cluster INSTALL_METRICS_SERVER=false
80+
INSTALL_METRICS_SERVER ?= true
81+
CONFIG_FILE := utils/configs/kind-notebooks-config.yaml
82+
DEFAULT_CLUSTER_NAME := $(shell grep '^name:' $(CONFIG_FILE) | awk '{print $$2}')
83+
CLUSTER_NAME ?= $(DEFAULT_CLUSTER_NAME)
84+
.PHONY: setup-kind-cluster
85+
setup-kind-cluster:
86+
KIND_EXPERIMENTAL_PROVIDER=$(CONTAINER_TOOL) kind delete cluster --name $(CLUSTER_NAME) || true
87+
KIND_EXPERIMENTAL_PROVIDER=$(CONTAINER_TOOL) kind create cluster --name $(CLUSTER_NAME) --config=$(CONFIG_FILE)
88+
./utils/scripts/install_cert_manager.sh
89+
ifeq ($(INSTALL_METRICS_SERVER),true)
90+
./utils/scripts/install_metrics_server.sh
91+
else
92+
@echo "--- Skipping metrics-server installation (INSTALL_METRICS_SERVER set to $(INSTALL_METRICS_SERVER)) ---"
93+
endif
94+
@echo "--- Setting the current context to $(CLUSTER_NAME) cluster ---"
95+
kubectl config set-context kind-$(CLUSTER_NAME) --namespace=workspace-controller-system
96+
6697
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
6798
# Prometheus and CertManager are installed by default; skip with:
6899
# - PROMETHEUS_INSTALL_SKIP=true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
name: kind-notebooks
4+
nodes:
5+
- role: control-plane
6+
- role: worker
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "--- Installing cert-manager ---"
6+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/latest/download/cert-manager.yaml
7+
8+
kubectl wait --for=condition=Available deployment/cert-manager -n cert-manager --timeout=300s
9+
10+
VERSION=$(kubectl get deployment cert-manager -n cert-manager -o jsonpath="{.spec.template.spec.containers[0].image}" | cut -d: -f2)
11+
echo "Cert Manager installed. Version: $VERSION"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "--- Installing metrics-server ---"
6+
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
7+
8+
#Do not verify the CA of serving certificates presented by Kubelets. For testing purposes only.
9+
kubectl patch deployment metrics-server --namespace kube-system --type='json' --patch='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--kubelet-insecure-tls"}]'
10+
11+
kubectl wait --for=condition=Available deployment/metrics-server -n kube-system --timeout=300s
12+
13+
VERSION=$(kubectl get deployment metrics-server -n kube-system -o jsonpath="{.spec.template.spec.containers[0].image}" | cut -d: -f2)
14+
echo "Metrics Server installed. Version: $VERSION"

0 commit comments

Comments
 (0)