1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-06 15:46:57 +01:00
Files
openshift-docs/modules/osdk-cli-reference-add.adoc
sheriff-rh 981be5a658 apiextensions.k8s.io/v1 and --crd-version flag added
additional changes

fixed typo

corrections

feedback
2020-10-15 12:29:45 +00:00

144 lines
3.6 KiB
Plaintext

[id="osdk-cli-reference-add_{context}"]
= add
The `operator-sdk add` command adds a controller or resource to the project. The
command must be run from the Operator project root directory.
.`add` subcommands
[options="header",cols="1,3"]
|===
|Subcommand |Description
|`api`
|Adds a new API definition for a new Custom Resource (CR) under `pkg/apis` and
generates the Customer Resource Definition (CRD) and Custom Resource (CR) files
under `deploy/crds/`. If the API already exists at `pkg/apis/<group>/<version>`,
then the command does not overwrite and returns an error.
|`controller`
|Adds a new controller under `pkg/controller/<kind>/`. The controller expects to
use the CR type that should already be defined under
`pkg/apis/<group>/<version>` via the `operator-sdk add api --kind=<kind>
--api-version=<group/version>` command. If the controller package for that
`Kind` already exists at `pkg/controller/<kind>`, then the command does not
overwrite and returns an error.
|`crd`
a|Adds a CRD and the CR files. The `<project-name>/deploy` path must already
exist. The `--api-version` and `--kind` flags are required to generate the new
Operator application.
* Generated CRD filename: `<project-name>/deploy/crds/<group>_<version>_<kind>_crd.yaml`
* Generated CR filename: `<project-name>/deploy/crds/<group>_<version>_<kind>_cr.yaml`
|===
.`add api` flags
[options="header",cols="1,3"]
|===
|Flag |Description
|`--api-version` (string)
|CRD `APIVersion` in the format `$GROUP_NAME/$VERSION` (e.g.,
`app.example.com/v1alpha1`).
|`--crd-version`
|CRD version to generate, like `v1`. Default setting is `v1beta1`.
|`--kind` (string)
|CRD `Kind`. For example, `AppService`.
|===
.`add crd` flags
[options="header",cols="1,3"]
|===
|Flag |Description
|`--api-version` (string)
|CRD `APIVersion` in the format `$GROUP_NAME/$VERSION`. For example, `app.example.com/v1alpha1`.
|`--crd-version`
|CRD version to generate, like `v1`. Default setting is `v1beta1`.
|`--kind` (string)
|CRD `Kind`. For example, `AppService`.
|===
For example:
[source,terminal]
----
$ operator-sdk add api --api-version app.example.com/v1alpha1 --kind AppService
----
.Example output
[source,terminal]
----
Create pkg/apis/app/v1alpha1/appservice_types.go
Create pkg/apis/addtoscheme_app_v1alpha1.go
Create pkg/apis/app/v1alpha1/register.go
Create pkg/apis/app/v1alpha1/doc.go
Create deploy/crds/app_v1alpha1_appservice_cr.yaml
Create deploy/crds/app_v1alpha1_appservice_crd.yaml
Running code-generation for Custom Resource (CR) group versions: [app:v1alpha1]
Generating deepcopy funcs
----
[source,terminal]
----
$ tree pkg/apis
----
.Example output
[source,terminal]
----
pkg/apis/
├── addtoscheme_app_appservice.go
├── apis.go
└── app
└── v1alpha1
├── doc.go
├── register.go
└── types.go
----
[source,terminal]
----
$ operator-sdk add controller --api-version app.example.com/v1alpha1 --kind AppService
----
.Example output
[source,terminal]
----
Create pkg/controller/appservice/appservice_controller.go
Create pkg/controller/add_appservice.go
----
[source,terminal]
----
$ tree pkg/controller
----
.Example output
[source,terminal]
----
pkg/controller/
├── add_appservice.go
├── appservice
│   └── appservice_controller.go
└── controller.go
----
[source,terminal]
----
$ operator-sdk add crd --api-version app.example.com/v1alpha1 --kind AppService
----
.Example output
[source,terminal]
----
Generating Custom Resource Definition (CRD) files
Create deploy/crds/app_v1alpha1_appservice_crd.yaml
Create deploy/crds/app_v1alpha1_appservice_cr.yaml
----