@@ -25,8 +25,8 @@ import (
2525var ClusterExtensionKind = "ClusterExtension"
2626
2727type (
28- UpgradeConstraintPolicy string
29- CRDUpgradeSafetyPolicy string
28+ UpgradeConstraintPolicy string
29+ CRDUpgradeSafetyEnforcement string
3030)
3131
3232const (
@@ -58,6 +58,7 @@ type ClusterExtensionSpec struct {
5858 // catalog:
5959 // packageName: example-package
6060 //
61+ // +kubebuilder:validation:Required
6162 Source SourceConfig `json:"source"`
6263
6364 // install is a required field used to configure the installation options
@@ -69,6 +70,7 @@ type ClusterExtensionSpec struct {
6970 // namespace: example-namespace
7071 // serviceAccount:
7172 // name: example-sa
73+ // +kubebuilder:validation:Required
7274 Install ClusterExtensionInstallConfig `json:"install"`
7375}
7476
@@ -88,6 +90,7 @@ type SourceConfig struct {
8890 //
8991 // +unionDiscriminator
9092 // +kubebuilder:validation:Enum:="Catalog"
93+ // +kubebuilder:validation:Required
9194 SourceType string `json:"sourceType"`
9295
9396 // catalog is used to configure how information is sourced from a catalog. This field must be defined when sourceType is set to "Catalog",
@@ -130,6 +133,7 @@ type ClusterExtensionInstallConfig struct {
130133 //+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
131134 //+kubebuilder:validation:MaxLength:=63
132135 //+kubebuilder:validation:XValidation:rule="self == oldSelf",message="namespace is immutable"
136+ //+kubebuilder:validation:Required
133137 Namespace string `json:"namespace"`
134138
135139 // serviceAccount is a required reference to a ServiceAccount that exists
@@ -140,6 +144,7 @@ type ClusterExtensionInstallConfig struct {
140144 // the ServiceAccount provided via this field should be configured with the
141145 // appropriate permissions to perform the necessary operations on all the
142146 // resources that are included in the bundle of content being applied.
147+ //+kubebuilder:validation:Required
143148 ServiceAccount ServiceAccountReference `json:"serviceAccount"`
144149
145150 // preflight is an optional field that can be used to configure the preflight checks run before installation or upgrade of the content for the package specified in the packageName field.
@@ -181,6 +186,7 @@ type CatalogSource struct {
181186 //+kubebuilder:validation:MaxLength:=253
182187 //+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
183188 //+kubebuilder:validation:XValidation:rule="self == oldSelf",message="packageName is immutable"
189+ //+kubebuilder:validation:Required
184190 PackageName string `json:"packageName"`
185191
186192 // version is an optional semver constraint (a specific version or range of versions). When unspecified, the latest version available will be installed.
@@ -258,7 +264,7 @@ type CatalogSource struct {
258264 // For more information on semver, please see https://semver.org/
259265 //
260266 //+kubebuilder:validation:MaxLength:=64
261- //+kubebuilder:validation:Pattern=` ^(\s*(=||!=|>|<|>=|=>|<=|=<|~|~>|\^)\s*(v?(0|[1-9]\d*|[x|X|\*])(\.(0|[1-9]\d*|x|X|\*]))?(\.(0|[1-9]\d*|x|X|\*))?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?)\s*)((?:\s+|,\s*|\s*\|\|\s*)(=||!=|>|<|>=|=>|<=|=<|~|~>|\^)\s*(v?(0|[1-9]\d*|x|X|\*])(\.(0|[1-9]\d*|x|X|\*))?(\.(0|[1-9]\d*|x|X|\*]))?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?)\s*)*$`
267+ //+kubebuilder:validation.XValidation:rule="self.matches(r' ^(\s*(=||!=|>|<|>=|=>|<=|=<|~|~>|\^)\s*(v?(0|[1-9]\d*|[x|X|\*])(\.(0|[1-9]\d*|x|X|\*]))?(\.(0|[1-9]\d*|x|X|\*))?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?)\s*)((?:\s+|,\s*|\s*\|\|\s*)(=||!=|>|<|>=|=>|<=|=<|~|~>|\^)\s*(v?(0|[1-9]\d*|x|X|\*])(\.(0|[1-9]\d*|x|X|\*))?(\.(0|[1-9]\d*|x|X|\*]))?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?)\s*)*$')"", message="invalid version expression in the catalog source"
262268 //+optional
263269 Version string `json:"version,omitempty"`
264270
@@ -373,6 +379,7 @@ type ServiceAccountReference struct {
373379 //+kubebuilder:validation:MaxLength:=253
374380 //+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
375381 //+kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
382+ //+kubebuilder:validation:Required
376383 Name string `json:"name"`
377384}
378385
@@ -386,28 +393,30 @@ type PreflightConfig struct {
386393 // consequences of upgrading a CRD, such as data loss.
387394 //
388395 // This field is required if the spec.install.preflight field is specified.
396+ //+kubebuilder:validation:Required
389397 CRDUpgradeSafety * CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety"`
390398}
391399
392400// CRDUpgradeSafetyPreflightConfig is the configuration for CRD upgrade safety preflight check.
393401type CRDUpgradeSafetyPreflightConfig struct {
394- // policy is used to configure the state of the CRD Upgrade Safety pre-flight check.
402+ // enforcement is used to configure the state of the CRD Upgrade Safety pre-flight check.
395403 //
396404 // This field is required when the spec.install.preflight.crdUpgradeSafety field is
397405 // specified.
398406 //
399- // Allowed values are ["Enabled ", "Disabled "]. The default value is "Enabled ".
407+ // Allowed values are ["None ", "Strict "]. The default value is "Strict ".
400408 //
401- // When set to "Disabled ", the CRD Upgrade Safety pre-flight check will be skipped
409+ // When set to "None ", the CRD Upgrade Safety pre-flight check will be skipped
402410 // when performing an upgrade operation. This should be used with caution as
403411 // unintended consequences such as data loss can occur.
404412 //
405- // When set to "Enabled ", the CRD Upgrade Safety pre-flight check will be run when
413+ // When set to "Strict ", the CRD Upgrade Safety pre-flight check will be run when
406414 // performing an upgrade operation.
407415 //
408- //+kubebuilder:validation:Enum:="Enabled";"Disabled"
409- //+kubebuilder:default:=Enabled
410- Policy CRDUpgradeSafetyPolicy `json:"policy"`
416+ //+kubebuilder:validation:Enum:="None";"Strict"
417+ //+kubebuilder:default:=Strict
418+ //+kubebuilder:validation:Required
419+ Enforcement CRDUpgradeSafetyEnforcement `json:"enforcement"`
411420}
412421
413422const (
@@ -428,8 +437,10 @@ const (
428437 ReasonBlocked = "Blocked"
429438 ReasonRetrying = "Retrying"
430439
431- CRDUpgradeSafetyPolicyEnabled CRDUpgradeSafetyPolicy = "Enabled"
432- CRDUpgradeSafetyPolicyDisabled CRDUpgradeSafetyPolicy = "Disabled"
440+ // None will not perform CRD upgrade safety checks.
441+ CRDUpgradeSafetyEnforcementNone CRDUpgradeSafetyEnforcement = "None"
442+ // Strict will enforce the CRD upgrade safety check and block the upgrade if the CRD would not pass the check.
443+ CRDUpgradeSafetyEnforcementStrict CRDUpgradeSafetyEnforcement = "Strict"
433444)
434445
435446func init () {
@@ -455,9 +466,11 @@ func init() {
455466type BundleMetadata struct {
456467 // name is a required field and is a reference
457468 // to the name of a bundle
469+ //+kubebuilder:validation:Required
458470 Name string `json:"name"`
459471 // version is a required field and is a reference
460472 // to the version that this bundle represents
473+ //+kubebuilder:validation:Required
461474 Version string `json:"version"`
462475}
463476
@@ -496,6 +509,7 @@ type ClusterExtensionStatus struct {
496509 // +patchStrategy=merge
497510 // +listType=map
498511 // +listMapKey=type
512+ // +optional
499513 Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
500514}
501515
@@ -504,6 +518,7 @@ type ClusterExtensionInstallStatus struct {
504518 //
505519 // A "bundle" is a versioned set of content that represents the resources that
506520 // need to be applied to a cluster to install a package.
521+ //+kubebuilder:validation:Required
507522 Bundle BundleMetadata `json:"bundle"`
508523}
509524
@@ -516,7 +531,9 @@ type ClusterExtension struct {
516531 metav1.TypeMeta `json:",inline"`
517532 metav1.ObjectMeta `json:"metadata,omitempty"`
518533
519- Spec ClusterExtensionSpec `json:"spec,omitempty"`
534+ //+optional
535+ Spec ClusterExtensionSpec `json:"spec,omitempty"`
536+ //+optional
520537 Status ClusterExtensionStatus `json:"status,omitempty"`
521538}
522539
@@ -525,8 +542,10 @@ type ClusterExtension struct {
525542// ClusterExtensionList contains a list of ClusterExtension
526543type ClusterExtensionList struct {
527544 metav1.TypeMeta `json:",inline"`
545+ //+optional
528546 metav1.ListMeta `json:"metadata,omitempty"`
529- Items []ClusterExtension `json:"items"`
547+ //+kubebuilder:validation:Required
548+ Items []ClusterExtension `json:"items"`
530549}
531550
532551func init () {
0 commit comments