Skip to content

Instantly share code, notes, and snippets.

@faun
Forked from jenting/controller-gen.txt
Created March 31, 2022 22:53
Show Gist options
  • Save faun/9b7cc18a2696555f0801aadf4e6ab1b7 to your computer and use it in GitHub Desktop.
Save faun/9b7cc18a2696555f0801aadf4e6ab1b7 to your computer and use it in GitHub Desktop.
controller gen help
CRD
+groupName package
=<string> specifies the API group name for this package.
+kubebuilder:deprecatedversion type
marks this version as deprecated.
[warning=<string>]
message to be shown on the deprecated version
+kubebuilder:printcolumn type
adds a column to "kubectl get" output for this CRD.
JSONPath=<string>
specifies the jsonpath expression used to extract the value of the column.
[description=<string>]
specifies the help/description for this column.
[format=<string>]
specifies the format of the column.
It may be any OpenAPI data format corresponding to the type, listed at https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types.
name=<string>
specifies the name of the column.
[priority=<int>]
indicates how important it is that this column be displayed.
Lower priority (*higher* numbered) columns will be hidden if the terminal width is too small.
type=<string>
indicates the type of the column.
It may be any OpenAPI data type listed at https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types.
+kubebuilder:resource type
configures naming and scope for a CRD.
[categories=<[]string>]
specifies which group aliases this resource is part of.
Group aliases are used to work with groups of resources at once. The most common one is "all" which covers about a third of the base resources in Kubernetes, and is generally used for "user-facing" resources.
[path=<string>]
specifies the plural "resource" for this CRD.
It generally corresponds to a plural, lower-cased version of the Kind. See https://book.kubebuilder.io/cronjob-tutorial/gvks.html.
[scope=<string>]
overrides the scope of the CRD (Cluster vs Namespaced).
Scope defaults to "Namespaced". Cluster-scoped ("Cluster") resources don't exist in namespaces.
[shortName=<[]string>]
specifies aliases for this CRD.
Short names are often used when people have work with your resource over and over again. For instance, "rs" for "replicaset" or "crd" for customresourcedefinition.
[singular=<string>]
overrides the singular form of your resource.
The singular form is otherwise defaulted off the plural (path).
+kubebuilder:skip package
don't consider this package as an API version.
+kubebuilder:skipversion type
removes the particular version of the CRD from the CRDs spec.
This is useful if you need to skip generating and listing version entries for 'internal' resource versions, which typically exist if using the Kubernetes upstream conversion-gen tool.
+kubebuilder:storageversion type
marks this version as the "storage version" for the CRD for conversion.
When conversion is enabled for a CRD (i.e. it's not a trivial-versions/single-version CRD), one version is set as the "storage version" to be stored in etcd. Attempting to store any other version will result in conversion to the storage version via a conversion webhook.
+kubebuilder:subresource:scale type
enables the "/scale" subresource on a CRD.
[selectorpath=<string>]
specifies the jsonpath to the pod label selector field for the scale's status.
The selector field must be the *string* form (serialized form) of a selector. Setting a pod label selector is necessary for your type to work with the HorizontalPodAutoscaler.
specpath=<string>
specifies the jsonpath to the replicas field for the scale's spec.
statuspath=<string>
specifies the jsonpath to the replicas field for the scale's status.
+kubebuilder:subresource:status type
enables the "/status" subresource on a CRD.
+kubebuilder:unservedversion type
does not serve this version.
This is useful if you need to drop support for a version in favor of a newer version.
+versionName package
=<string> overrides the API group version for this package (defaults to the package name).
CRD processing
+kubebuilder:pruning:PreserveUnknownFields type
PreserveUnknownFields stops the apiserver from pruning fields which are not specified.
By default the apiserver drops unknown fields from the request payload during the decoding step. This marker stops the API server from doing so. It affects fields recursively, but switches back to normal pruning behaviour if nested properties or additionalProperties are specified in the schema. This can either be true or undefined. False is forbidden.
NB: The kubebuilder:validation:XPreserveUnknownFields variant is deprecated in favor of the kubebuilder:pruning:PreserveUnknownFields variant. They function identically.
+kubebuilder:pruning:PreserveUnknownFields field
PreserveUnknownFields stops the apiserver from pruning fields which are not specified.
By default the apiserver drops unknown fields from the request payload during the decoding step. This marker stops the API server from doing so. It affects fields recursively, but switches back to normal pruning behaviour if nested properties or additionalProperties are specified in the schema. This can either be true or undefined. False is forbidden.
NB: The kubebuilder:validation:XPreserveUnknownFields variant is deprecated in favor of the kubebuilder:pruning:PreserveUnknownFields variant. They function identically.
+kubebuilder:validation:XPreserveUnknownFields type
PreserveUnknownFields stops the apiserver from pruning fields which are not specified.
By default the apiserver drops unknown fields from the request payload during the decoding step. This marker stops the API server from doing so. It affects fields recursively, but switches back to normal pruning behaviour if nested properties or additionalProperties are specified in the schema. This can either be true or undefined. False is forbidden.
NB: The kubebuilder:validation:XPreserveUnknownFields variant is deprecated in favor of the kubebuilder:pruning:PreserveUnknownFields variant. They function identically.
+kubebuilder:validation:XPreserveUnknownFields field
PreserveUnknownFields stops the apiserver from pruning fields which are not specified.
By default the apiserver drops unknown fields from the request payload during the decoding step. This marker stops the API server from doing so. It affects fields recursively, but switches back to normal pruning behaviour if nested properties or additionalProperties are specified in the schema. This can either be true or undefined. False is forbidden.
NB: The kubebuilder:validation:XPreserveUnknownFields variant is deprecated in favor of the kubebuilder:pruning:PreserveUnknownFields variant. They function identically.
+listMapKey field
=<string> specifies the keys to map listTypes.
It indicates the index of a map list. They can be repeated if multiple keys must be used. It can only be used when ListType is set to map, and the keys should be scalar types.
+listType field
=<string> specifies the type of data-structure that the list represents (map, set, atomic).
Possible data-structure types of a list are:
- "map": it needs to have a key field, which will be used to build an associative list. A typical example is a the pod container list, which is indexed by the container name.
- "set": Fields need to be "scalar", and there can be only one occurrence of each.
- "atomic": All the fields in the list are treated as a single value, are typically manipulated together by the same actor.
+mapType field
=<string> specifies the level of atomicity of the map; i.e. whether each item in the map is independent of the others, or all fields are treated as a single unit.
Possible values:
- "granular": items in the map are independent of each other, and can be manipulated by different actors. This is the default behavior.
- "atomic": all fields are treated as one unit. Any changes have to replace the entire map.
+structType field
=<string> specifies the level of atomicity of the struct; i.e. whether each field in the struct is independent of the others, or all fields are treated as a single unit.
Possible values:
- "granular": fields in the struct are independent of each other, and can be manipulated by different actors. This is the default behavior.
- "atomic": all fields are treated as one unit. Any changes have to replace the entire struct.
CRD validation
+kubebuilder:default field
=<any> sets the default value for this field.
A default value will be accepted as any value valid for the field. Formatting for common types include: boolean: `true`, string: `Cluster`, numerical: `1.24`, array: `{1,2}`, object: `{policy: "delete"}`). Defaults should be defined in pruned form, and only best-effort validation will be performed. Full validation of a default requires submission of the containing CRD to an apiserver.
+kubebuilder:validation:EmbeddedResource field
EmbeddedResource marks a fields as an embedded resource with apiVersion, kind and metadata fields.
An embedded resource is a value that has apiVersion, kind and metadata fields. They are validated implicitly according to the semantics of the currently running apiserver. It is not necessary to add any additional schema for these field, yet it is possible. This can be combined with PreserveUnknownFields.
+kubebuilder:validation:Enum field
=<[]any> specifies that this (scalar) field is restricted to the *exact* values specified here.
+kubebuilder:validation:Enum type
=<[]any> specifies that this (scalar) field is restricted to the *exact* values specified here.
+kubebuilder:validation:ExclusiveMaximum field
=<bool> indicates that the maximum is "up to" but not including that value.
+kubebuilder:validation:ExclusiveMaximum type
=<bool> indicates that the maximum is "up to" but not including that value.
+kubebuilder:validation:ExclusiveMinimum field
=<bool> indicates that the minimum is "up to" but not including that value.
+kubebuilder:validation:ExclusiveMinimum type
=<bool> indicates that the minimum is "up to" but not including that value.
+kubebuilder:validation:Format type
=<string> specifies additional "complex" formatting for this field.
For example, a date-time field would be marked as "type: string" and "format: date-time".
+kubebuilder:validation:Format field
=<string> specifies additional "complex" formatting for this field.
For example, a date-time field would be marked as "type: string" and "format: date-time".
+kubebuilder:validation:MaxItems type
=<int> specifies the maximum length for this list.
+kubebuilder:validation:MaxItems field
=<int> specifies the maximum length for this list.
+kubebuilder:validation:MaxLength field
=<int> specifies the maximum length for this string.
+kubebuilder:validation:MaxLength type
=<int> specifies the maximum length for this string.
+kubebuilder:validation:MaxProperties field
=<int> restricts the number of keys in an object
+kubebuilder:validation:MaxProperties type
=<int> restricts the number of keys in an object
+kubebuilder:validation:Maximum type
=<int> specifies the maximum numeric value that this field can have.
+kubebuilder:validation:Maximum field
=<int> specifies the maximum numeric value that this field can have.
+kubebuilder:validation:MinItems field
=<int> specifies the minimun length for this list.
+kubebuilder:validation:MinItems type
=<int> specifies the minimun length for this list.
+kubebuilder:validation:MinLength field
=<int> specifies the minimum length for this string.
+kubebuilder:validation:MinLength type
=<int> specifies the minimum length for this string.
+kubebuilder:validation:MinProperties type
=<int> restricts the number of keys in an object
+kubebuilder:validation:MinProperties field
=<int> restricts the number of keys in an object
+kubebuilder:validation:Minimum type
=<int> specifies the minimum numeric value that this field can have. Negative integers are supported.
+kubebuilder:validation:Minimum field
=<int> specifies the minimum numeric value that this field can have. Negative integers are supported.
+kubebuilder:validation:MultipleOf field
=<int> specifies that this field must have a numeric value that's a multiple of this one.
+kubebuilder:validation:MultipleOf type
=<int> specifies that this field must have a numeric value that's a multiple of this one.
+kubebuilder:validation:Optional field
specifies that this field is optional, if fields are required by default.
+kubebuilder:validation:Optional package
specifies that all fields in this package are optional by default.
+kubebuilder:validation:Pattern type
=<string> specifies that this string must match the given regular expression.
+kubebuilder:validation:Pattern field
=<string> specifies that this string must match the given regular expression.
+kubebuilder:validation:Required field
specifies that this field is required, if fields are optional by default.
+kubebuilder:validation:Required package
specifies that all fields in this package are required by default.
+kubebuilder:validation:Schemaless field
marks a field as being a schemaless object.
Schemaless objects are not introspected, so you must provide any type and validation information yourself. One use for this tag is for embedding fields that hold JSONSchema typed objects. Because this field disables all type checking, it is recommended to be used only as a last resort.
+kubebuilder:validation:Type type
=<string> overrides the type for this field (which defaults to the equivalent of the Go type).
This generally must be paired with custom serialization. For example, the metav1.Time field would be marked as "type: string" and "format: date-time".
+kubebuilder:validation:Type field
=<string> overrides the type for this field (which defaults to the equivalent of the Go type).
This generally must be paired with custom serialization. For example, the metav1.Time field would be marked as "type: string" and "format: date-time".
+kubebuilder:validation:UniqueItems field
=<bool> specifies that all items in this list must be unique.
+kubebuilder:validation:UniqueItems type
=<bool> specifies that all items in this list must be unique.
+kubebuilder:validation:XEmbeddedResource type
EmbeddedResource marks a fields as an embedded resource with apiVersion, kind and metadata fields.
An embedded resource is a value that has apiVersion, kind and metadata fields. They are validated implicitly according to the semantics of the currently running apiserver. It is not necessary to add any additional schema for these field, yet it is possible. This can be combined with PreserveUnknownFields.
+kubebuilder:validation:XEmbeddedResource field
EmbeddedResource marks a fields as an embedded resource with apiVersion, kind and metadata fields.
An embedded resource is a value that has apiVersion, kind and metadata fields. They are validated implicitly according to the semantics of the currently running apiserver. It is not necessary to add any additional schema for these field, yet it is possible. This can be combined with PreserveUnknownFields.
+kubebuilder:validation:XIntOrString type
IntOrString marks a fields as an IntOrString.
This is required when applying patterns or other validations to an IntOrString field. Knwon information about the type is applied during the collapse phase and as such is not normally available during marker application.
+kubebuilder:validation:XIntOrString field
IntOrString marks a fields as an IntOrString.
This is required when applying patterns or other validations to an IntOrString field. Knwon information about the type is applied during the collapse phase and as such is not normally available during marker application.
+nullable field
marks this field as allowing the "null" value.
This is often not necessary, but may be helpful with custom serialization.
+optional field
specifies that this field is optional, if fields are required by default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment