API Markers

This document describes code markers supported by the SDK.

ClusterServiceVersion markers

This section details ClusterServiceVersion (CSV) code markers and lists available markers.

Note: CSV markers can only be used in Go Operator projects. Annotations for Ansible and Helm Operator projects will be added in the future.

Usage

All markers have a +operator-sdk:gen-csv prefix, denoting that they’re parsed while executing operator-sdk generate kustomize manifests.

Paths

Paths are dot-separated string hierarchies with the above prefix that map to CSV spec field names.

Example: +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Pod Count"

customresourcedefinitions

  • customresourcedefinitions: child path token
    • displayName: quoted string or string literal
    • resources: quoted string or string literal, in the format "kind,version,\"name\"" or `kind,version,"name"` , where kind, version, and name are fields in each CSV resources entry
    • specDescriptors, statusDescriptors: bool, or child path token
      • displayName: quoted string or string literal
      • x-descriptors: quoted string or string literal comma-separated list of x-descriptor UI hints.

NOTES

  • specDescriptors and statusDescriptors with a value of true is required for each field to be included in their respective customresourcedefinitions CSV fields. See the examples below.
  • customresourcedefinitions top-level kind, name, and version fields are parsed from API code.
  • All description fields are parsed from type declaration and struct type field comments.
  • path is parsed out of a field’s JSON tag and merged with parent field path’s in dot-hierarchy notation.

Examples

These examples assume Memcached, MemcachedSpec, and MemcachedStatus are the example projects’ kind, spec, and status.

  1. Set a display name for a customresourcedefinitions kind entry:
  1. // +operator-sdk:gen-csv:customresourcedefinitions.displayName="Memcached App"
  2. type Memcached struct {
  3. metav1.TypeMeta `json:",inline"`
  4. metav1.ObjectMeta `json:"metadata,omitempty"`
  5. Spec MemcachedSpec `json:"spec,omitempty"`
  6. Status MemcachedStatus `json:"status,omitempty"`
  7. }
  1. Set displayName, path, x-descriptors, and description on a field for a customresourcedefinitions.specDescriptors entry:
  1. type MemcachedSpec struct {
  2. // Size is the size of the memcached deployment. <-- This will become Size's specDescriptors.description.
  3. // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
  4. // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Pod Count"
  5. // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:podCount,urn:alm:descriptor:io.kubernetes:custom"
  6. Size int32 `json:"size"` // <-- Size's specDescriptors.path is inferred from this JSON tag.
  7. }
  1. Let the SDK infer all unmarked paths on a field for a customresourcedefinitions.specDescriptors entry:
  1. type MemcachedSpec struct {
  2. // Size is the size of the memcached deployment.
  3. // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
  4. Size int32 `json:"size"`
  5. }

The SDK uses the Size fields’ json tag name as path, Size as displayName, and field comments as description.

The SDK also checks path elements against a list of well-known path to x-descriptor string mappings and either uses a match as x-descriptors, or does not set x-descriptors. Supported mappings:

Spec x-descriptors

Pathx-descriptor
sizeurn:alm:descriptor:com.tectonic.ui:podCount
podCounturn:alm:descriptor:com.tectonic.ui:podCount
endpointsurn:alm:descriptor:com.tectonic.ui:endpointList
endpointListurn:alm:descriptor:com.tectonic.ui:endpointList
labelurn:alm:descriptor:com.tectonic.ui:label
resourcesurn:alm:descriptor:com.tectonic.ui:resourceRequirements
resourceRequirementsurn:alm:descriptor:com.tectonic.ui:resourceRequirements
selectorurn:alm:descriptor:com.tectonic.ui:selector:
namespaceSelectorurn:alm:descriptor:com.tectonic.ui:namespaceSelector
noneurn:alm:descriptor:io.kubernetes:
booleanSwitchurn:alm:descriptor:com.tectonic.ui:booleanSwitch
passwordurn:alm:descriptor:com.tectonic.ui:password
checkboxurn:alm:descriptor:com.tectonic.ui:checkbox
imagePullPolicyurn:alm:descriptor:com.tectonic.ui:imagePullPolicy
updateStrategyurn:alm:descriptor:com.tectonic.ui:updateStrategy
texturn:alm:descriptor:com.tectonic.ui:text
numberurn:alm:descriptor:com.tectonic.ui:number
nodeAffinityurn:alm:descriptor:com.tectonic.ui:nodeAffinity
podAffinityurn:alm:descriptor:com.tectonic.ui:podAffinity
podAntiAffinityurn:alm:descriptor:com.tectonic.ui:podAntiAffinity
noneurn:alm:descriptor:com.tectonic.ui:fieldGroup:
noneurn:alm:descriptor:com.tectonic.ui:arrayFieldGroup:
noneurn:alm:descriptor:com.tectonic.ui:select:
advancedurn:alm:descriptor:com.tectonic.ui:advanced

