From a3a1482d509f1468583c65654483a6288a93f849 Mon Sep 17 00:00:00 2001 From: Jim Fitzpatrick Date: Mon, 21 Aug 2023 12:03:38 +0100 Subject: [PATCH 1/2] Namespace support. - Add support for setting the namespace during the manifest creations - Add make targets for creation of kind cluster for local development --- Makefile | 111 +++++++++++++++++++++++++++++- README.md | 17 +++++ config/default/kustomization.yaml | 5 +- config/deploy/kustomization.yaml | 9 ++- config/install/kustomization.yaml | 5 +- utils/kind-cluster.yaml | 6 ++ 6 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 utils/kind-cluster.yaml diff --git a/Makefile b/Makefile index 974d4f74..bde1bcd7 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,10 @@ KUSTOMIZE = $(shell pwd)/bin/kustomize kustomize: ## Download kustomize locally if necessary. $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.5) +KIND = $(shell pwd)/bin/kind +kind: + $(call go-get-tool,$(KIND),sigs.k8s.io/kind@v0.20.0) + YQ = $(shell pwd)/bin/yq YQ_VERSION := v4.34.2 $(YQ): @@ -182,16 +186,40 @@ docker-push: ## Push docker image with the manager. ##@ Deployment install: manifests kustomize install-authorino ## Install CRDs into the K8s cluster specified in ~/.kube/config. + @if [ $(NAMESPACE) != '' ];then \ + echo "Setting Custom Namespace: $(NAMESPACE)"; \ + cd $(PROJECT_DIR)/config/install && $(KUSTOMIZE) edit set namespace $(NAMESPACE); \ + kubectl create namespace $(NAMESPACE); \ + else \ + kubectl create namespace $(DEFAULT_REPO); \ + fi + cd $(PROJECT_DIR) && $(KUSTOMIZE) build config/install > $(OPERATOR_MANIFESTS) kubectl apply -f $(OPERATOR_MANIFESTS) + # clean up + @if [ $(NAMESPACE) != '' ];then \ + echo "Removing Custom Namespace: $(NAMESPACE)"; \ + cd $(PROJECT_DIR)/config/install && $(KUSTOMIZE) edit set namespace $(DEFAULT_REPO); \ + fi + + uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. kubectl delete -f $(OPERATOR_MANIFESTS) deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd config/manager && $(KUSTOMIZE) edit set image controller=${OPERATOR_IMAGE} + @if [ $(NAMESPACE) != '' ];then \ + echo "Setting Custom Namespace: $(NAMESPACE)"; \ + cd $(PROJECT_DIR)/config/default && $(KUSTOMIZE) edit set namespace $(NAMESPACE); \ + fi + $(KUSTOMIZE) build config/default | kubectl apply -f - # rollback kustomize edit cd config/manager && $(KUSTOMIZE) edit set image controller=${DEFAULT_OPERATOR_IMAGE} + @if [ $(NAMESPACE) != '' ];then \ + echo "Removing Custom Namespace: $(NAMESPACE)"; \ + cd $(PROJECT_DIR)/config/default && $(KUSTOMIZE) edit set namespace $(DEFAULT_REPO); \ + fi undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/default | kubectl delete -f - @@ -216,12 +244,22 @@ endef DEPLOYMENT_DIR = $(PROJECT_DIR)/config/deploy DEPLOYMENT_FILE = $(DEPLOYMENT_DIR)/manifests.yaml .PHONY: deploy-manifest -deploy-manifest: +deploy-manifest: kustomize mkdir -p $(DEPLOYMENT_DIR) - cd $(PROJECT_DIR)/config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE) ;\ + cd $(PROJECT_DIR)/config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE) + + @if [ $(NAMESPACE) != '' ];then \ + echo "Setting Custom Namespace: $(NAMESPACE)"; \ + cd $(PROJECT_DIR)/config/deploy && $(KUSTOMIZE) edit set namespace $(NAMESPACE); \ + fi + cd $(PROJECT_DIR) && $(KUSTOMIZE) build config/deploy > $(DEPLOYMENT_FILE) # clean up cd $(PROJECT_DIR)/config/manager && $(KUSTOMIZE) edit set image controller=${DEFAULT_OPERATOR_IMAGE} + @if [ $(NAMESPACE) != '' ];then \ + echo "Removing Custom Namespace: $(NAMESPACE)"; \ + cd $(PROJECT_DIR)/config/deploy && $(KUSTOMIZE) edit set namespace $(DEFAULT_REPO); \ + fi .PHONY: bundle bundle: export IMAGE_TAG := $(IMAGE_TAG) @@ -307,3 +345,72 @@ verify-bundle: bundle ## Verify bundle update. .PHONY: verify-fmt verify-fmt: fmt ## Verify fmt update. git diff --exit-code ./api ./controllers + +## local configurations + +deploy-develmode: manifests kustomize ## Deploy controller in debug mode to the K8s cluster specified in ~/.kube/config. + cd config/manager && $(KUSTOMIZE) edit set image controller=${OPERATOR_IMAGE} + @if [ $(NAMESPACE) != '' ];then \ + echo "Setting Custom Namespace: $(NAMESPACE)"; \ + cd $(PROJECT_DIR)/config/default && $(KUSTOMIZE) edit set namespace $(NAMESPACE); \ + fi + + cd $(PROJECT_DIR) && $(KUSTOMIZE) build config/deploy > $(DEPLOYMENT_FILE) + + $(KUSTOMIZE) build config/default | kubectl apply -f - + +# clean up + cd config/manager && $(KUSTOMIZE) edit set image controller=${DEFAULT_OPERATOR_IMAGE} + @if [ $(NAMESPACE) != '' ];then \ + echo "Removing Custom Namespace: $(NAMESPACE)"; \ + cd $(PROJECT_DIR)/config/default && $(KUSTOMIZE) edit set namespace $(DEFAULT_REPO); \ + fi + +.PHONY: local-cleanup +local-cleanup: + $(MAKE) kind-delete-cluster + +.PHONY: local-env-setup +local-env-setup: + $(MAKE) kind-delete-cluster + $(MAKE) kind-create-cluster + $(KUSTOMIZE) build config/crd | kubectl apply -f - + +.PHONY: local-setup +local-setup: export OPERATOR_IMAGE := authorino-operator:dev +local-setup: + $(MAKE) local-env-setup + $(MAKE) docker-build + echo "Deploying Authorino control plane" + $(KIND) load docker-image ${OPERATOR_IMAGE} --name ${KIND_CLUSTER_NAME} + $(MAKE) install + $(MAKE) deploy + +.PHONY: local-redeploy +local-redeploy: export OPERATOR_IMAGE := authorino-operator:dev +local-redeploy: + $(MAKE) docker-build + echo "Deploying Authorino control plane" + $(KIND) load docker-image ${OPERATOR_IMAGE} --name ${KIND_CLUSTER_NAME} + + @if [ $(NAMESPACE) != '' ];then \ + kubectl rollout restart deployment -n $(NAMESPACE) authorino-operator; \ + echo "Wait for all deployments to be up"; \ + kubectl -n $(NAMESPACE) wait --timeout=300s --for=condition=Available deployments --all; \ + else \ + kubectl rollout restart deployment -n $(DEFAULT_REPO) authorino-operator; \ + echo "Wait for all deployments to be up"; \ + kubectl -n $(DEFAULT_REPO) wait --timeout=300s --for=condition=Available deployments --all; \ + fi + +## kind configuration + +KIND_CLUSTER_NAME ?= authorino-local + +.PHONY: kind-create-cluster +kind-create-cluster: kind ## Create the "authorino-local" kind cluster. + $(KIND) create cluster --name $(KIND_CLUSTER_NAME) --config utils/kind-cluster.yaml + +.PHONY: kind-delete-cluster +kind-delete-cluster: kind ## Delete the "authorino-local" kind cluster. + $(KIND) delete cluster --name $(KIND_CLUSTER_NAME) \ No newline at end of file diff --git a/README.md b/README.md index a76ae780..943f297a 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,23 @@ spec: EOF ``` +### Installing via kind for local development + +1. Create the kind cluster, build the operator image and deploy the operator. +```shell +make local-setup +``` + +2. Rebuild and Redeploy the operator image +```shell +make local-redeploy +``` + +3. Remove the kind cluster +```shell +make local-cleanup +``` + ## Requesting an Authorino instance Once the Operator is up and running, you can request instances of Authorino by creating `Authorino` CRs. E.g.: diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index d0c24e74..86049d65 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -1,3 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + # Adds namespace to all resources. namespace: authorino-operator @@ -12,7 +15,7 @@ namespace: authorino-operator #commonLabels: # someName: someValue -bases: +resources: - ../crd - ../rbac - ../manager diff --git a/config/deploy/kustomization.yaml b/config/deploy/kustomization.yaml index e46bfb22..ae94f742 100644 --- a/config/deploy/kustomization.yaml +++ b/config/deploy/kustomization.yaml @@ -1,3 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + resources: - - ../authorino - - ../default +- ../authorino +- ../default + +namespace: authorino-operator diff --git a/config/install/kustomization.yaml b/config/install/kustomization.yaml index ed41771f..48d60dbb 100644 --- a/config/install/kustomization.yaml +++ b/config/install/kustomization.yaml @@ -1,3 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + # Adds namespace to all resources. namespace: authorino-operator @@ -5,6 +8,6 @@ namespace: authorino-operator # names of all resources, e.g. a deployment named # namePrefix: authorino-operator- -bases: +resources: - ../crd - ../rbac \ No newline at end of file diff --git a/utils/kind-cluster.yaml b/utils/kind-cluster.yaml new file mode 100644 index 00000000..14fea8e5 --- /dev/null +++ b/utils/kind-cluster.yaml @@ -0,0 +1,6 @@ +--- +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: + - role: control-plane + image: kindest/node:v1.27.3 From 8659e3284dee4c03d395c99824262461f8b9ac62 Mon Sep 17 00:00:00 2001 From: Jim Fitzpatrick Date: Thu, 31 Aug 2023 10:50:23 +0100 Subject: [PATCH 2/2] Change pre PR review --- Makefile | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index bde1bcd7..0458dd5c 100644 --- a/Makefile +++ b/Makefile @@ -347,25 +347,6 @@ verify-fmt: fmt ## Verify fmt update. git diff --exit-code ./api ./controllers ## local configurations - -deploy-develmode: manifests kustomize ## Deploy controller in debug mode to the K8s cluster specified in ~/.kube/config. - cd config/manager && $(KUSTOMIZE) edit set image controller=${OPERATOR_IMAGE} - @if [ $(NAMESPACE) != '' ];then \ - echo "Setting Custom Namespace: $(NAMESPACE)"; \ - cd $(PROJECT_DIR)/config/default && $(KUSTOMIZE) edit set namespace $(NAMESPACE); \ - fi - - cd $(PROJECT_DIR) && $(KUSTOMIZE) build config/deploy > $(DEPLOYMENT_FILE) - - $(KUSTOMIZE) build config/default | kubectl apply -f - - -# clean up - cd config/manager && $(KUSTOMIZE) edit set image controller=${DEFAULT_OPERATOR_IMAGE} - @if [ $(NAMESPACE) != '' ];then \ - echo "Removing Custom Namespace: $(NAMESPACE)"; \ - cd $(PROJECT_DIR)/config/default && $(KUSTOMIZE) edit set namespace $(DEFAULT_REPO); \ - fi - .PHONY: local-cleanup local-cleanup: $(MAKE) kind-delete-cluster @@ -386,9 +367,9 @@ local-setup: $(MAKE) install $(MAKE) deploy -.PHONY: local-redeploy -local-redeploy: export OPERATOR_IMAGE := authorino-operator:dev -local-redeploy: +.PHONY: local-rollout +local-rollout: export OPERATOR_IMAGE := authorino-operator:dev +local-rollout: $(MAKE) docker-build echo "Deploying Authorino control plane" $(KIND) load docker-image ${OPERATOR_IMAGE} --name ${KIND_CLUSTER_NAME}