Skip to content

feat: Create Makefile target for a fresh kind cluster #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: notebooks-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions workspaces/controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: kind-notebooks
nodes:
- role: control-plane
- role: worker
11 changes: 11 additions & 0 deletions workspaces/controller/utils/scripts/install_cert_manager.sh
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions workspaces/controller/utils/scripts/install_metrics_server.sh
Original file line number Diff line number Diff line change
@@ -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"