diff --git a/Makefile b/Makefile index 975f282..c814c80 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,11 @@ deploy: manifests cd config/manager && kustomize edit set image controller=${IMG} kustomize build config/default | kubectl apply -f - +# Deploy controller using the "Prod" example overlay +deploy-prod: manifests + cd config/manager && kustomize edit set image controller=${IMG} + kustomize build config/overlays/prod | kubectl apply -f - + # Generate manifests e.g. CRD, RBAC etc. manifests: controller-gen $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases @@ -87,3 +92,19 @@ CONTROLLER_GEN=$(GOBIN)/controller-gen else CONTROLLER_GEN=$(shell which controller-gen) endif + +# Setup Test Namespace and artifacts +test-setup: + kubectl create ns test1 + kubectl label ns test1 k8s.twr.dev/owner="user1" + kubectl apply -f ./testing/kubernetes/crdb-sts.yaml -n test1 + +set-reclaim-delete: + kubectl -n test1 label pvc --all storage.k8s.twr.dev/reclaim-policy=Delete --overwrite + +set-reclaim-retain: + kubectl -n test1 label pvc --all storage.k8s.twr.dev/reclaim-policy=Retain --overwrite + +set-reclaim-recycle: + kubectl -n test1 label pvc --all storage.k8s.twr.dev/reclaim-policy=Recycle --overwrite + diff --git a/config/overlays/prod/kustomization.yaml b/config/overlays/prod/kustomization.yaml new file mode 100644 index 0000000..0c45058 --- /dev/null +++ b/config/overlays/prod/kustomization.yaml @@ -0,0 +1,5 @@ +resources: + - "../../default" + +patchesStrategicMerge: + - "volrec-startup-args-patch.yaml" \ No newline at end of file diff --git a/config/overlays/prod/volrec-startup-args-patch.yaml b/config/overlays/prod/volrec-startup-args-patch.yaml new file mode 100644 index 0000000..d7704f2 --- /dev/null +++ b/config/overlays/prod/volrec-startup-args-patch.yaml @@ -0,0 +1,17 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: volrec-controller + namespace: volrec-system +spec: + replicas: 2 + template: + spec: + containers: + - name: volrec + command: + - /manager + args: + - --enable-leader-election + - --set-owner + - --set-ns diff --git a/notes/testing.md b/notes/testing.md index 9f0aeab..4d66108 100644 --- a/notes/testing.md +++ b/notes/testing.md @@ -1,21 +1,20 @@ # Notes on Testing the volrec Controller -## Create Test Namespace +## Deploy Volrec ```shell -$ kubectl create ns test1 +$ make deploy-prod ``` -## Label Namespace +## Setup Test environment -```shell -$ kubectl label ns test1 k8s.twr.dev/owner="user1" -``` +This creates a test namespace, applies appropriate labels, and deploys a sample Statefulset with dynamic PVC/PV's. + +The PVC claim wihtin the Statefulset is configured to set PV reclaim policy from to `Retain`. -## Deploy Test Statefulset ```shell -$ kubectl apply -f ./testing/kubernetes/crdb-sts.yaml -n test1 +$ make test-setup ``` ## Check the logs of the controller @@ -27,7 +26,9 @@ $ kubectl logs -n volrec-system -l app=volrec -c volrec -f ## Apply labels to PVC to change Reclaim Policy ```shell -$ kubectl label pvc -n test1 datadir-crdb1-0 storage.k8s.twr.dev/reclaim-policy=Retain --overwrite +$ make set-reclaim-delete +$ make set-reclaim-recycle +$ make set-reclaim-retain ``` NOTE: The default Reclaim Policy could differ, so update the label value to something pertinent for your environment