[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//`, then the command does not overwrite and returns an error. |`controller` |Adds a new controller under `pkg/controller//`. The controller expects to use the CR type that should already be defined under `pkg/apis//` via the `operator-sdk add api --kind= --api-version=` command. If the controller package for that `Kind` already exists at `pkg/controller/`, then the command does not overwrite and returns an error. |`crd` a|Adds a CRD and the CR files. The `/deploy` path must already exist. The `--api-version` and `--kind` flags are required to generate the new Operator application. * Generated CRD filename: `/deploy/crds/___crd.yaml` * Generated CR filename: `/deploy/crds/___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 ----