controller101

module
v0.0.0-...-5362612 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Apache-2.0

README

Controller 101

This repository implements a simple controller for watching VM resources as defined with a CRD.

This example will show you how to perform basic operations such as:

  • How to create a custom resource of type VM using CRD API.
  • How to operate instances of type VM.
  • How to implement a controller for handling an instance of type VM to move the current state towards the desired state.
  • How to use Finalizer on instances of type VM.
  • How to implement LeaseLock for multiple controllers.
  • How to expose metrics of the controller.

Building from Source

Clone the repo in whatever working directory you like, and run the following commands:

$ export GO111MODULE=on
$ git clone https://github.com/cloud-native-taiwan/controller101
$ cd controller101
$ make

Running

Run the following command to debug:

$ minikube start --kubernetes-version=v1.15.4 
$ eval $(minikube docker-env)
$ POD_NAME=test1 go run cmd/main.go --kubeconfig=$HOME/.kube/config \
    -v=3 --logtostderr \
    --lease-lock-namespace=default \
    --vm-driver=docker
...
I1015 02:16:08.067269   53517 leaderelection.go:242] attempting to acquire leader lease  default/controller101...
I1015 02:16:08.083723   53517 leaderelection.go:252] successfully acquired lease default/controller101
I1015 02:16:08.083830   53517 controller.go:77] Starting the controller
I1015 02:16:08.083846   53517 controller.go:78] Waiting for the informer caches to sync
I1015 02:16:08.185334   53517 controller.go:86] Started workers
I1015 02:16:08.185379   53517 main.go:144] test1: leading

Deploy in the cluster

Run the following command to deploy the controller:

$ minikube start --kubernetes-version=v1.15.4
$ minikube docker-env
$ kubectl -n kube-system create secret generic docker-certs \
  --from-file=$HOME/.minikube/certs/ca.pem \
  --from-file=$HOME/.minikube/certs/cert.pem \
  --from-file=$HOME/.minikube/certs/key.pem

# Modify envs in `deploy/deployment.yml` to reflect you need values:
$ kubectl apply -f deploy/

Directories

Path Synopsis
pkg
apis/cloudnative/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/cloudnative/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
generated/clientset/versioned/typed/cloudnative/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