operator-sdk add api

operator-sdk add api

Adds a new api definition under pkg/apis

Synopsis

operator-sdk add api –kind= –api-version creates an API definition for a new custom resource. This command must be run from the project root directory.

For Go-based operators:

  • Creates the api definition for a new custom resource under pkg/apis.
  • By default, this command runs Kubernetes deepcopy and CRD generators on tagged types in all paths under pkg/apis. Go code is generated under pkg/apis///zz_generated.deepcopy.go. Generation can be disabled with the –skip-generation flag for Go-based operators.

For Ansible-based operators:

  • Creates resource folder under /roles.
  • watches.yaml is updated with new resource.
  • deploy/role.yaml will be updated with apiGroup for new API.

For Helm-based operators:

  • Creates resource folder under /helm-charts.
  • watches.yaml is updated with new resource.
  • deploy/role.yaml will be updated to reflact new rules for the incoming API.

CRD’s are generated, or updated if they exist for a particular group + version + kind, under deploy/crds/__crd.yaml; OpenAPI V3 validation YAML is generated as a ‘validation’ object.

  1. operator-sdk add api [flags]

Examples

  1. # Create a new API, under an existing project. This command must be run from the project root directory.
  2. # Go Example:
  3. $ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
  4. # Ansible Example
  5. $ operator-sdk add api \
  6. --api-version=app.example.com/v1alpha1 \
  7. --kind=AppService
  8. # Helm Example:
  9. $ operator-sdk add api \
  10. --api-version=app.example.com/v1alpha1 \
  11. --kind=AppService
  12. $ operator-sdk add api \
  13. --api-version=app.example.com/v1alpha1 \
  14. --kind=AppService
  15. --helm-chart=myrepo/app
  16. $ operator-sdk add api \
  17. --helm-chart=myrepo/app
  18. $ operator-sdk add api \
  19. --helm-chart=myrepo/app \
  20. --helm-chart-version=1.2.3
  21. $ operator-sdk add api \
  22. --helm-chart=app \
  23. --helm-chart-repo=https://charts.mycompany.com/
  24. $ operator-sdk add api \
  25. --helm-chart=app \
  26. --helm-chart-repo=https://charts.mycompany.com/ \
  27. --helm-chart-version=1.2.3
  28. $ operator-sdk add api \
  29. --helm-chart=/path/to/local/chart-directories/app/
  30. $ operator-sdk add api \
  31. --helm-chart=/path/to/local/chart-archives/app-1.2.3.tgz

Options

  1. --api-version string Kubernetes apiVersion and has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)
  2. --crd-version string CRD version to generate (default "v1")
  3. --helm-chart string Initialize helm operator with existing helm chart (<URL>, <repo>/<name>, or local path). Valid only for --type helm
  4. --helm-chart-repo string Chart repository URL for the requested helm chart, Valid only for --type helm
  5. --helm-chart-version string Specific version of the helm chart (default is latest version). Valid only for --type helm
  6. -h, --help help for api
  7. --kind string Kubernetes resource Kind name. (e.g AppService)
  8. --skip-generation Skip generation of deepcopy and OpenAPI code and OpenAPI CRD specs

SEE ALSO

Last modified April 24, 2020: internal/generate/crd: change default CRD to v1 (#2874) (b17779d7)