This repo is a fork of RedHat operator-sdk and will be re-used to develop composition-sdk.
run make all
. an executable named operator-sdk
will be created under build/
directory.
-
Set your namespace:
export NAMESPACE=...
-
deploy the following operators (instructions are available inside each of them):
-
Deploy the sleep sample from the istio.io. You will use this sample to send
curl
commands to the Multi-Language-Hello application. (No features of istio.io are used in this demo, you will only use the sample from the project's repository).$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/master/samples/sleep/sleep.yaml -n $NAMESPACE
-
Export the sleep pod as an environment variable:
$ export SLEEP_POD=$(kubectl get pod -l app=sleep -n $NAMESPACE -o jsonpath={.items..metadata.name})
-
Generate a new composition operator using composition-sdk.
The sdk expects to get as an inputapi-version
andkind
of the generated CRD and a network service template:nsvc_template.yaml
apiVersion: gnforchestrator.ibm.com/v2alpha1 kind: NetworkService metadata: name: example-pingpong labels: service: pingpong spec: properties: message: "Hello" components: ping: template: apiVersion: ping.example.com/v1alpha1 kind: Ping metadata: name: "[% meta.name %]-ping" namespace: "[% meta.namespace %]" spec: pingVersion: v1.0 pongAddress: "[% pong.status.ip %]" pongPort: 6006 pong: template: apiVersion: pong.example.com/v1alpha1 kind: Pong metadata: name: "[% meta.name %]-pong" namespace: "[% meta.namespace %]" spec: pongVersion: v1.4 message: "[% message %]" statusTemplate: ip: "[% ping.status.ip %]" port: "[% ping.status.port %]"
$ operator-sdk composition test-operator \ --api-version=pingpong.example.com/v1alpha1 \ --kind=Pingpong \ --generate-playbook \ --nsvc-template=nsvc_template.yaml
This command generates a skeletal test-operator application in the current directory.
-
Implement your Pingpong CRD and CRs inside the generated operator under
deploy/crds
directory. -
Install the new operator as explained in the auto generated
README.md
file.export REGISTRY=<YOUR REGISTRY> export IMAGE=$REGISTRY/$(basename $(pwd)):v0.0.1 make docker-push "IMAGE=$IMAGE" "NAMESPACE=$NAMESPACE" make install "IMAGE=$IMAGE" "NAMESPACE=$NAMESPACE"
-
Deploy Pingpong:
deploy/crds/pingpong.example.com_v1alpha1_pingpong_cr_message.yaml
apiVersion: pingpong.example.com/v1alpha1 kind: Pingpong metadata: name: example-pingpong spec: message: HelloWorldTest pingVersion: Ping1 pongVersion: Pong1
$ kubectl apply -f deploy/crds/pingpong.example.com_v1alpha1_pingpong_cr_message.yaml -n $NAMESPACE
-
Watch the network services resources being created:
$ watch kubectl get pingpong,nsvc,ping,pong,pod -n $NAMESPACE
-
Create aliases to get the IP address and port of the pingpong resource:
alias example-ip='kubectl get pingpong example-pingpong -n $NAMESPACE -o jsonpath={.status.ip}' alias example-port='kubectl get pingpong example-pingpong -n $NAMESPACE -o jsonpath={.status.port}'
-
Run
curl
to ping hello endpoint:$ kubectl exec -it $SLEEP_POD -n $NAMESPACE -- curl $(example-ip):$(example-port)/hello Hello from Ping VNF
-
Run
curl
to perform ping pong 3 times:$ kubectl exec -it $SLEEP_POD -n $NAMESPACE -- curl $(example-ip):$(example-port)/ping/3 ping version v1.0: pong version v1.4 message HelloWorldTest.pong version v1.4 message HelloWorldTest.pong version v1.4 message HelloWorldTest.
-
Clean Pingpong:
$ kubectl delete -f deploy/crds/pingpong.example.com_v1alpha1_pingpong_cr_message.yaml -n $NAMESPACE
Docs can be found on the Operator SDK website.
This project is a component of the Operator Framework, an open source toolkit to manage Kubernetes native applications, called Operators, in an effective, automated, and scalable way. Read more in the introduction blog post.
Operators make it easy to manage complex stateful applications on top of Kubernetes. However writing an operator today can be difficult because of challenges such as using low level APIs, writing boilerplate, and a lack of modularity which leads to duplication.
The Operator SDK is a framework that uses the controller-runtime library to make writing operators easier by providing:
- High level APIs and abstractions to write the operational logic more intuitively
- Tools for scaffolding and code generation to bootstrap a new project fast
- Extensions to cover common operator use cases
Operator SDK is under Apache 2.0 license. See the LICENSE file for details.