When you generate the source code for a Kubernetes operator with Operator
Builder, it can include the code for a companion CLI. The source code for the
companion CLI will be found in the cmd
directory of the generated codebase.
The companion CLI does three things:
- Generate Sample Manifests: the
init
command will save a sample manifest to disk for a custom resource. This gives the end user a convenient way to get started with defining configuration variables. - Generate Child Resource Manifests: the
generate
command prints the manifests for all of the custom resources children - the Kubernetes resources that are created and managed when a custom resource is created. This offers the end user a workaround when they need to configure changes that are not exposed by the operator. - Install the Operator: the
install
command installs the operator, CRDs and necessary resources in a Kubernetes cluster.
These are the CLI configurations:
- No CLI: Don't define any companion CLI data and no CLI source code will be scaffolded.
- A single root command: define the
spec.companionCliRootcmd
fields in a standaloneWorkloadConfig
manifest. - A root command with subcommands: define the
spec.companionCliRootcmd
in a collectionWorkloadConfig
manifest. Then definespec.companionCliSubcmd
in one or more componentWorkloadConfig
manifests.
The root command for the CLI can be defined in a standalone workload or in a workload collection.
If a workload belongs to a collection you may define a subcommand for that workload.