Skip to content

IBM/CompositionSDK

This repo is a fork of RedHat operator-sdk and will be re-used to develop composition-sdk.

Build sdk

run make all. an executable named operator-sdk will be created under build/ directory.

Walkthrough example

Pre-requisites

  1. Set your namespace:

    export NAMESPACE=...
    
  2. deploy the following operators (instructions are available inside each of them):

    1. gnforchestrator
    2. ping-operator
    3. pong-operator

Demo steps

  1. 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
    
  2. Export the sleep pod as an environment variable:

    $ export SLEEP_POD=$(kubectl get pod -l app=sleep -n $NAMESPACE -o jsonpath={.items..metadata.name})
    
  3. Generate a new composition operator using composition-sdk.
    The sdk expects to get as an input api-version and kind 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.

  4. Implement your Pingpong CRD and CRs inside the generated operator under deploy/crds directory.

  5. 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"
    
  6. 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
    
  7. Watch the network services resources being created:

    $ watch kubectl get pingpong,nsvc,ping,pong,pod -n $NAMESPACE
    
  8. 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}'
    
  9. Run curl to ping hello endpoint:

    $ kubectl exec -it $SLEEP_POD -n $NAMESPACE -- curl $(example-ip):$(example-port)/hello
    Hello from Ping VNF
    
  10. 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.
    
  11. Clean Pingpong:

    $ kubectl delete -f deploy/crds/pingpong.example.com_v1alpha1_pingpong_cr_message.yaml -n $NAMESPACE
    

Build Status License Go Report Card

Documentation

Docs can be found on the Operator SDK website.

Overview

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

License

Operator SDK is under Apache 2.0 license. See the LICENSE file for details.

About

This SDK is an extension of RedHat operator SDK and is meant to to be used for GNF-Orchestrator composition feature

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages