Skip to content

Commit 0871178

Browse files
committed
Implement API changes according to RFC spec
resolves #1088 Summary: * v1 API now uses a `SourceConfig` discriminated union which will allow modularity for future install sources (bundles, charts, etc). * `SourceConfig` uses CEL validation to ensure only valid field names & values are utilized (`sourceType: Catalog` ensures that the `catalog` field is also set in `SourceConfig`). * Added new `clusterextension_admission` unit test for `SourceConfig` objects. The test covers both valid and invalid cases. * Fixed `clusterextension_controller` test where an unset `ClusterExtension` spec caused a null pointer deref. Signed-off-by: Josh Manning <[email protected]>
1 parent e664658 commit 0871178

12 files changed

+724
-382
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,78 @@ const (
4646

4747
// ClusterExtensionSpec defines the desired state of ClusterExtension
4848
type ClusterExtensionSpec struct {
49+
// source is the selected resolution source such as catalog or bundle
50+
Source SourceConfig `json:"source"`
51+
52+
// installNamespace is a reference to the Namespace in which the bundle of
53+
// content for the package referenced in the packageName field will be applied.
54+
// The bundle may contain cluster-scoped resources or resources that are
55+
// applied to other Namespaces. This Namespace is expected to exist.
56+
//
57+
// installNamespace is required, immutable, and follows the DNS label standard
58+
// as defined in RFC 1123. This means that valid values:
59+
// - Contain no more than 63 characters
60+
// - Contain only lowercase alphanumeric characters or '-'
61+
// - Start with an alphanumeric character
62+
// - End with an alphanumeric character
63+
//
64+
// Some examples of valid values are:
65+
// - some-namespace
66+
// - 123-namespace
67+
// - 1-namespace-2
68+
// - somenamespace
69+
//
70+
// Some examples of invalid values are:
71+
// - -some-namespace
72+
// - some-namespace-
73+
// - thisisareallylongnamespacenamethatisgreaterthanthemaximumlength
74+
// - some.namespace
75+
//
76+
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
77+
//+kubebuilder:validation:MaxLength:=63
78+
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="installNamespace is immutable"
79+
InstallNamespace string `json:"installNamespace"`
80+
81+
// 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.
82+
//
83+
// When specified, it overrides the default configuration of the preflight checks that are required to execute successfully during an install/upgrade operation.
84+
//
85+
// When not specified, the default configuration for each preflight check will be used.
86+
//
87+
//+optional
88+
Preflight *PreflightConfig `json:"preflight,omitempty"`
89+
90+
// serviceAccount is a required reference to a ServiceAccount that exists
91+
// in the installNamespace. The provided ServiceAccount is used to install and
92+
// manage the content for the package specified in the packageName field.
93+
//
94+
// In order to successfully install and manage the content for the package,
95+
// the ServiceAccount provided via this field should be configured with the
96+
// appropriate permissions to perform the necessary operations on all the
97+
// resources that are included in the bundle of content being applied.
98+
ServiceAccount ServiceAccountReference `json:"serviceAccount"`
99+
}
100+
101+
const ResolutionTypeCatalog = "Catalog"
102+
103+
// SourceConfig is a discriminated union which selects the type of resolver.
104+
// +union
105+
// +kubebuilder:validation:XValidation:rule="self.sourceType == 'Catalog' && has(self.catalog)",message="sourceType Catalog requires catalog field"
106+
type SourceConfig struct {
107+
108+
// sourceType selects the type of resolver and currently supports only one value: "Catalog"
109+
// +unionDiscriminator
110+
// +kubebuilder:validation:Enum:="Catalog"
111+
// +kubebuilder:validation:Required
112+
SourceType string `json:"sourceType,omitempty"`
113+
114+
// catalog defines required fields for catalog resolution. This field must be defined when sourceType is set to "Catalog".
115+
// +optional.
116+
Catalog *CatalogResolution `json:"catalog,omitempty"`
117+
}
118+
119+
// CatalogResolution defines the required fields for catalog source.
120+
type CatalogResolution struct {
49121
// packageName is a reference to the name of the package to be installed
50122
// and is used to filter the content from catalogs.
51123
//
@@ -204,7 +276,7 @@ type ClusterExtensionSpec struct {
204276
// the bundle selection process.
205277
//
206278
//+optional
207-
CatalogSelector metav1.LabelSelector `json:"catalogSelector,omitempty"`
279+
LabelSelector metav1.LabelSelector `json:"catalogSelector,omitempty"`
208280

209281
// upgradeConstraintPolicy is an optional field that controls whether
210282
// the upgrade path(s) defined in the catalog are enforced for the package
@@ -228,54 +300,6 @@ type ClusterExtensionSpec struct {
228300
//+kubebuilder:default:=Enforce
229301
//+optional
230302
UpgradeConstraintPolicy UpgradeConstraintPolicy `json:"upgradeConstraintPolicy,omitempty"`
231-
232-
// installNamespace is a reference to the Namespace in which the bundle of
233-
// content for the package referenced in the packageName field will be applied.
234-
// The bundle may contain cluster-scoped resources or resources that are
235-
// applied to other Namespaces. This Namespace is expected to exist.
236-
//
237-
// installNamespace is required, immutable, and follows the DNS label standard
238-
// as defined in RFC 1123. This means that valid values:
239-
// - Contain no more than 63 characters
240-
// - Contain only lowercase alphanumeric characters or '-'
241-
// - Start with an alphanumeric character
242-
// - End with an alphanumeric character
243-
//
244-
// Some examples of valid values are:
245-
// - some-namespace
246-
// - 123-namespace
247-
// - 1-namespace-2
248-
// - somenamespace
249-
//
250-
// Some examples of invalid values are:
251-
// - -some-namespace
252-
// - some-namespace-
253-
// - thisisareallylongnamespacenamethatisgreaterthanthemaximumlength
254-
// - some.namespace
255-
//
256-
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
257-
//+kubebuilder:validation:MaxLength:=63
258-
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="installNamespace is immutable"
259-
InstallNamespace string `json:"installNamespace"`
260-
261-
// 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.
262-
//
263-
// When specified, it overrides the default configuration of the preflight checks that are required to execute successfully during an install/upgrade operation.
264-
//
265-
// When not specified, the default configuration for each preflight check will be used.
266-
//
267-
//+optional
268-
Preflight *PreflightConfig `json:"preflight,omitempty"`
269-
270-
// serviceAccount is a required reference to a ServiceAccount that exists
271-
// in the installNamespace. The provided ServiceAccount is used to install and
272-
// manage the content for the package specified in the packageName field.
273-
//
274-
// In order to successfully install and manage the content for the package,
275-
// the ServiceAccount provided via this field should be configured with the
276-
// appropriate permissions to perform the necessary operations on all the
277-
// resources that are included in the bundle of content being applied.
278-
ServiceAccount ServiceAccountReference `json:"serviceAccount"`
279303
}
280304

281305
// ServiceAccountReference references a serviceAccount.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)