|
| 1 | +# Kind cluster management |
| 2 | + |
| 3 | +KIND_CLUSTER_NAME ?= kubernetes-mcp-server |
| 4 | + |
| 5 | +# Detect container engine (docker or podman) |
| 6 | +CONTAINER_ENGINE ?= $(shell command -v docker 2>/dev/null || command -v podman 2>/dev/null) |
| 7 | + |
| 8 | +.PHONY: kind-create-certs |
| 9 | +kind-create-certs: |
| 10 | + @if [ ! -f _output/cert-manager-ca/ca.crt ]; then \ |
| 11 | + echo "Creating placeholder CA certificate for bind mount..."; \ |
| 12 | + ./hack/generate-placeholder-ca.sh; \ |
| 13 | + else \ |
| 14 | + echo "✅ Placeholder CA already exists"; \ |
| 15 | + fi |
| 16 | + |
| 17 | +.PHONY: kind-create-cluster |
| 18 | +kind-create-cluster: kind kind-create-certs |
| 19 | + @# Set KIND provider for podman on Linux |
| 20 | + @if [ "$(shell uname -s)" != "Darwin" ] && echo "$(CONTAINER_ENGINE)" | grep -q "podman"; then \ |
| 21 | + export KIND_EXPERIMENTAL_PROVIDER=podman; \ |
| 22 | + fi; \ |
| 23 | + if $(KIND) get clusters 2>/dev/null | grep -q "^$(KIND_CLUSTER_NAME)$$"; then \ |
| 24 | + echo "Kind cluster '$(KIND_CLUSTER_NAME)' already exists, skipping creation"; \ |
| 25 | + else \ |
| 26 | + echo "Creating Kind cluster '$(KIND_CLUSTER_NAME)'..."; \ |
| 27 | + $(KIND) create cluster --name $(KIND_CLUSTER_NAME) --config dev/config/kind/cluster.yaml; \ |
| 28 | + echo "Adding ingress-ready label to control-plane node..."; \ |
| 29 | + kubectl label node $(KIND_CLUSTER_NAME)-control-plane ingress-ready=true --overwrite; \ |
| 30 | + echo "Installing nginx ingress controller..."; \ |
| 31 | + kubectl apply -f dev/config/ingress/nginx-ingress.yaml; \ |
| 32 | + echo "Waiting for ingress controller to be ready..."; \ |
| 33 | + kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=90s; \ |
| 34 | + echo "✅ Ingress controller ready"; \ |
| 35 | + echo "Installing cert-manager..."; \ |
| 36 | + kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.16.2/cert-manager.yaml; \ |
| 37 | + echo "Waiting for cert-manager to be ready..."; \ |
| 38 | + kubectl wait --namespace cert-manager --for=condition=available deployment/cert-manager --timeout=120s; \ |
| 39 | + kubectl wait --namespace cert-manager --for=condition=available deployment/cert-manager-cainjector --timeout=120s; \ |
| 40 | + kubectl wait --namespace cert-manager --for=condition=available deployment/cert-manager-webhook --timeout=120s; \ |
| 41 | + echo "✅ cert-manager ready"; \ |
| 42 | + echo "Creating cert-manager ClusterIssuer..."; \ |
| 43 | + sleep 5; \ |
| 44 | + kubectl apply -f dev/config/cert-manager/selfsigned-issuer.yaml; \ |
| 45 | + echo "✅ ClusterIssuer created"; \ |
| 46 | + echo "Adding /etc/hosts entry for Keycloak in control plane..."; \ |
| 47 | + if command -v docker >/dev/null 2>&1 && docker ps --filter "name=$(KIND_CLUSTER_NAME)-control-plane" --format "{{.Names}}" | grep -q "$(KIND_CLUSTER_NAME)-control-plane"; then \ |
| 48 | + docker exec $(KIND_CLUSTER_NAME)-control-plane bash -c 'grep -q "keycloak.127-0-0-1.sslip.io" /etc/hosts || echo "127.0.0.1 keycloak.127-0-0-1.sslip.io" >> /etc/hosts'; \ |
| 49 | + elif command -v podman >/dev/null 2>&1 && podman ps --filter "name=$(KIND_CLUSTER_NAME)-control-plane" --format "{{.Names}}" | grep -q "$(KIND_CLUSTER_NAME)-control-plane"; then \ |
| 50 | + podman exec $(KIND_CLUSTER_NAME)-control-plane bash -c 'grep -q "keycloak.127-0-0-1.sslip.io" /etc/hosts || echo "127.0.0.1 keycloak.127-0-0-1.sslip.io" >> /etc/hosts'; \ |
| 51 | + fi; \ |
| 52 | + echo "✅ /etc/hosts entry added"; \ |
| 53 | + fi |
| 54 | + |
| 55 | +.PHONY: kind-delete-cluster |
| 56 | +kind-delete-cluster: kind |
| 57 | + @# Set KIND provider for podman on Linux |
| 58 | + @if [ "$(shell uname -s)" != "Darwin" ] && echo "$(CONTAINER_ENGINE)" | grep -q "podman"; then \ |
| 59 | + export KIND_EXPERIMENTAL_PROVIDER=podman; \ |
| 60 | + fi; \ |
| 61 | + $(KIND) delete cluster --name $(KIND_CLUSTER_NAME) |
0 commit comments