Skip to content

Commit ae86221

Browse files
committed
updates from api audit
Signed-off-by: Jordan Keister <[email protected]>
1 parent 6f42274 commit ae86221

File tree

4 files changed

+78
-44
lines changed

4 files changed

+78
-44
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
var ClusterExtensionKind = "ClusterExtension"
2626

2727
type (
28-
UpgradeConstraintPolicy string
29-
CRDUpgradeSafetyPolicy string
28+
UpgradeConstraintPolicy string
29+
CRDUpgradeSafetyEnforcement string
3030
)
3131

3232
const (
@@ -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.
393401
type 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

413422
const (
@@ -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

435446
func init() {
@@ -455,9 +466,11 @@ func init() {
455466
type 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
526543
type 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

532551
func init() {

config/base/crd/bases/olm.operatorframework.io_clusterextensions.yaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,28 @@ spec:
102102
103103
This field is required if the spec.install.preflight field is specified.
104104
properties:
105-
policy:
106-
default: Enabled
105+
enforcement:
106+
default: Strict
107107
description: |-
108-
policy is used to configure the state of the CRD Upgrade Safety pre-flight check.
108+
enforcement is used to configure the state of the CRD Upgrade Safety pre-flight check.
109109
110110
This field is required when the spec.install.preflight.crdUpgradeSafety field is
111111
specified.
112112
113-
Allowed values are ["Enabled", "Disabled"]. The default value is "Enabled".
113+
Allowed values are ["None", "Strict"]. The default value is "Strict".
114114
115-
When set to "Disabled", the CRD Upgrade Safety pre-flight check will be skipped
115+
When set to "None", the CRD Upgrade Safety pre-flight check will be skipped
116116
when performing an upgrade operation. This should be used with caution as
117117
unintended consequences such as data loss can occur.
118118
119-
When set to "Enabled", the CRD Upgrade Safety pre-flight check will be run when
119+
When set to "Strict", the CRD Upgrade Safety pre-flight check will be run when
120120
performing an upgrade operation.
121121
enum:
122-
- Enabled
123-
- Disabled
122+
- None
123+
- Strict
124124
type: string
125125
required:
126-
- policy
126+
- enforcement
127127
type: object
128128
required:
129129
- crdUpgradeSafety
@@ -433,7 +433,6 @@ spec:
433433
434434
For more information on semver, please see https://semver.org/
435435
maxLength: 64
436-
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*)*$
437436
type: string
438437
required:
439438
- packageName

0 commit comments

Comments
 (0)