From 51a3b633b4c03d95056662852f98f77101ff14c7 Mon Sep 17 00:00:00 2001 From: Bharathi Tenneti Date: Wed, 8 Jul 2020 11:47:46 -0400 Subject: [PATCH] README updated to add certmanager installation step (#133) * README updated to add certmanager installation step --- go/kubebuilder/memcached-operator/README.md | 41 ++++++++++++++++--- .../config/manager/kustomization.yaml | 1 + 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/go/kubebuilder/memcached-operator/README.md b/go/kubebuilder/memcached-operator/README.md index 2c1755aa..152c4e52 100644 --- a/go/kubebuilder/memcached-operator/README.md +++ b/go/kubebuilder/memcached-operator/README.md @@ -33,24 +33,44 @@ Run the following command ``` $ go mod tidy ``` +***NOTE*** As this example showcases validation webhook creation, please follow [this][certmanager] guide to install cert-mamager into cluster prior to deployment. ### Building the operator Build the Memcached operator image and push it to a public registry, such as quay.io: -``` -$ make install +```shell $ export IMG=quay.io/example-inc/memcached-operator:v0.0.1 -$ make docker-build $IMG -$ docker push $IMG -$ make deploy $IMG +$ make docker-build docker-push IMG=$IMG ``` **NOTE** The `quay.io/example-inc/memcached-operator:v0.0.1` is an example. You should build and push the image for your repository. +### Instaling Operator API + +Install the CRDs into the cluster: + +```shell +$ make install +``` +### Deploying your operator + +Deploy the Memcached Operator to the cluster with image specified by IMG + +```shell +$ make deploy IMG=$IMG +``` + +### Create memcached-sample instances. + +```shell +$ kubectl create -f config/samples/cache_v1alpha1_memcached.yaml -n memcached-operator-system +``` + Please verify expected result. ```shell + $ kubectl get all -n memcached-operator-system NAME READY STATUS RESTARTS AGE pod/memcached-operator-controller-manager-864f7c75d4-7cf47 2/2 Running 0 118s @@ -69,6 +89,16 @@ NAME DESIRED CUR replicaset.apps/memcached-operator-controller-manager-864f7c75d4 1 1 1 118s ``` +### Verifying the validating webhook + +The following command attempts to increase the CR's `spec.size` to an even number. It should throw an error like that shown below, as the validating webhook does not allow an even `spec.size`. + +```console +$ kubectl patch memcached memcached-sample -p '{"spec":{"size": 4}}' --type=merge -n memcached-operator-system + +Error from server (Cluster size must be an odd number): admission webhook "vmemcached.kb.io" denied the request: Cluster size must be an odd number +``` + ### Uninstalling To uninstall all that was performed in the above step run `make uninstall`. @@ -89,3 +119,4 @@ $ kubectl logs deployment.apps/memcached-operator-controller-manager -n memcach [operator_sdk]: https://github.com/operator-framework/operator-sdk [operator_install]: https://sdk.operatorframework.io/docs/install-operator-sdk/ [quickstart]: https://github.com/operator-framework/operator-sdk/blob/master/website/content/en/docs/kubebuilder/quickstart.md#implement-the-controller +[certmanager]: https://cert-manager.io/docs/installation/kubernetes/ diff --git a/go/kubebuilder/memcached-operator/config/manager/kustomization.yaml b/go/kubebuilder/memcached-operator/config/manager/kustomization.yaml index e1c76cf3..8781649c 100644 --- a/go/kubebuilder/memcached-operator/config/manager/kustomization.yaml +++ b/go/kubebuilder/memcached-operator/config/manager/kustomization.yaml @@ -5,3 +5,4 @@ kind: Kustomization images: - name: controller newName: quay.io/example-inc/memcached-operator + newTag: v0.0.1