Este contenido no está disponible en el idioma seleccionado.
Chapter 7. Operator SDK
7.1. Installing the Operator SDK CLI Copiar enlaceEnlace copiado en el portapapeles!
The Operator SDK provides a command-line interface (CLI) tool that Operator developers can use to build, test, and deploy an Operator. You can install the Operator SDK CLI on your workstation so that you are prepared to start authoring your own Operators.
See Developing Operators for full documentation on the Operator SDK.
OpenShift Container Platform 4.8 and later supports Operator SDK v1.8.0.
7.1.1. Installing the Operator SDK CLI Copiar enlaceEnlace copiado en el portapapeles!
You can install the OpenShift SDK CLI tool on Linux.
Prerequisites
- Go v1.16+
-
v17.03+,
dockerv1.9.3+, orpodmanv1.7+buildah
Procedure
- Navigate to the OpenShift mirror site.
-
From the directory, download the latest version of the tarball for Linux.
4.8.4 Unpack the archive:
$ tar xvf operator-sdk-v1.8.0-ocp-linux-x86_64.tar.gzMake the file executable:
$ chmod +x operator-sdkMove the extracted
binary to a directory that is on youroperator-sdk.PATHTipTo check your
:PATH$ echo $PATH$ sudo mv ./operator-sdk /usr/local/bin/operator-sdk
Verification
After you install the Operator SDK CLI, verify that it is available:
$ operator-sdk versionExample output
operator-sdk version: "v1.8.0-ocp", ...
7.2. Operator SDK CLI reference Copiar enlaceEnlace copiado en el portapapeles!
The Operator SDK command-line interface (CLI) is a development kit designed to make writing Operators easier.
Operator SDK CLI syntax
$ operator-sdk <command> [<subcommand>] [<argument>] [<flags>]
Operator authors with cluster administrator access to a Kubernetes-based cluster (such as OpenShift Container Platform) can use the Operator SDK CLI to develop their own Operators based on Go, Ansible, or Helm. Kubebuilder is embedded into the Operator SDK as the scaffolding solution for Go-based Operators, which means existing Kubebuilder projects can be used as is with the Operator SDK and continue to work.
See Developing Operators for full documentation on the Operator SDK.
7.2.1. bundle Copiar enlaceEnlace copiado en el portapapeles!
The
operator-sdk bundle
7.2.1.1. validate Copiar enlaceEnlace copiado en el portapapeles!
The
bundle validate
| Flag | Description |
|---|---|
|
| Help output for the
|
|
| Tool to pull and unpack bundle images. Only used when validating a bundle image. Available options are
|
|
| List all optional validators available. When set, no validators are run. |
|
| Label selector to select optional validators to run. When run with the
|
7.2.2. cleanup Copiar enlaceEnlace copiado en el portapapeles!
The
operator-sdk cleanup
run
| Flag | Description |
|---|---|
|
| Help output for the
|
|
| Path to the
|
|
| If present, namespace in which to run the CLI request. |
|
| Time to wait for the command to complete before failing. The default value is
|
7.2.3. completion Copiar enlaceEnlace copiado en el portapapeles!
The
operator-sdk completion
| Subcommand | Description |
|---|---|
|
| Generate bash completions. |
|
| Generate zsh completions. |
| Flag | Description |
|---|---|
|
| Usage help output. |
For example:
$ operator-sdk completion bash
Example output
# bash completion for operator-sdk -*- shell-script -*-
...
# ex: ts=4 sw=4 et filetype=sh
7.2.4. create Copiar enlaceEnlace copiado en el portapapeles!
The
operator-sdk create
7.2.4.1. api Copiar enlaceEnlace copiado en el portapapeles!
The
create api
init
| Flag | Description |
|---|---|
|
| Help output for the
|
7.2.5. generate Copiar enlaceEnlace copiado en el portapapeles!
The
operator-sdk generate
7.2.5.1. bundle Copiar enlaceEnlace copiado en el portapapeles!
The
generate bundle
bundle.Dockerfile
Typically, you run the
generate kustomize manifests
generate bundle
make bundle
| Flag | Description |
|---|---|
|
| Comma-separated list of channels to which the bundle belongs. The default value is
|
|
| Root directory for
|
|
| The default channel for the bundle. |
|
| Root directory for Operator manifests, such as deployments and RBAC. This directory is different from the directory passed to the
|
|
| Help for
|
|
| Directory from which to read an existing bundle. This directory is the parent of your bundle
|
|
| Directory containing Kustomize bases and a
|
|
| Generate bundle manifests. |
|
| Generate bundle metadata and Dockerfile. |
|
| Directory to write the bundle to. |
|
| Overwrite the bundle metadata and Dockerfile if they exist. The default value is
|
|
| Package name for the bundle. |
|
| Run in quiet mode. |
|
| Write bundle manifest to standard out. |
|
| Semantic version of the Operator in the generated bundle. Set only when creating a new bundle or upgrading the Operator. |
7.2.5.2. kustomize Copiar enlaceEnlace copiado en el portapapeles!
The
generate kustomize
7.2.5.2.1. manifests Copiar enlaceEnlace copiado en el portapapeles!
The
generate kustomize manifests
kustomization.yaml
config/manifests
--interactive=false
| Flag | Description |
|---|---|
|
| Root directory for API type definitions. |
|
| Help for
|
|
| Directory containing existing Kustomize files. |
|
| When set to
|
|
| Directory where to write Kustomize files. |
|
| Package name. |
|
| Run in quiet mode. |
7.2.6. init Copiar enlaceEnlace copiado en el portapapeles!
The
operator-sdk init
This command writes the following files:
- Boilerplate license file
-
file with the domain and repository
PROJECT -
to build the project
Makefile -
file with project dependencies
go.mod -
file for customizing manifests
kustomization.yaml - Patch file for customizing images for manager manifests
- Patch file for enabling Prometheus metrics
-
file to run
main.go
| Flag | Description |
|---|---|
|
| Help output for the
|
|
| Name and optionally version of the plugin to initialize the project with. Available plugins are
|
|
| Project version. Available values are
|
7.2.7. run Copiar enlaceEnlace copiado en el portapapeles!
The
operator-sdk run
7.2.7.1. bundle Copiar enlaceEnlace copiado en el portapapeles!
The
run bundle
| Flag | Description |
|---|---|
|
| Index image in which to inject a bundle. The default image is
|
|
| Install mode supported by the cluster service version (CSV) of the Operator, for example
|
|
| Install timeout. The default value is
|
|
| Path to the
|
|
| If present, namespace in which to run the CLI request. |
|
| Help output for the
|
7.2.7.2. bundle-upgrade Copiar enlaceEnlace copiado en el portapapeles!
The
run bundle-upgrade
| Flag | Description |
|---|---|
|
| Upgrade timeout. The default value is
|
|
| Path to the
|
|
| If present, namespace in which to run the CLI request. |
|
| Help output for the
|
7.2.8. scorecard Copiar enlaceEnlace copiado en el portapapeles!
The
operator-sdk scorecard
| Flag | Description |
|---|---|
|
| Path to scorecard configuration file. The default path is
|
|
| Help output for the
|
|
| Path to
|
|
| List which tests are available to run. |
|
| Namespace in which to run the test images. |
|
| Output format for results. Available values are
|
|
| Label selector to determine which tests are run. |
|
| Service account to use for tests. The default value is
|
|
| Disable resource cleanup after tests are run. |
|
| Seconds to wait for tests to complete, for example
|