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

Namespace support. #134

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
92 changes: 90 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected])

KIND = $(shell pwd)/bin/kind
kind:
$(call go-get-tool,$(KIND),sigs.k8s.io/[email protected])

YQ = $(shell pwd)/bin/yq
YQ_VERSION := v4.34.2
$(YQ):
Expand Down Expand Up @@ -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); \
Copy link
Collaborator

@guicassolato guicassolato Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have the diff of what this target yields with a custom namespace vs the default one? Likely, this is only because of the role bindings created for the operator, so it sets the right ServiceAccount, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create a diff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is in the gist. I comment out then clean up code when creating the diff.
https://gist.github.com/Boomatang/becfda6a1659f7e864ac039a439889bd

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 -
Expand All @@ -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)
Expand Down Expand Up @@ -307,3 +345,53 @@ verify-bundle: bundle ## Verify bundle update.
.PHONY: verify-fmt
verify-fmt: fmt ## Verify fmt update.
git diff --exit-code ./api ./controllers

## local configurations
.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-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}

@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)
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.:
Expand Down
5 changes: 4 additions & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

# Adds namespace to all resources.
namespace: authorino-operator

Expand All @@ -12,7 +15,7 @@ namespace: authorino-operator
#commonLabels:
# someName: someValue

bases:
resources:
- ../crd
- ../rbac
- ../manager
Expand Down
9 changes: 7 additions & 2 deletions config/deploy/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../authorino
- ../default
- ../authorino
- ../default

namespace: authorino-operator
5 changes: 4 additions & 1 deletion config/install/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

# Adds namespace to all resources.
namespace: authorino-operator

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# namePrefix: authorino-operator-

bases:
resources:
- ../crd
- ../rbac
6 changes: 6 additions & 0 deletions utils/kind-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.27.3