Skip to content
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

chore: impersonate KGO RBACs with make _run #740

Merged
merged 6 commits into from
Nov 29, 2024
Merged
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
36 changes: 31 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,25 @@ _ensure-kong-system-namespace:
@kubectl create ns kong-system 2>/dev/null || true

# Run a controller from your host.
# TODO: In order not to rely on 'main' version of Gateway API CRDs address but
# on the tag that is used in code (defined in go.mod) address this by solving
# https://github.com/Kong/gateway-operator/pull/480.
.PHONY: run
run: webhook-certs-dir manifests generate install.all _ensure-kong-system-namespace
run: webhook-certs-dir manifests generate install.all _ensure-kong-system-namespace install.rbacs
@$(MAKE) _run

# Run a controller from your host and make it impersonate the controller-manager service account from kong-system namespace.
.PHONY: run.with_impersonate
run.with_impersonate: webhook-certs-dir manifests generate install.all _ensure-kong-system-namespace install.rbacs
@$(MAKE) _run.with-impersonate

KUBECONFIG ?= $(HOME)/.kube/config

# Run the operator without checking any preconditions, installing CRDs etc.
# This is mostly useful when 'run' was run at least once on a server and CRDs, RBACs
# etc didn't change in between the runs.
.PHONY: _run
_run:
GATEWAY_OPERATOR_DEVELOPMENT_MODE=true go run ./cmd/main.go \
KUBECONFIG=$(KUBECONFIG) \
GATEWAY_OPERATOR_DEVELOPMENT_MODE=true \
go run ./cmd/main.go \
--no-leader-election \
-cluster-ca-secret-namespace kong-system \
-enable-controller-kongplugininstallation \
Expand All @@ -520,6 +526,21 @@ _run:
-zap-log-level 2 \
-zap-devel true

# Run the operator locally with impersonation of controller-manager service account from kong-system namespace.
# The operator will use a temporary kubeconfig file and impersonate the real RBACs.
.PHONY: _run.with-impersonate
_run.with-impersonate:
@$(eval TMP := $(shell mktemp -d))
@$(eval TMP_KUBECONFIG := $(TMP)/kubeconfig)
[ ! -z "$(KUBECONFIG)" ] || exit 1
cp $(KUBECONFIG) $(TMP_KUBECONFIG)
@$(eval TMP_TOKEN := $(shell kubectl create token --namespace=kong-system controller-manager))
@$(eval CLUSTER := $(shell kubectl config get-contexts | grep '^\*' | tr -s ' ' | cut -d ' ' -f 3))
KUBECONFIG=$(TMP_KUBECONFIG) kubectl config set-credentials kgo --token=$(TMP_TOKEN)
KUBECONFIG=$(TMP_KUBECONFIG) kubectl config set-context kgo --cluster=$(CLUSTER) --user=kgo --namespace=kong-system
KUBECONFIG=$(TMP_KUBECONFIG) kubectl config use-context kgo
bash -c "trap 'echo deleting temporary kubeconfig $(TMP); rm -rf $(TMP)' EXIT; $(MAKE) _run KUBECONFIG=$(TMP_KUBECONFIG)"

SKAFFOLD_RUN_PROFILE ?= dev

.PHONY: _skaffold
Expand Down Expand Up @@ -569,6 +590,11 @@ KUBERNETES_CONFIGURATION_CRDS_CRDS_LOCAL_PATH = $(shell go env GOPATH)/pkg/mod/$
install.kubernetes-configuration-crds: kustomize
$(KUSTOMIZE) build $(KUBERNETES_CONFIGURATION_CRDS_CRDS_LOCAL_PATH) | kubectl apply -f -

# Install RBACs from config/rbac into the K8s cluster specified in ~/.kube/config.
.PHONY: install.rbacs
install.rbacs: kustomize
$(KUSTOMIZE) build config/rbac | kubectl apply -f -
mlavacca marked this conversation as resolved.
Show resolved Hide resolved

# Install standard and experimental CRDs into the K8s cluster specified in ~/.kube/config.
.PHONY: install.all
install.all: manifests kustomize install-gateway-api-crds install.kubernetes-configuration-crds
Expand Down
Loading