Status x-descriptors

Pathx-descriptor
podStatusesurn:alm:descriptor:com.tectonic.ui:podStatuses
sizeurn:alm:descriptor:com.tectonic.ui:podCount
podCounturn:alm:descriptor:com.tectonic.ui:podCount
linkurn:alm:descriptor:org.w3:link
w3linkurn:alm:descriptor:org.w3:link
conditionsurn:alm:descriptor:io.kubernetes.conditions
texturn:alm:descriptor:text
prometheusEndpointurn:alm:descriptor:prometheusEndpoint
phaseurn:alm:descriptor:io.kubernetes.phase
k8sPhaseurn:alm:descriptor:io.kubernetes.phase
reasonurn:alm:descriptor:io.kubernetes.phase:reason
k8sReasonurn:alm:descriptor:io.kubernetes.phase:reason
noneurn:alm:descriptor:io.kubernetes:

NOTE: any x-descriptor that ends in : will not be inferred by path element, ex. urn:alm:descriptor:io.kubernetes:. Use the x-descriptors marker if you want to enable one for your type.

  1. A comprehensive example:
  • Infer path, description, displayName, and x-descriptors for specDescriptors and statusDescriptors entries.
  • Create three resources entries each with kind, version, and name values.
  1. // Represents a cluster of Memcached apps
  2. // +operator-sdk:gen-csv:customresourcedefinitions.displayName="Memcached App"
  3. // +operator-sdk:gen-csv:customresourcedefinitions.resources="Deployment,v1,\"memcached-operator\""
  4. // +operator-sdk:gen-csv:customresourcedefinitions.resources=`Service,v1,"memcached-operator"`
  5. type Memcached struct {
  6. metav1.TypeMeta `json:",inline"`
  7. metav1.ObjectMeta `json:"metadata,omitempty"`
  8. Spec MemcachedSpec `json:"spec,omitempty"`
  9. Status MemcachedStatus `json:"status,omitempty"`
  10. }
  11. type MemcachedSpec struct {
  12. Pods MemcachedPods `json:"pods"`
  13. }
  14. type MemcachedStatus struct {
  15. Pods MemcachedPods `json:"podStatuses"`
  16. }
  17. type MemcachedPods struct {
  18. // Size is the size of the memcached deployment.
  19. // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
  20. // +operator-sdk:gen-csv:customresourcedefinitions.statusDescriptors=true
  21. Size int32 `json:"size"`
  22. }

The generated customresourcedefinitions will look like:

  1. customresourcedefinitions:
  2. owned:
  3. - description: Represents a cluster of Memcached apps
  4. displayName: Memcached App
  5. kind: Memcached
  6. name: memcacheds.cache.example.com
  7. version: v1alpha1
  8. resources:
  9. - kind: Deployment
  10. name: A Kubernetes Deployment
  11. version: v1
  12. - kind: ReplicaSet
  13. name: A Kubernetes ReplicaSet
  14. version: v1beta2
  15. - kind: Pod
  16. name: A Kubernetes Pod
  17. version: v1
  18. specDescriptors:
  19. - description: The desired number of member Pods for the deployment.
  20. displayName: Size
  21. path: pods.size
  22. x-descriptors:
  23. - 'urn:alm:descriptor:com.tectonic.ui:podCount'
  24. statusDescriptors:
  25. - description: The desired number of member Pods for the deployment.
  26. displayName: Size
  27. path: podStatuses.size
  28. x-descriptors:
  29. - 'urn:alm:descriptor:com.tectonic.ui:podStatuses'
  30. - 'urn:alm:descriptor:com.tectonic.ui:podCount'

Last modified July 8, 2020: docs: OLM integration docs reference new commands (new and legacy CLI) (#3320) (ec03835e)