operator-sdk alpha config-gen

config-gen programatically generates configuration for a controller-runtime based project using the project source code (golang) and a KubebuilderConfigGen resource file.

This is an alternative to expressing configuration as a static set of kustomize patches in the “config” directory.

config-gen may be used as a standalone command run against a file, as a kustomize transformer plugin, or as a configuration function (e.g. kpt).

Following is an example KubebuilderConfigGen resource used by config-gen:

kubebuilderconfiggen.yaml

this resource describes how to generate configuration for a controller-runtime

based project

apiVersion: kubebuilder.sigs.k8s.io/v1alpha1 kind: KubebuilderConfigGen metadata: name: my-project-name spec: controllerManager: image: my-org-name/my-project-name:v0.1.0

If this file was at the project source root, config-gen could be used to emit configuration using:

The KubebuilderConfigGen resource has the following fields:

apiVersion: kubebuilder.sigs.k8s.io/v1alpha1 kind: KubebuilderConfigGen

metadata: # name of the project. used in various resource names. # required name: project-name

  1. controllerManager:
  2. # image to run
  3. image: my-org/my-project:v0.1.0
  4. # if set, use component config for the controller-manager
  5. # optional
  6. componentConfig:
  7. # use component config
  8. enable: true
  9. # path to component config to put into a ConfigMap
  10. configFilepath: ./path/to/componentconfig.yaml
  11. # configure how metrics are exposed
  12. metrics:
  13. # disable the auth proxy required for scraping metrics
  14. # disable: false
  15. # generate prometheus ServiceMonitor resource
  16. enableServiceMonitor: true
  17. # configure how webhooks are generated
  18. # optional -- defaults to not generating webhook configuration
  19. webhooks:
  20. # enable will cause webhook config to be generated
  21. enable: true
  22. enableConversion:
  23. # key is the name of the CRD
  24. "bars.example.my.domain": true
  25. # configures where to get the certificate used for webhooks
  26. certificateSource:
  27. # type of certificate source
  28. # one of ["certManager", "dev", "manual"] -- defaults to "manual"
  29. # certManager: certmanager is used to manage certificates -- requires CertManager to be installed
  30. # dev: certificate is generated and wired into resources
  31. # manual: no certificate is generated or wired into resources
  32. type: "dev"
  33. # options for a dev certificate -- requires "dev" as the type
  34. devCertificate:
  35. duration: 1h
  1. #
  2. # As command
  3. #
  4. # create the kubebuilderconfiggen.yaml at project root
  5. cat > kubebuilderconfiggen.yaml <<EOF
  6. apiVersion: kubebuilder.sigs.k8s.io/v1alpha1
  7. kind: KubebuilderConfigGen
  8. metadata:
  9. name: project
  10. spec:
  11. controllerManager
  12. image: org/project:v0.1.0
  13. EOF
  14. # run the config generator
  15. kubebuilder alpha config-gen kubebuilderconfiggen.yaml
  16. # run the config generator and apply
  17. kubebuilder alpha config-gen kubebuilderconfiggen.yaml | kubectl apply -f -
  18. kubebuilder alpha config-gen kubebuilderconfiggen.yaml patch1.yaml patch2.yaml
  19. #
  20. # As Kustomize plugin
  21. # this allows using config-gen with kustomize features such as patches, commonLabels,
  22. # commonAnnotations, resources, configMapGenerator and other transformer plugins.
  23. #
  24. # install the latest kustomize
  25. GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v4
  26. # install the command as a kustomize plugin
  27. kubebuilder alpha config-gen install-as-plugin
  28. # create the kustomization.yaml containing the KubebuilderConfigGen resource
  29. cat > kustomization.yaml <<EOF
  30. apiVersion: kustomize.config.k8s.io/v1beta1
  31. kind: Kustomization
  32. transformers:
  33. - |-
  34. apiVersion: kubebuilder.sigs.k8s.io
  35. kind: KubebuilderConfigGen
  36. metadata:
  37. name: my-project
  38. spec:
  39. controllerManager:
  40. image: my-org/my-project:v0.1.0
  41. EOF
  42. # generate configuration from kustomize > v4.0.0
  43. kustomize build --enable-alpha-plugins .
  44. # generate configuration from kustomize <= v4.0.0
  45. kustomize build --enable_alpha_plugins .
  1. --plugins strings plugin keys to be used for this subcommand execution