Skip to content

Commit

Permalink
refactor examples/status to conform to Metac (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: AmitKumarDas <[email protected]>
  • Loading branch information
Amit Kumar Das authored Oct 7, 2019
1 parent 0c2ed34 commit c8987c0
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 30 deletions.
11 changes: 6 additions & 5 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
- <ctrl-ns>-<ctrl-name>.dctl.metac.openebs.io/last-applied-config
- <ctrl-ns>-<ctrl-name>.gctl.metac.openebs.io/last-applied-config
- <ctrl-ns>-<ctrl-name>.cctl.metac.openebs.io/last-applied-config
- Should Metac support UDS?
- https://eli.thegreenplace.net/2019/unix-domain-sockets-in-go/

Expand Down
2 changes: 1 addition & 1 deletion examples/service-per-pod/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 28 additions & 4 deletions examples/status/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 3 additions & 1 deletion examples/status/my-noop.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -58,7 +59,7 @@ apiVersion: v1
kind: Service
metadata:
name: noop-controller
namespace: metacontroller
namespace: metac
spec:
selector:
app: noop-controller
Expand Down
13 changes: 12 additions & 1 deletion examples/status/sync.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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'},
};
};
35 changes: 24 additions & 11 deletions examples/status/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c8987c0

Please sign in to comment.