sample-operator

command
v0.0.0-...-f8211af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

README

Sample Operator

The sample operator creates a custom resources and watches for changes.

Code Generation

K8s 1.8 requires code generation for all CRDs. See the code generation sample for the steps taken to generate the necessary types for this walkthrough. You can skip those details if all you want to do is get the sample running.

Build

# from the root of the repo pull all the libraries needed for operator-kit (this may take a while with all the Kubernetes dependencies)
dep ensure

# change directory to sample-operator
cd sample-operator

# build the sample operator binary
CGO_ENABLED=0 GOOS=linux go build

# build the docker container
# Note: If you are using minikube, don't forget to run "eval $(minikube docker-env)" first!
docker build -t sample-operator:0.1 .

Start the Operator

# Create the sample operator
$ kubectl create -f sample-operator.yaml

# Wait for the pod status to be Running
$ kubectl get pod -l app=sample-operator
NAME                              READY     STATUS    RESTARTS   AGE
sample-operator-821691060-m5vqp   1/1       Running   0          3m

# View the samples CRD
$ kubectl get crd samples.myproject.io
NAME                   KIND
samples.myproject.io   CustomResourceDefinition.v1beta1.apiextensions.k8s.io

Create the Sample Resource

# Create the sample
$ kubectl create -f sample-resource.yaml

# See the sample resource
$ kubectl get samples.myproject.io
NAME       KIND
mysample   Sample.v1alpha1.myproject.io

Modify the Sample Resource

Change the value of the Hello property in sample-resource.yaml, then apply the new yaml.

kubectl apply -f sample-resource.yaml

Logs

Notice the added and modified Hello= text in the log below

$ kubectl logs -l app=sample-operator
Getting kubernetes context
Creating the sample resource
Managing the sample resource
Added Sample 'mysample' with Hello=world!
Updated sample 'mysample' from world to goodbye!

Cleanup

kubectl delete -f sample-resource.yaml
kubectl delete -f sample-operator.yaml
kubectl delete crd samples.myproject.io

Documentation

Overview

Package main for a sample operator

Package main for a sample operator

Directories

Path Synopsis
pkg
apis/myproject/v1alpha1
Package v1 is the v1 version of the API.
Package v1 is the v1 version of the API.
client/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
client/clientset/versioned/typed/myproject/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/myproject/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL