From b7540d72852dd626768d4095669b31ab465e6966 Mon Sep 17 00:00:00 2001 From: Shu Muto Date: Wed, 1 May 2024 00:14:16 +0900 Subject: [PATCH] Fix envs for kubeconfig Also, stop using KIND_EXPERIMENTAL_DOCKER_NETWORK. --- Makefile | 6 +++--- hack/develop/run-dev-container.sh | 3 +-- hack/docker/dev.compose.yml | 2 +- hack/docker/docker.compose.yaml | 2 +- hack/include/config.mk | 29 ++++++++++++++++------------- hack/include/kind.mk | 24 ++++++++++++------------ 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 01aea3c0b501..bcb0ab82819e 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ tools: $(PRE) ## Installs required tools # Note: Make sure that the port 8080 (Web HTTP) is free on your localhost .PHONY: serve serve: $(PRE) --ensure-kind-cluster --ensure-metrics-server ## Starts development version of the application on http://localhost:8080 - @KUBECONFIG=$(KUBECONFIG_FOR_DOCKER_COMPOSE) \ + @KUBECONFIG=$(DOCKER_COMPOSE_KUBECONFIG) \ SOURCE_DIR=$(SOURCE_DIR) \ SYSTEM_BANNER=$(SYSTEM_BANNER) \ SYSTEM_BANNER_SEVERITY=$(SYSTEM_BANNER_SEVERITY) \ @@ -96,7 +96,7 @@ serve: $(PRE) --ensure-kind-cluster --ensure-metrics-server ## Starts developmen # Note: Make sure that the ports 8443 (Gateway HTTPS) and 8080 (Gateway HTTP) are free on your localhost .PHONY: run run: $(PRE) --ensure-kind-cluster --ensure-metrics-server ## Starts production version of the application on https://localhost:8443 and https://localhost:8000 - @KUBECONFIG=$(KUBECONFIG_FOR_DOCKER_COMPOSE) \ + @KUBECONFIG=$(DOCKER_COMPOSE_KUBECONFIG) \ SOURCE_DIR=$(SOURCE_DIR) \ SYSTEM_BANNER=$(SYSTEM_BANNER) \ SYSTEM_BANNER_SEVERITY=$(SYSTEM_BANNER_SEVERITY) \ @@ -113,7 +113,7 @@ run: $(PRE) --ensure-kind-cluster --ensure-metrics-server ## Starts production v .PHONY: image image: ifndef NO_BUILD - @KUBECONFIG=$(KUBECONFIG_FOR_DOCKER_COMPOSE) \ + @KUBECONFIG=$(DOCKER_COMPOSE_KUBECONFIG) \ SOURCE_DIR=$(SOURCE_DIR) \ SYSTEM_BANNER=$(SYSTEM_BANNER) \ SYSTEM_BANNER_SEVERITY=$(SYSTEM_BANNER_SEVERITY) \ diff --git a/hack/develop/run-dev-container.sh b/hack/develop/run-dev-container.sh index 0298eefbc32a..550b6fccf323 100755 --- a/hack/develop/run-dev-container.sh +++ b/hack/develop/run-dev-container.sh @@ -24,7 +24,7 @@ LOCAL_GID=$(id -g) DOCKER_GID=$(getent group docker|cut -d ":" -f 3) # Create docker network to work with kind cluster -KD_DEV_NETWORK="kubernetes-dashboard" +KD_DEV_NETWORK="kind" docker network create ${KD_DEV_NETWORK} \ -d=bridge \ -o com.docker.network.bridge.enable_ip_masquerade=true \ @@ -67,7 +67,6 @@ docker run \ -e K8S_OWN_CLUSTER=${K8S_OWN_CLUSTER} \ -e BIND_ADDRESS=${KD_DEV_BIND_ADDRESS} \ -e KUBECONFIG=${KD_DEV_KUBECONFIG} \ - -e KIND_EXPERIMENTAL_DOCKER_NETWORK=${KD_DEV_NETWORK} \ -e SIDECAR_HOST=${KD_DEV_SIDECAR_HOST} \ -e LOCAL_UID="${LOCAL_UID}" \ -e LOCAL_GID="${LOCAL_GID}" \ diff --git a/hack/docker/dev.compose.yml b/hack/docker/dev.compose.yml index 037ba6827930..9a6352efd89b 100644 --- a/hack/docker/dev.compose.yml +++ b/hack/docker/dev.compose.yml @@ -114,5 +114,5 @@ services: networks: default: - name: kubernetes-dashboard + name: kind external: true diff --git a/hack/docker/docker.compose.yaml b/hack/docker/docker.compose.yaml index 5c693fd7078f..5dbaea4ddcbe 100644 --- a/hack/docker/docker.compose.yaml +++ b/hack/docker/docker.compose.yaml @@ -97,5 +97,5 @@ services: networks: default: - name: kubernetes-dashboard + name: kind external: true diff --git a/hack/include/config.mk b/hack/include/config.mk index f24b5cc8cbeb..f07da3f64873 100644 --- a/hack/include/config.mk +++ b/hack/include/config.mk @@ -2,6 +2,11 @@ PROJECT_NAME := dashboard ### Dirs and paths +# Dashboard source directory +SOURCE_DIR := $(ROOT_DIRECTORY) +ifdef KD_DEV_SRC +SOURCE_DIR := $(KD_DEV_SRC) +endif # Base paths PARTIALS_DIRECTORY := $(ROOT_DIRECTORY)/hack/include # Modules @@ -23,8 +28,18 @@ TMP_DIRECTORY := $(ROOT_DIRECTORY)/.tmp KIND_CLUSTER_NAME := kubernetes-dashboard KIND_CLUSTER_VERSION := v1.29.0 KIND_CLUSTER_IMAGE := docker.io/kindest/node:${KIND_CLUSTER_VERSION} -KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH := $(TMP_DIRECTORY)/kubeconfig KIND_CONFIG_FILE := $(PARTIALS_DIRECTORY)/kind.config.yml +KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH := $(TMP_DIRECTORY)/kubeconfig +# Kubectl +KIND_CLUSTER_DEPLOY_KUBECONFIG := $(HOME)/.kube/config +ifdef KD_DEV_SRC +KIND_CLUSTER_DEPLOY_KUBECONFIG := $(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) +endif +# Kubeconfig to mount into docker compose +DOCKER_COMPOSE_KUBECONFIG := $(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) +ifdef KD_DEV_SRC +DOCKER_COMPOSE_KUBECONFIG := $(SOURCE_DIR)/.tmp/kubeconfig +endif # Metrics server METRICS_SERVER_VERSION := v0.7.0 # Ingress nginx (kind) @@ -42,15 +57,3 @@ endif ifeq (,$(findstring $(GOPATH)/bin,$(PATH))) $(warning $$GOPATH/bin directory is not in your $$PATH) endif - -### KUBECONFIG for docker compose -KUBECONFIG_FOR_DOCKER_COMPOSE := $(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) -ifdef KD_DEV_SRC -KUBECONFIG_FOR_DOCKER_COMPOSE := $(KD_DEV_SRC)/.tmp/kubeconfig -endif - -### Dashboard source directory for docker compose -SOURCE_DIR := $(PWD) -ifdef KD_DEV_SRC -SOURCE_DIR := $(KD_DEV_SRC) -endif diff --git a/hack/include/kind.mk b/hack/include/kind.mk index 3c5b7d7286e7..5e4120eba2a5 100644 --- a/hack/include/kind.mk +++ b/hack/include/kind.mk @@ -3,22 +3,22 @@ include $(PARTIALS_DIRECTORY)/config.mk .PHONY: --ensure-kind-cluster --ensure-kind-cluster: @if test -n "$(shell kind get clusters 2>/dev/null | grep $(KIND_CLUSTER_NAME))"; then \ - echo [kind] cluster already exists; \ - else \ - echo [kind] creating cluster $(KIND_CLUSTER_NAME); \ - kind create cluster -q --config=$(KIND_CONFIG_FILE) --name=$(KIND_CLUSTER_NAME) --image=$(KIND_CLUSTER_IMAGE); \ - fi; \ - echo [kind] exporting internal kubeconfig to $(TMP_DIRECTORY); \ - mkdir -p $(TMP_DIRECTORY); \ - kind get kubeconfig --name $(KIND_CLUSTER_NAME) --internal > $(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) + echo [kind] cluster already exists; \ + else \ + echo [kind] creating cluster $(KIND_CLUSTER_NAME); \ + kind create cluster -q --config=$(KIND_CONFIG_FILE) --name=$(KIND_CLUSTER_NAME) --image=$(KIND_CLUSTER_IMAGE); \ + fi; \ + echo [kind] exporting internal kubeconfig to $(TMP_DIRECTORY); \ + mkdir -p $(TMP_DIRECTORY); \ + kind get kubeconfig --name $(KIND_CLUSTER_NAME) --internal > $(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) .PHONY: --ensure-metrics-server --ensure-metrics-server: @echo [kind] installing metrics server $(METRICS_SERVER_VERSION) - @KUBECONFIG=$(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) \ + @KUBECONFIG=$(KIND_CLUSTER_DEPLOY_KUBECONFIG) \ kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/$(METRICS_SERVER_VERSION)/components.yaml >/dev/null @echo [kind] patching metrics server arguments - @KUBECONFIG=$(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) \ + @KUBECONFIG=$(KIND_CLUSTER_DEPLOY_KUBECONFIG) \ kubectl patch deployment \ metrics-server \ -n kube-system \ @@ -28,9 +28,9 @@ include $(PARTIALS_DIRECTORY)/config.mk .PHONY: --ensure-kind-ingress-nginx --ensure-kind-ingress-nginx: @echo [kind] installing ingress-nginx - @KUBECONFIG=$(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) \ + @KUBECONFIG=$(KIND_CLUSTER_DEPLOY_KUBECONFIG) \ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-$(INGRESS_NGINX_VERSION)/deploy/static/provider/kind/deploy.yaml >/dev/null - @KUBECONFIG=$(KIND_CLUSTER_INTERNAL_KUBECONFIG_PATH) \ + @KUBECONFIG=$(KIND_CLUSTER_DEPLOY_KUBECONFIG) \ kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission >/dev/null .PHONY: --ensure-helm-dependencies