Skip to content

Commit 7c30312

Browse files
authored
doc/sdk-cli-reference: update for [api,controller], cleanup for [new,generate] (#674)
- Added the CLI reference description and examples for `add api` and `add controller` - Cleaned up the section for `new` by making the flags `--api-version` and `--kind` only specific to `--type=ansible`. Also added the example cmd for ansible. - Made the description for `generate k8s` more specific. The example output was outdated as well. - The doc for `generate crd` was wrong. It's actually `add crd` so I moved it down to the correct section. The example was outdated too since the filenames changed after the refactor. - Removed the section for `generate olm-catalog` since we no longer have that in our CLI.
1 parent 0537f59 commit 7c30312

File tree

1 file changed

+86
-60
lines changed

1 file changed

+86
-60
lines changed

doc/sdk-cli-reference.md

Lines changed: 86 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -90,100 +90,125 @@ operator-sdk completion bash
9090

9191
## generate
9292

93-
### Available Commands
94-
95-
#### k8s - Generates Kubernetes code for custom resource
93+
### k8s
9694

97-
##### Use
95+
Runs the Kubernetes [code-generators][k8s-code-generator] for all Custom Resource Definitions (CRD) apis under `pkg/apis/...`.
96+
Currently only runs `deepcopy-gen` to generate the required `DeepCopy()` functions for all custom resource types.
9897

99-
k8s generator generates code for custom resource given the API spec
100-
to comply with kube-API requirements.
98+
**Note**: This command must be run every time the api (spec and status) for a custom resource type is updated.
10199

102-
##### Flags
103-
104-
* `-h, --help` - help for k8s
105-
106-
##### Example
100+
#### Example
107101

108102
```bash
109-
operator-sdk generate k8s
110-
111-
# Output:
112-
Run code-generation for custom resources
103+
$ tree pkg/apis/app/v1alpha1/
104+
pkg/apis/app/v1alpha1/
105+
├── appservice_types.go
106+
├── doc.go
107+
├── register.go
108+
109+
$ operator-sdk generate k8s
110+
Running code-generation for custom resource group versions: [app:v1alpha1]
113111
Generating deepcopy funcs
112+
113+
$ tree pkg/apis/app/v1alpha1/
114+
pkg/apis/app/v1alpha1/
115+
├── appservice_types.go
116+
├── doc.go
117+
├── register.go
118+
└── zz_generated.deepcopy.go
114119
```
115120

116-
#### crd - Generates a custom resource definition (CRD) and the custom resource (CR) files
121+
## new
117122

118-
##### Use
123+
Scaffolds a new operator project.
119124

120-
crd generator generates custom resource definition and custom resource
121-
files for the specified api-version and kind.
125+
### Args
122126

123-
##### Flags
127+
* `project-name` - name of the new project
124128

125-
* `--api-version` **(required)** string - Kubernetes apiVersion and has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)
126-
* `-h, --help` - help for k8s
127-
* `--kind` **(required)** string - Kubernetes CustomResourceDefinition kind. (e.g AppService)
129+
### Flags
128130

129-
##### Example
130131

132+
* `--skip-git-init` Do not init the directory as a git repository
133+
* `--type` Type of operator to initialize: "ansible" or "go" (default "go"). Also requires the following flags if `--type=ansible`
134+
* `--api-version` CRD APIVersion in the format `$GROUP_NAME/$VERSION` (e.g app.example.com/v1alpha1)
135+
* `--kind` CRD Kind. (e.g AppService)
136+
* `-h, --help` - help for new
137+
138+
### Example
139+
140+
Go project:
131141
```bash
132-
operator-sdk generate crd --api-version app.example.com/v1alpha1 --kind AppService
142+
mkdir $GOPATH/src/github.com/example.com/
143+
cd $GOPATH/src/github.com/example.com/
144+
operator-sdk new app-operator
145+
```
133146

134-
# Output:
135-
Generating custom resource definition (CRD) file
136-
Create <path_to_project>/deploy/appservice_cr.yaml
137-
Create <path_to_project>/deploy/appservice_crd.yaml
147+
Ansible project:
148+
```bash
149+
operator-sdk new app-operator --type=ansible --api-version=app.example.com/v1alpha1 --kind=AppService
138150
```
139-
#### olm-catalog - Generates OLM Catalog manifests
140151

141-
##### Flags
152+
## add
142153

