cnat-kubebuilder/

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 Kubebuilder and then bootstrap the At operator as follows:

$ mkdir cnat-kubebuilder && cd $_

$ kubebuilder init \
              --domain programming-kubernetes.info \
              --license apache2 \
              --owner "We, the Kube people"

$ kubebuilder create api \
              --group cnat \
              --version v1alpha1 \
              --kind At
Create Resource under pkg/apis [y/n]?
y
Create Controller under pkg/controller [y/n]?
y
...

Launch operator locally

# install CRD via:
$ make install

# create the dedicated namespace and set the context to it:
$ kubectl create ns cnat && \
  kubectl config set-context $(kubectl config current-context) --namespace=cnat

# launch operator:
$ make run

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

$ kubectl apply -f config/samples/cnat_v1alpha1_at.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     Completed     0          32s

Implement business logic

  • In at_types.go: we modify the AtSpec struct to include the respective fields such as schedule and command. Note that you must run make whenever you change something here in order to regenerate the controller code.
  • 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
Package apis contains Kubernetes API groups.
Package apis contains Kubernetes API groups.
apis/cnat
Package cnat contains cnat API versions
Package cnat contains cnat API versions
apis/cnat/v1alpha1
Package v1alpha1 contains the cnat v1alpha1 API group +k8s:deepcopy-gen=package +groupName=cnat.programming-kubernetes.info Package v1alpha1 contains API Schema definitions for the cnat v1alpha1 API group +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:conversion-gen=github.com/programming-kubernetes/cnat/cnat-kubebuilder/pkg/apis/cnat +k8s:defaulter-gen=TypeMeta +groupName=cnat.programming-kubernetes.info
Package v1alpha1 contains the cnat v1alpha1 API group +k8s:deepcopy-gen=package +groupName=cnat.programming-kubernetes.info Package v1alpha1 contains API Schema definitions for the cnat v1alpha1 API group +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:conversion-gen=github.com/programming-kubernetes/cnat/cnat-kubebuilder/pkg/apis/cnat +k8s:defaulter-gen=TypeMeta +groupName=cnat.programming-kubernetes.info

Jump to

Keyboard shortcuts

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