Skip to content

ocklin/ndb-operator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ndb-operator

This repository implements a simple controller for watching Ndb resources as defined with a CustomResourceDefinition (CRD).

This is pre-alpha - mostly prototyping for testing concepts.

Details

The ndb controller uses client-go library extensively.

Fetch ndb-operator and its dependencies

The ndb-operator uses go modules and has been developed with go 1.13.

git clone <this repo>
cd ndb-operator

Changes to the types

Note, if you intend to change the types then you will need to generate code which only seems to support old style $GOPATH.

First it depends on the vendor directory. Populate that with

go mod vendor

The code generator script script will generate files & directories:

  • pkg/apis/ndbcontroller/v1alpha1/zz_generated.deepcopy.go
  • pkg/generated/

It requires some copying as described in the script.

Generators are in k8s.io/code-generator and generate a typed client, informers, listers and deep-copy functions.

Building

You may have to set the OS variable to your operating system in the Makefile.

# Build ndb-operator 
make build

Docker image building

You can build your own ndb cluster images but you don't have to. Currently public image 8.0.22 is used.

Prerequisite: You have a build directory available that is build for OL8. You can use a OL8 build-container in docker/ol8 for that or download a readily compiled OL8 build.

If you use minikube then set the environment to minikube first before building the image.

# copy necessary ndb binaries 
make install-minimal

# point to minikube
$ eval $(minikube docker-env)

# build docker image
make build-docker

Running

Prerequisite: operator built, docker images built and made available in kubernetes

Create custom resource definitions and the roles:

NAMESPACE=default
kubectl -n ${NAMESPACE} apply -f artifacts/manifests/crd.yaml
sed -e "s/<NAMESPACE>/${NAMESPACE}/g" artifacts/manifests/rbac.yaml | kubectl -n ${NAMESPACE} apply -f -

or use helm

helm install ndb-operator helm

the proceed with starting the operator - currently outside of the k8 cluster:

./ndb-operator -kubeconfig=$HOME/.kube/config

# create a custom resource of type Ndb
kubectl apply -f artifacts/examples/example-ndb.yaml

# check statefulsets created through the custom resource
kubectl get pods,statefulsets

# watch pods change state
kubectl get pods -w

# "log into" pods with 
kubectl exec -ti pod/example-ndb-mgmd-0 -- /bin/bash

You can delete the cluster installation again with

kubectl delete -f artifacts/examples/example-ndb.yaml

Defining types

The Ndb instance of our custom resource has an attached Spec, which is defined in types.go

Validation

To validate custom resources, use the CustomResourceValidation feature.

This feature is beta and enabled by default in v1.9.

Example

The schema in crd-validation.yaml applies the following validation on the custom resource: spec.replicas must be an integer and must have a minimum value of 1 and a maximum value of 10.

In the above steps, use crd-validation.yaml to create the CRD:

# create a CustomResourceDefinition supporting validation
kubectl create -f artifacts/examples/crd-validation.yaml

Subresources

TBD

Cleanup

You can clean up the created CustomResourceDefinition with:

kubectl delete crd ndbs.ndbcontroller.k8s.io

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published