Skip to content

Instantly share code, notes, and snippets.

@madorn
Last active May 10, 2018 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madorn/f921feb578361aa69afb38394fe25d54 to your computer and use it in GitHub Desktop.
Save madorn/f921feb578361aa69afb38394fe25d54 to your computer and use it in GitHub Desktop.

Install Docker

Install Go

MacOS

brew install go
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/bin:$GOPATH/bin

Linux

wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz
sudo tar -xvf go1.10.2.linux-amd64.tar.gz -C /usr/local/
mkdir -p $HOME/go/src
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

Windows

choco install golang

Create folder at C:\go-work.
Right click on "Start" and click on "Control Panel". Select "System and Security", then click on "System".
From the menu on the left, select the "Advanced systems settings".
Click the "Environment Variables" button at the bottom.
Click "New" from the "User variables" section.
Type GOPATH into the "Variable name" field.
Type C:\go-work into the "Variable value" field.
Click OK.

Install Dep

MacOS

brew install dep

Linux

curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

Windows

choco install dep

Install the Operator SDK

Clone the Operator SDK to $GOPATH/src

go get -d -v github.com/operator-framework/operator-sdk

Navigate to the Operator SDK source directory containing the Gopkg.lock file

cd $GOPATH/src/github.com/operator-framework/operator-sdk

Install the Operator SDK's dependencies

dep ensure -v

Install the Operator SDK

go install github.com/operator-framework/operator-sdk/commands/operator-sdk

Verify the Operator SDK was successfully installed

operator-sdk --version

Create a new directory for your custom operator in the $GOPATH/src/github.com directory

mkdir $GOPATH/src/github.com/memcached-operator

Navigate to the custom operator directory

cd $GOPATH/src/github.com/memcached-operator

Create the project scaffold for the new custom operator. See https://github.com/operator-framework/operator-sdk/blob/master/doc/project_layout.md

operator-sdk new memcached-operator --api-version=cache.example.com/v1alpha1 --kind=Memcached

Modify the spec and status of the Memcached CRD at pkg/apis/cache/v1alpha1/types.go

type MemcachedSpec struct {
	// Size is the size of the memcached deployment
	Size int32 `json:"size"`
}
type MemcachedStatus struct {
	// Nodes are the names of the memcached pods
	Nodes []string `json:"nodes"`
}

Update the generated code for the CR

operator-sdk generate k8s

Update the custom logic found in the Handle() function at pkg/stub/handler.go.

https://gist.githubusercontent.com/madorn/974f3b0b841c0d4621ef4b12ce5d6a14/raw/6f62c728587ad3c3a4e20d68df06e1a167f8fc2e/handler.go

Build the Operator!

operator-sdk build quay.io/madorn/memcached-operator:v0.0.1

Push the Operator!

docker push quay.io/madorn/memcached-operator:v0.0.1

Deploy the generated manifests manually to a Kubernetes environment.

kubectl apply -f deploy/deploy.yaml

Go Get or Clone the Operator Lifecycle Manager repo

go get -d -v github.com/operator-framework/operator-lifecycle-manager

Fire up minishift or minikube

minikube start --kubernetes-version=v1.10.0
minishift start --openshift-version=v3.9.0

Create a namespace for the Opertor Lifecycle Manager

kubectl create namespace tectonic-system

Install the Operator Lifecycle Manager

kubectl apply -f operator-lifecycle-manager/deploy/tectonic-alm-operator/manifests/0.4.0

Verify OLM is running

kubectl get pods -n tectonic-system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment