cnat-operator/

directory
v0.0.0-...-27f8ddb Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: Apache-2.0

README

Development

Install the Operator SDK and then bootstrap the At operator as follows:

$ operator-sdk new cnat-operator && cd cnat-operator

$ operator-sdk add api \
               --api-version=cnat.programming-kubernetes.info/v1alpha1 \
               --kind=At

$ operator-sdk add controller \
               --api-version=cnat.programming-kubernetes.info/v1alpha1 \
               --kind=At  

Launch operator locally

$ kubectl apply -f deploy/crds/cnat_v1alpha1_at_crd.yaml

$ kubectl create ns cnat

$ OPERATOR_NAME=cnatop operator-sdk up local --namespace "cnat"

Now, once we create the At custom resource, we see the execution at the scheduled time:

$ kubectl -n cnat apply -f deploy/crds/cnat_v1alpha1_at_cr.yaml

$ kubectl -n cnat  get at,po
NAME                               AGE
at.cnat.programming-kubernetes.info/example-at   54s

NAME                 READY   STATUS             RESTARTS   AGE
pod/example-at-pod   0/1     CrashLoopBackOff   2          34s

Implement business logic

  • In at_types.go: we modify the AtSpec struct to include the respective fields such as schedule and command and use operator-sdk generate k8s to regenerate code (and operator-sdk generate openapi for the OpenAPI bits).
  • In at_controller.go: we modify the Reconcile(request reconcile.Request) method to create a pod at the time defined in Spec.Schedule.

Directories

Path Synopsis
cmd
pkg
apis/cnat/v1alpha1
Package v1alpha1 contains API Schema definitions for the cnat v1alpha1 API group +k8s:deepcopy-gen=package,register +groupName=cnat.programming-kubernetes.info Package v1alpha1 contains API Schema definitions for the cnat v1alpha1 API group +k8s:deepcopy-gen=package,register +groupName=cnat.programming-kubernetes.info
Package v1alpha1 contains API Schema definitions for the cnat v1alpha1 API group +k8s:deepcopy-gen=package,register +groupName=cnat.programming-kubernetes.info Package v1alpha1 contains API Schema definitions for the cnat v1alpha1 API group +k8s:deepcopy-gen=package,register +groupName=cnat.programming-kubernetes.info

Jump to

Keyboard shortcuts

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