Skip to content

Commit

Permalink
Fix envs for kubeconfig
Browse files Browse the repository at this point in the history
Also, stop using KIND_EXPERIMENTAL_DOCKER_NETWORK.
  • Loading branch information
shu-mutou committed Apr 30, 2024
1 parent 27b664c commit b7540d7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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) \
Expand All @@ -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) \
Expand Down
3 changes: 1 addition & 2 deletions hack/develop/run-dev-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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}" \
Expand Down
2 changes: 1 addition & 1 deletion hack/docker/dev.compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ services:

networks:
default:
name: kubernetes-dashboard
name: kind
external: true
2 changes: 1 addition & 1 deletion hack/docker/docker.compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ services:

networks:
default:
name: kubernetes-dashboard
name: kind
external: true
29 changes: 16 additions & 13 deletions hack/include/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
24 changes: 12 additions & 12 deletions hack/include/kind.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down

0 comments on commit b7540d7

Please sign in to comment.