Skip to content

Commit 0aa7e92

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

File tree

4 files changed

+95
-56
lines changed

4 files changed

+95
-56
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 40 additions & 20 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

@@ -80,14 +82,16 @@ const SourceTypeCatalog = "Catalog"
8082
type SourceConfig struct {
8183
// sourceType is a required reference to the type of install source.
8284
//
83-
// Allowed values are ["Catalog"]
85+
// Allowed values are "Catalog"
8486
//
85-
// When this field is set to "Catalog", information for determining the appropriate
86-
// bundle of content to install will be fetched from ClusterCatalog resources existing
87-
// on the cluster. When using the Catalog sourceType, the catalog field must also be set.
87+
// When this field is set to "Catalog", information for determining the
88+
// appropriate bundle of content to install will be fetched from
89+
// ClusterCatalog resources existing on the cluster.
90+
// When using the Catalog sourceType, the catalog field must also be set.
8891
//
8992
// +unionDiscriminator
9093
// +kubebuilder:validation:Enum:="Catalog"
94+
// +kubebuilder:validation:Required
9195
SourceType string `json:"sourceType"`
9296

9397
// 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 +134,7 @@ type ClusterExtensionInstallConfig struct {
130134
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
131135
//+kubebuilder:validation:MaxLength:=63
132136
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="namespace is immutable"
137+
//+kubebuilder:validation:Required
133138
Namespace string `json:"namespace"`
134139

135140
// serviceAccount is a required reference to a ServiceAccount that exists
@@ -140,6 +145,7 @@ type ClusterExtensionInstallConfig struct {
140145
// the ServiceAccount provided via this field should be configured with the
141146
// appropriate permissions to perform the necessary operations on all the
142147
// resources that are included in the bundle of content being applied.
148+
//+kubebuilder:validation:Required
143149
ServiceAccount ServiceAccountReference `json:"serviceAccount"`
144150

145151
// 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 +187,7 @@ type CatalogSource struct {
181187
//+kubebuilder:validation:MaxLength:=253
182188
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
183189
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="packageName is immutable"
190+
//+kubebuilder:validation:Required
184191
PackageName string `json:"packageName"`
185192

186193
// version is an optional semver constraint (a specific version or range of versions). When unspecified, the latest version available will be installed.
@@ -258,14 +265,14 @@ type CatalogSource struct {
258265
// For more information on semver, please see https://semver.org/
259266
//
260267
//+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*)*$`
268+
//+kubebuilder:validation:XValidation:rule="self.matches(\"^(\\\\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"
262269
//+optional
263270
Version string `json:"version,omitempty"`
264271

265272
// channels is an optional reference to a set of channels belonging to
266273
// the package specified in the packageName field.
267274
//
268-
// A "channel" is a package author defined stream of updates for an extension.
275+
// A "channel" is a package-author-defined stream of updates for an extension.
269276
//
270277
// When specified, it is used to constrain the set of installable bundles and
271278
// the automated upgrade path. This constraint is an AND operation with the
@@ -322,7 +329,7 @@ type CatalogSource struct {
322329
// the upgrade path(s) defined in the catalog are enforced for the package
323330
// referenced in the packageName field.
324331
//
325-
// Allowed values are: ["CatalogProvided", "SelfCertified"].
332+
// Allowed values are: "CatalogProvided" or "SelfCertified".
326333
//
327334
// When this field is set to "CatalogProvided", automatic upgrades will only occur
328335
// when upgrade constraints specified by the package author are met.
@@ -373,6 +380,7 @@ type ServiceAccountReference struct {
373380
//+kubebuilder:validation:MaxLength:=253
374381
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
375382
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
383+
//+kubebuilder:validation:Required
376384
Name string `json:"name"`
377385
}
378386

@@ -386,28 +394,30 @@ type PreflightConfig struct {
386394
// consequences of upgrading a CRD, such as data loss.
387395
//
388396
// This field is required if the spec.install.preflight field is specified.
397+
//+kubebuilder:validation:Required
389398
CRDUpgradeSafety *CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety"`
390399
}
391400

392401
// CRDUpgradeSafetyPreflightConfig is the configuration for CRD upgrade safety preflight check.
393402
type CRDUpgradeSafetyPreflightConfig struct {
394-
// policy is used to configure the state of the CRD Upgrade Safety pre-flight check.
403+
// enforcement is used to configure the state of the CRD Upgrade Safety pre-flight check.
395404
//
396405
// This field is required when the spec.install.preflight.crdUpgradeSafety field is
397406
// specified.
398407
//
399-
// Allowed values are ["Enabled", "Disabled"]. The default value is "Enabled".
408+
// Allowed values are "None" or "Strict". The default value is "Strict".
400409
//
401-
// When set to "Disabled", the CRD Upgrade Safety pre-flight check will be skipped
410+
// When set to "None", the CRD Upgrade Safety pre-flight check will be skipped
402411
// when performing an upgrade operation. This should be used with caution as
403412
// unintended consequences such as data loss can occur.
404413
//
405-
// When set to "Enabled", the CRD Upgrade Safety pre-flight check will be run when
414+
// When set to "Strict", the CRD Upgrade Safety pre-flight check will be run when
406415
// performing an upgrade operation.
407416
//
408-
//+kubebuilder:validation:Enum:="Enabled";"Disabled"
409-
//+kubebuilder:default:=Enabled
410-
Policy CRDUpgradeSafetyPolicy `json:"policy"`
417+
//+kubebuilder:validation:Enum:="None";"Strict"
418+
//+kubebuilder:default:=Strict
419+
//+kubebuilder:validation:Required
420+
Enforcement CRDUpgradeSafetyEnforcement `json:"enforcement"`
411421
}
412422

413423
const (
@@ -428,8 +438,10 @@ const (
428438
ReasonBlocked = "Blocked"
429439
ReasonRetrying = "Retrying"
430440

431-
CRDUpgradeSafetyPolicyEnabled CRDUpgradeSafetyPolicy = "Enabled"
432-
CRDUpgradeSafetyPolicyDisabled CRDUpgradeSafetyPolicy = "Disabled"
441+
// None will not perform CRD upgrade safety checks.
442+
CRDUpgradeSafetyEnforcementNone CRDUpgradeSafetyEnforcement = "None"
443+
// Strict will enforce the CRD upgrade safety check and block the upgrade if the CRD would not pass the check.
444+
CRDUpgradeSafetyEnforcementStrict CRDUpgradeSafetyEnforcement = "Strict"
433445
)
434446

435447
func init() {
@@ -455,9 +467,11 @@ func init() {
455467
type BundleMetadata struct {
456468
// name is a required field and is a reference
457469
// to the name of a bundle
470+
//+kubebuilder:validation:Required
458471
Name string `json:"name"`
459472
// version is a required field and is a reference
460473
// to the version that this bundle represents
474+
//+kubebuilder:validation:Required
461475
Version string `json:"version"`
462476
}
463477

@@ -496,6 +510,7 @@ type ClusterExtensionStatus struct {
496510
// +patchStrategy=merge
497511
// +listType=map
498512
// +listMapKey=type
513+
// +optional
499514
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
500515
}
501516

@@ -504,6 +519,7 @@ type ClusterExtensionInstallStatus struct {
504519
//
505520
// A "bundle" is a versioned set of content that represents the resources that
506521
// need to be applied to a cluster to install a package.
522+
//+kubebuilder:validation:Required
507523
Bundle BundleMetadata `json:"bundle"`
508524
}
509525

@@ -516,7 +532,9 @@ type ClusterExtension struct {
516532
metav1.TypeMeta `json:",inline"`
517533
metav1.ObjectMeta `json:"metadata,omitempty"`
518534

519-
Spec ClusterExtensionSpec `json:"spec,omitempty"`
535+
//+optional
536+
Spec ClusterExtensionSpec `json:"spec,omitempty"`
537+
//+optional
520538
Status ClusterExtensionStatus `json:"status,omitempty"`
521539
}
522540

@@ -525,8 +543,10 @@ type ClusterExtension struct {
525543
// ClusterExtensionList contains a list of ClusterExtension
526544
type ClusterExtensionList struct {
527545
metav1.TypeMeta `json:",inline"`
546+
//+optional
528547
metav1.ListMeta `json:"metadata,omitempty"`
529-
Items []ClusterExtension `json:"items"`
548+
//+kubebuilder:validation:Required
549+
Items []ClusterExtension `json:"items"`
530550
}
531551

532552
func init() {

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

Lines changed: 19 additions & 16 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" or "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
@@ -208,7 +208,7 @@ spec:
208208
channels is an optional reference to a set of channels belonging to
209209
the package specified in the packageName field.
210210
211-
A "channel" is a package author defined stream of updates for an extension.
211+
A "channel" is a package-author-defined stream of updates for an extension.
212212
213213
When specified, it is used to constrain the set of installable bundles and
214214
the automated upgrade path. This constraint is an AND operation with the
@@ -340,7 +340,7 @@ spec:
340340
the upgrade path(s) defined in the catalog are enforced for the package
341341
referenced in the packageName field.
342342
343-
Allowed values are: ["CatalogProvided", "SelfCertified"].
343+
Allowed values are: "CatalogProvided" or "SelfCertified".
344344
345345
When this field is set to "CatalogProvided", automatic upgrades will only occur
346346
when upgrade constraints specified by the package author are met.
@@ -433,20 +433,23 @@ 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
437+
x-kubernetes-validations:
438+
- message: invalid version expression in the catalog source
439+
rule: self.matches("^(\\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*)*$")
438440
required:
439441
- packageName
440442
type: object
441443
sourceType:
442444
description: |-
443445
sourceType is a required reference to the type of install source.
444446
445-
Allowed values are ["Catalog"]
447+
Allowed values are "Catalog"
446448
447-
When this field is set to "Catalog", information for determining the appropriate
448-
bundle of content to install will be fetched from ClusterCatalog resources existing
449-
on the cluster. When using the Catalog sourceType, the catalog field must also be set.
449+
When this field is set to "Catalog", information for determining the
450+
appropriate bundle of content to install will be fetched from
451+
ClusterCatalog resources existing on the cluster.
452+
When using the Catalog sourceType, the catalog field must also be set.
450453
enum:
451454
- Catalog
452455
type: string

0 commit comments

Comments
 (0)