Skip to content

tiagoangelozup/operators-hands-on

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

operators-hands-on

Set up your environment

Create your KinD cluster:

kind create cluster --name operators-hands-on

Project creation

Use the OperatorSDK to create a new operator project:

mkdir -p $HOME/dev/projects/hello-kubernetes-operator
cd $HOME/dev/projects/hello-kubernetes-operator
# obs: if your version is newer than 1.16, you can skip de validation --skip-go-version-check
operator-sdk init --domain zup.com --repo github.com/example/hello-kubernetes-operator

Create a new API and Controller

operator-sdk create api --group install --version v1alpha1 --kind HelloKubernetes --resource --controller

API definition

Define your API that is represented in api/v1alpha1/hellokubernetes_types.go by HelloKubernetesSpec type:

// HelloKubernetesSpec defines the desired state of HelloKubernetes
type HelloKubernetesSpec struct {
	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
	// Important: Run "make" to regenerate code after modifying this file

	Enabled bool `json:"enabled"`
}

Then update the generated code and the CRD manifests by running:

make generate manifests

Now you can install your new API by running:

make install

Implement the Controller

The controller template file on method Reconcile at controllers/hellokubernetes_controller.go

Reconcilers return options

The following are a few possible return options for a Reconciler:

  • With the error:

    return ctrl.Result{}, err
  • Without an error:

    return ctrl.Result{Requeue: true}, nil
  • Therefore, to stop the Reconcile, use:

    return ctrl.Result{}, nil
  • Reconcile again after X time:

     return ctrl.Result{RequeueAfter: nextRun.Sub(r.Now())}, nil

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages