Cheat Sheet

Operator-SDK Cheat Sheet commands and operations

Below you will find a cheat sheet with options and helpers for projects, which are built with the SDK and are respecting its proposed layout.

Common commands and options

CommandDescription
operator-sdk initTo initialize an operator project in the current directory.
operator-sdk init —plugins=<plugin-key>To initialize an operator project in the current directory using a specific plugin. To check the available plugins you can run oparator-sdk —help. E.g (operator-sdk init —plugins=helm).
operator-sdk create api [flags]Lets you create your own APIs with its GKV by Extending the Kubernetes API with CustomResourceDefinitions, or lets you use external/core-types. Also generates their respective controllers.
operator-sdk create webhook [flags]To scaffold Webhooks for the APIs declared in the project. Currently, only the Go-based project supports this option.
make docker-build IMG=<some-registry>/<project-name>:<tag>Build the operator image.
make docker-build docker-push IMG=<some-registry>/<project-name>:<tag>Build and push the operator image for your registry.
make installInstall the CRDs into the cluster.
make uninstallUninstall the CRDs into the cluster.
make runRun your controller locally and outside of the cluster. Note that this will run in the foreground, so switch to a new terminal if you want to leave it running.
make deployDeploy your project on the cluster.
make undeployUndeploy your project on the cluster.

To create bundles, catalogs, and develop for OLM

For further information check Operator SDK Integration with Operator Lifecycle Manager.

CommandDescription
make bundleCreate/update the bundle based on the project manifests in the bundle/ directory. For more info see Create a bundle.
operator-sdk bundle validate ./bundleTo validate your bundle spec definition.
operator-sdk bundle validate ./bundle —select-optional suite=operatorframeworkValidate your bundle against OperatorHub.io criteria. For further information use the flag —help.
operator-sdk olm installTo install OLM on your cluster for development purposes.
operator-sdk olm uninstallTo uninstall OLM from your cluster.
make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>To build your bundle operator image.
make bundle-build bundle-push BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>To build and push your bundle operator image.
operator-sdk run bundle <some-registry>/<project-name-bundle>:<tag>To deploy your bundle operator using OLM on your cluster for development purposes.
operator-sdk run bundle private-registry.org/bundle:v1.2.3 —service-account sa-with-secret —pull-secret-name regcred —ca-secret-name cert-secConfigure run bundle (and run bundle-upgrade) to use an image pull secret, non-default service account configured with that secret, and custom CA certificate secret

Updating bundle channels

The following examples let you update the bundle with data-informed. For further information also check Upgrade your Operator and see Channel Naming.

NOTE: Note that it will carry over any customizations you have made and ensure a rolling update to the next version of your Operator.

  1. make bundle CHANNELS=fast,preview DEFAULT_CHANNEL=stable VERSION=1.0.0 IMG=<some-registry>/<project-name-bundle>:<tag>

NOTE You can use environment variables to pass the values such as export CHANNELS=fast,candidate. Note that, their values will be used by make bundle command.

To test your projects

CommandDescription
operator-sdk scorecard ./bundleRun the Scorecard tests for your bundle.
make testRun Go tests. It is valid only for Go-based operators.
molecule testRun Molecule tests. It is valid only for Ansible-based operators.
helm testRun Helm chart tests. It is valid only for Helm-based operators.

NOTE: This is not a comprehensive list of make targets or commands. Please see the scaffolded Makefile and make help for the full list of targets. Note that you can use operator-sdk <command> --help and check the CLI section to check all options.

Last modified August 11, 2021: WIP (#5135) (a05f9668)