diff --git a/workspaces/controller/Makefile b/workspaces/controller/Makefile index 6032c8c91..a905e2582 100644 --- a/workspaces/controller/Makefile +++ b/workspaces/controller/Makefile @@ -63,6 +63,37 @@ vet: ## Run go vet against code. test: manifests generate fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out +# Sets up a local Kubernetes cluster using Kind. +# By default: +# - The cluster name is read from the `name:` field in the Kind config file (CONFIG_FILE). +# - cert-manager is installed automatically. +# - metrics-server is installed automatically (can be disabled). +# Variables you can override: +# - CONFIG_FILE: Path to your Kind config file. +# - CLUSTER_NAME: Cluster name (overrides the name from the config file). +# - INSTALL_METRICS_SERVER: Set to false to skip metrics-server installation. +# Usage examples: +# make setup-kind-cluster +# make setup-kind-cluster CONFIG_FILE=utils/configs/my-config.yaml +# make setup-kind-cluster CLUSTER_NAME=my-cluster +# make setup-kind-cluster INSTALL_METRICS_SERVER=false +INSTALL_METRICS_SERVER ?= true +CONFIG_FILE := utils/configs/kind-notebooks-config.yaml +DEFAULT_CLUSTER_NAME := $(shell grep '^name:' $(CONFIG_FILE) | awk '{print $$2}') +CLUSTER_NAME ?= $(DEFAULT_CLUSTER_NAME) +.PHONY: setup-kind-cluster +setup-kind-cluster: + KIND_EXPERIMENTAL_PROVIDER=$(CONTAINER_TOOL) kind delete cluster --name $(CLUSTER_NAME) || true + KIND_EXPERIMENTAL_PROVIDER=$(CONTAINER_TOOL) kind create cluster --name $(CLUSTER_NAME) --config=$(CONFIG_FILE) + ./utils/scripts/install_cert_manager.sh +ifeq ($(INSTALL_METRICS_SERVER),true) + ./utils/scripts/install_metrics_server.sh +else + @echo "--- Skipping metrics-server installation (INSTALL_METRICS_SERVER set to $(INSTALL_METRICS_SERVER)) ---" +endif + @echo "--- Setting the current context to $(CLUSTER_NAME) cluster ---" + kubectl config set-context kind-$(CLUSTER_NAME) --namespace=workspace-controller-system + # The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally. # Prometheus and CertManager are installed by default; skip with: # - PROMETHEUS_INSTALL_SKIP=true diff --git a/workspaces/controller/utils/configs/kind-notebooks-config.yaml b/workspaces/controller/utils/configs/kind-notebooks-config.yaml new file mode 100644 index 000000000..9c0833edc --- /dev/null +++ b/workspaces/controller/utils/configs/kind-notebooks-config.yaml @@ -0,0 +1,6 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +name: kind-notebooks +nodes: +- role: control-plane +- role: worker diff --git a/workspaces/controller/utils/scripts/install_cert_manager.sh b/workspaces/controller/utils/scripts/install_cert_manager.sh new file mode 100755 index 000000000..12816d001 --- /dev/null +++ b/workspaces/controller/utils/scripts/install_cert_manager.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -euo pipefail + +echo "--- Installing cert-manager ---" +kubectl apply -f https://github.com/cert-manager/cert-manager/releases/latest/download/cert-manager.yaml + +kubectl wait --for=condition=Available deployment/cert-manager -n cert-manager --timeout=300s + +VERSION=$(kubectl get deployment cert-manager -n cert-manager -o jsonpath="{.spec.template.spec.containers[0].image}" | cut -d: -f2) +echo "Cert Manager installed. Version: $VERSION" diff --git a/workspaces/controller/utils/scripts/install_metrics_server.sh b/workspaces/controller/utils/scripts/install_metrics_server.sh new file mode 100755 index 000000000..bd8292dc9 --- /dev/null +++ b/workspaces/controller/utils/scripts/install_metrics_server.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -euo pipefail + +echo "--- Installing metrics-server ---" +kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml + +#Do not verify the CA of serving certificates presented by Kubelets. For testing purposes only. +kubectl patch deployment metrics-server --namespace kube-system --type='json' --patch='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--kubelet-insecure-tls"}]' + +kubectl wait --for=condition=Available deployment/metrics-server -n kube-system --timeout=300s + +VERSION=$(kubectl get deployment metrics-server -n kube-system -o jsonpath="{.spec.template.spec.containers[0].image}" | cut -d: -f2) +echo "Metrics Server installed. Version: $VERSION"