ndb-operator

module
v0.0.0-...-ab0235b Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: Apache-2.0

README

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

Directories

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

Jump to

Keyboard shortcuts

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