diff --git a/TODO b/TODO index a5b4f41..52e53f0 100644 --- a/TODO +++ b/TODO @@ -12,6 +12,12 @@ - check for 2-way merge as well as 3-way merge - default to 2-way merge if only finalize hook is present - default to 3-way merge if both sync & finalize hooks are present + - send specific parts of attachments: + - send - []string{Name, MetaData, Labels, Annotations, Spec, Status} + - default sends everything + - special annotation & label expressions: + - operator - WatchIsOwner, WatchIsCreator, WatchIsUpdater + - operator - WatchInKey, WatchInValue, ValueContainsWatch, KeyContainsWatch - gctl - read & review - https://github.com/GoogleCloudPlatform/metacontroller/issues/98 @@ -49,11 +55,6 @@ ### Future Actions: - Make metacontroller watch resources from specific namespace if required -- If multiple meta controllers work against a resource then apply function might be buggy - - Provide last-applied-configuration per meta controller resource - - -.dctl.metac.openebs.io/last-applied-config - - -.gctl.metac.openebs.io/last-applied-config - - -.cctl.metac.openebs.io/last-applied-config - Should Metac support UDS? - https://eli.thegreenplace.net/2019/unix-domain-sockets-in-go/ diff --git a/examples/service-per-pod/test.sh b/examples/service-per-pod/test.sh index 27a78d8..f4e6d95 100755 --- a/examples/service-per-pod/test.sh +++ b/examples/service-per-pod/test.sh @@ -11,7 +11,7 @@ cleanup() { kubectl patch statefulset nginx --type=merge -p '{"metadata":{"finalizers":[]}}' || true kubectl delete -f my-statefulset.yaml || true - kubectl delete -f service-per-pod.yaml || true + kubectl delete -f operator.yaml || true kubectl delete svc -l app=service-per-pod || true kubectl delete configmap service-per-pod-hooks -n metac || true diff --git a/examples/status/README.md b/examples/status/README.md index 87e5f5d..2e1dc1d 100644 --- a/examples/status/README.md +++ b/examples/status/README.md @@ -4,17 +4,41 @@ This is an example DecoratorController returning a status ### Prerequisites -* Install [Metacontroller](https://github.com/GoogleCloudPlatform/metacontroller) +* Install Metac from the manifests folder -### Deploy the controller +```sh +# verify creation of CRDs +kubectl get crd +``` + +### Steps to deploy Noop controller ```sh +# This configmap embeds the sync hook file (a javascript impl). +# This hook file is injected into noop controller. +# +# NOTE: +# Noop controller is a nodejs server exposing a http endpoint URL +# ending with '/sync' kubectl create configmap noop-controller -n metacontroller --from-file=sync.js -kubectl apply -f noop-controller.yaml + +# Deploy the Noop controller +kubectl apply -f operator.yaml + +# Verify creation of CRD +kubectl get crd noops.metac.openebs.io -oyaml + +# Verify creation of Noop operator +kubectl get deploy -n metac +kubectl get svc -n metac +kubectl get configmap -n metac ``` -### Create a Noop +### Verify by creating a Noop resource ```sh kubectl apply -f my-noop.yaml + +# verify if status is set with 'success' +kubectl get noop -oyaml ``` diff --git a/examples/status/my-noop.yaml b/examples/status/my-noop.yaml index a2f9c8a..697a64a 100644 --- a/examples/status/my-noop.yaml +++ b/examples/status/my-noop.yaml @@ -1,4 +1,6 @@ -apiVersion: metacontroller.k8s.io/v1 +apiVersion: metac.openebs.io/v1 +# Doesn't this sound great for creating your +# own test controllers kind: Noop metadata: name: noop diff --git a/examples/status/noop-controller.yaml b/examples/status/operator.yaml similarity index 79% rename from examples/status/noop-controller.yaml rename to examples/status/operator.yaml index a7fe18e..799128a 100644 --- a/examples/status/noop-controller.yaml +++ b/examples/status/operator.yaml @@ -1,9 +1,9 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: noops.metacontroller.k8s.io + name: noops.metac.openebs.io spec: - group: metacontroller.k8s.io + group: metac.openebs.io version: v1 scope: Namespaced names: @@ -13,24 +13,25 @@ spec: subresources: status: {} --- -apiVersion: metacontroller.k8s.io/v1alpha1 +apiVersion: metac.openebs.io/v1alpha1 kind: DecoratorController metadata: name: noop-controller spec: resources: - - apiVersion: metacontroller.k8s.io/v1 + # we are interested for noops resource only + - apiVersion: metac.openebs.io/v1 resource: noops hooks: sync: webhook: - url: http://noop-controller.metacontroller/sync + url: http://noop-controller.metac/sync --- apiVersion: apps/v1beta1 kind: Deployment metadata: name: noop-controller - namespace: metacontroller + namespace: metac spec: replicas: 1 selector: @@ -58,7 +59,7 @@ apiVersion: v1 kind: Service metadata: name: noop-controller - namespace: metacontroller + namespace: metac spec: selector: app: noop-controller diff --git a/examples/status/sync.js b/examples/status/sync.js index 2e354a9..179aef1 100644 --- a/examples/status/sync.js +++ b/examples/status/sync.js @@ -1,5 +1,6 @@ /* Copyright 2017 Google Inc. +Copyright 2019 The MayaData Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,5 +17,15 @@ limitations under the License. module.exports = async function (context) { - return {status: 200, body: { status: { message: "success"} }, headers: {'Content-Type': 'application/json'}}; + return { + status: 200, + body: { + // Noop resource will have this status set + // after the sync operation + status: { + message: "success", + }, + }, + headers: {'Content-Type': 'application/json'}, + }; }; diff --git a/examples/status/test.sh b/examples/status/test.sh index 61a76b8..d62ca06 100755 --- a/examples/status/test.sh +++ b/examples/status/test.sh @@ -2,27 +2,40 @@ cleanup() { set +e - echo "Clean up..." + echo "" + + echo "--------------------------" + echo "++ Clean up started" + echo "--------------------------" + kubectl delete -f my-noop.yaml kubectl delete rs,svc -l app=noop-controller - kubectl delete -f noop-controller.yaml - kubectl delete configmap noop-controller -n metacontroller + kubectl delete -f operator.yaml + kubectl delete configmap noop-controller -n metac + + echo "--------------------------" + echo "++ Clean up completed" + echo "--------------------------" } +# Comment below if you want to check manually +# the state of the cluster and intended resources trap cleanup EXIT -set -ex +# Uncomment below if debug / verbose execution is needed +#set -ex -np="noops.metacontroller.k8s.io" +# noop crd name +np="noops.metac.openebs.io" -echo "Install controller..." -kubectl create configmap noop-controller -n metacontroller --from-file=sync.js -kubectl apply -f noop-controller.yaml +echo -e "\n++Will install Noop operator..." +kubectl create configmap noop-controller -n metac --from-file=sync.js +kubectl apply -f operator.yaml -echo "Wait until CRD is available..." +echo -e "\n++Wait until CRD is available..." until kubectl get $np; do sleep 1; done -echo "Create an object..." +echo -e "\n++Will apply Noop resource..." kubectl apply -f my-noop.yaml -echo "Wait for status to be updated..." +echo -e "\n++Wait for Noop resource's status to be updated..." until [[ "$(kubectl get $np noop -o 'jsonpath={.status.message}')" == "success" ]]; do sleep 1; done