143-
* `--image` **(required)** string - The container image name to set in the CSV to deploy the operator e.g: quay.io/example/operator:v0.0.1
144-
* `--version` **(required)** string - The version of the current CSV e.g: 0.0.1
145-
* `-h, --help` - help for olm-catalog
154+
### api
146155

147-
##### Example
156+
Adds the
157+
api definition for a new custom resource under `pkg/apis` and generates the CRD and CR files under `depoy/crds/...`.
148158

149-
```bash
150-
operator-sdk generate olm-catalog --image=quay.io/example/operator:v0.0.1 --version=0.0.1
159+
#### Flags
151160

152-
# Output:
153-
Generating OLM catalog manifests
161+
* `--api-version` CRD APIVersion in the format `$GROUP_NAME/$VERSION` (e.g app.example.com/v1alpha1)
162+
* `--kind` CRD Kind. (e.g AppService)
163+
164+
#### Example
165+
166+
```bash
167+
$ operator-sdk add api --api-version app.example.com/v1alpha1 --kind AppService
168+
Create pkg/apis/app/v1alpha1/appservice_types.go
169+
Create pkg/apis/addtoscheme_app_v1alpha1.go
170+
Create pkg/apis/app/v1alpha1/register.go
171+
Create pkg/apis/app/v1alpha1/doc.go
172+
Create deploy/crds/app_v1alpha1_appservice_cr.yaml
173+
Create deploy/crds/app_v1alpha1_appservice_crd.yaml
174+
Running code-generation for custom resource group versions: [app:v1alpha1]
175+
Generating deepcopy funcs
154176
```
155177

156-
### Flags
178+
### controller
157179

158-
* `-h, --help` - help for generate
180+
Adds a new
181+
controller under `pkg/controller/<kind>/...` that, by default, reconciles a custom resource for the specified apiversion and kind.
159182

160-
## new
183+
#### Flags
161184

162-
The operator-sdk new command creates a new operator application and
163-
generates a default directory layout based on the input `project-name`.
185+
* `--api-version` CRD APIVersion in the format `$GROUP_NAME/$VERSION` (e.g app.example.com/v1alpha1)
186+
* `--kind` CRD Kind. (e.g AppService)
164187

165-
### Args
188+
#### Example
166189

167-
* `project-name` - the project name of the new
190+
```bash
191+
$ operator-sdk add controller --api-version app.example.com/v1alpha1 --kind AppService
192+
Create pkg/controller/appservice/appservice_controller.go
193+
Create pkg/controller/add_appservice.go
194+
```
168195

169-
### Flags
196+
### crd
170197

171-
* `--api-version` **(required)** string - Kubernetes apiVersion and has a format of `$GROUP_NAME/$VERSION` (e.g app.example.com/v1alpha1)
172-
* `--kind` **(required)** string - Kubernetes CustomResourceDefintion kind. (e.g AppService)
173-
* `--skip-git-init` Do not init the directory as a git repository
174-
* `--type` Type of operator to initialize (e.g "ansible") (default "go")
175-
* `-h, --help` - help for new
198+
Generates the CRD and the CR files for the specified api-version and kind.
176199

177-
### Example
200+
#### Flags
178201

179-
```bash
180-
mkdir $GOPATH/src/github.com/example.com/
181-
cd $GOPATH/src/github.com/example.com/
182-
operator-sdk new app-operator --api-version=app.example.com/v1alpha1 --kind=AppService
202+
* `--api-version` CRD APIVersion in the format `$GROUP_NAME/$VERSION` (e.g app.example.com/v1alpha1)
203+
* `--kind` CRD Kind. (e.g AppService)
183204

184-
# Output:
185-
Create app-operator/.gitignore
186-
...
205+
#### Example
206+
207+
```bash
208+
$ operator-sdk add crd --api-version app.example.com/v1alpha1 --kind AppService
209+
Generating custom resource definition (CRD) files
210+
Create deploy/crds/app_v1alpha1_appservice_crd.yaml
211+
Create deploy/crds/app_v1alpha1_appservice_cr.yaml
187212
```
188213

189214
## test
@@ -293,3 +318,4 @@ operator-sdk up local --namespace "testing"
293318
* `-h, --help` - help for up
294319

295320
[utility_link]: https://github.com/operator-framework/operator-sdk/blob/89bf021063d18b6769bdc551ed08fc37027939d5/pkg/util/k8sutil/k8sutil.go#L140
321+
[k8s-code-generator]: https://github.com/kubernetes/code-generator

0 commit comments

Comments
 (0)