Skip to content

Commit aaa0e00

Browse files
authored
⚠️ Move .spec.install.namespace and .spec.install.serviceAccount to .spec.namespace and .spec.serviceAccount (#1439)
* move namespace and serviceAccount fields to spec root Signed-off-by: everettraven <[email protected]> * address comments, make verify Signed-off-by: everettraven <[email protected]> * fix e2e failures Signed-off-by: everettraven <[email protected]> --------- Signed-off-by: everettraven <[email protected]>
1 parent 6c2be08 commit aaa0e00

13 files changed

+270
-277
lines changed

api/v1alpha1/clusterextension_types.go

+33-41
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@ const (
4343

4444
// ClusterExtensionSpec defines the desired state of ClusterExtension
4545
type ClusterExtensionSpec struct {
46+
// namespace is a reference to a Kubernetes namespace.
47+
// This is the namespace in which the provided ServiceAccount must exist.
48+
// It also designates the default namespace where namespace-scoped resources
49+
// for the extension are applied to the cluster.
50+
// Some extensions may contain namespace-scoped resources to be applied in other namespaces.
51+
// This namespace must exist.
52+
//
53+
// namespace is required, immutable, and follows the DNS label standard
54+
// as defined in [RFC 1123]. It must contain only lowercase alphanumeric characters or hyphens (-),
55+
// start and end with an alphanumeric character, and be no longer than 63 characters
56+
//
57+
// [RFC 1123]: https://tools.ietf.org/html/rfc1123
58+
//
59+
// +kubebuilder:validation:MaxLength:=63
60+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="namespace is immutable"
61+
// +kubebuilder:validation:XValidation:rule="self.matches(\"^[a-z0-9]([-a-z0-9]*[a-z0-9])?$\")",message="namespace must be a valid DNS1123 label"
62+
// +kubebuilder:validation:Required
63+
Namespace string `json:"namespace"`
64+
65+
// serviceAccount is a reference to a ServiceAccount used to perform all interactions
66+
// with the cluster that are required to manage the extension.
67+
// The ServiceAccount must be configured with the necessary permissions to perform these interactions.
68+
// The ServiceAccount must exist in the namespace referenced in the spec.
69+
// serviceAccount is required.
70+
//
71+
// +kubebuilder:validation:Required
72+
ServiceAccount ServiceAccountReference `json:"serviceAccount"`
73+
4674
// source is a required field which selects the installation source of content
4775
// for this ClusterExtension. Selection is performed by setting the sourceType.
4876
//
@@ -59,18 +87,11 @@ type ClusterExtensionSpec struct {
5987
// +kubebuilder:validation:Required
6088
Source SourceConfig `json:"source"`
6189

62-
// install is a required field used to configure the installation options
63-
// for the ClusterExtension such as the installation namespace,
64-
// the service account and the pre-flight check configuration.
90+
// install is an optional field used to configure the installation options
91+
// for the ClusterExtension such as the pre-flight check configuration.
6592
//
66-
// Below is a minimal example of an installation definition (in yaml):
67-
// install:
68-
// namespace: example-namespace
69-
// serviceAccount:
70-
// name: example-sa
71-
//
72-
// +kubebuilder:validation:Required
73-
Install ClusterExtensionInstallConfig `json:"install"`
93+
// +optional
94+
Install *ClusterExtensionInstallConfig `json:"install,omitempty"`
7495
}
7596

7697
const SourceTypeCatalog = "Catalog"
@@ -104,38 +125,9 @@ type SourceConfig struct {
104125
// ClusterExtensionInstallConfig is a union which selects the clusterExtension installation config.
105126
// ClusterExtensionInstallConfig requires the namespace and serviceAccount which should be used for the installation of packages.
106127
//
128+
// +kubebuilder:validation:XValidation:rule="has(self.preflight)",message="at least one of [preflight] are required when install is specified"
107129
// +union
108130
type ClusterExtensionInstallConfig struct {
109-
// namespace designates the kubernetes Namespace where bundle content
110-
// for the package, referenced in the 'packageName' field, will be applied and the necessary
111-
// service account can be found.
112-
// The bundle may contain cluster-scoped resources or resources that are
113-
// applied to other Namespaces. This Namespace is expected to exist.
114-
//
115-
// namespace is required, immutable, and follows the DNS label standard
116-
// as defined in [RFC 1123]. It must contain only lowercase alphanumeric characters or hyphens (-),
117-
// start and end with an alphanumeric character, and be no longer than 63 characters
118-
//
119-
// [RFC 1123]: https://tools.ietf.org/html/rfc1123
120-
//
121-
// +kubebuilder:validation:MaxLength:=63
122-
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="namespace is immutable"
123-
// +kubebuilder:validation:XValidation:rule="self.matches(\"^[a-z0-9]([-a-z0-9]*[a-z0-9])?$\")",message="namespace must be a valid DNS1123 label. It must contain only lowercase alphanumeric characters or hyphens (-), start and end with an alphanumeric character, and be no longer than 63 characters"
124-
// +kubebuilder:validation:Required
125-
Namespace string `json:"namespace"`
126-
127-
// serviceAccount is a required reference to a ServiceAccount that exists
128-
// in the installNamespace which is used to install and
129-
// manage the content for the package specified in the packageName field.
130-
//
131-
// In order to successfully install and manage the content for the package,
132-
// the ServiceAccount provided via this field should be configured with the
133-
// appropriate permissions to perform the necessary operations on all the
134-
// resources that are included in the bundle of content being applied.
135-
//
136-
// +kubebuilder:validation:Required
137-
ServiceAccount ServiceAccountReference `json:"serviceAccount"`
138-
139131
// preflight is an optional field that can be used to configure the checks that are
140132
// run before installation or upgrade of the content for the package specified in the packageName field.
141133
//

api/v1alpha1/zz_generated.deepcopy.go

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/manager/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func main() {
197197
helmclient.StorageDriverMapper(action.ChunkedStorageDriverMapper(coreClient, mgr.GetAPIReader(), systemNamespace)),
198198
helmclient.ClientNamespaceMapper(func(obj client.Object) (string, error) {
199199
ext := obj.(*ocv1alpha1.ClusterExtension)
200-
return ext.Spec.Install.Namespace, nil
200+
return ext.Spec.Namespace, nil
201201
}),
202202
helmclient.ClientRestConfigMapper(clientRestConfigMapper),
203203
)

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

+68-78
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,9 @@ spec:
5858
properties:
5959
install:
6060
description: |-
61-
install is a required field used to configure the installation options
62-
for the ClusterExtension such as the installation namespace,
63-
the service account and the pre-flight check configuration.
64-
65-
Below is a minimal example of an installation definition (in yaml):
66-
install:
67-
namespace: example-namespace
68-
serviceAccount:
69-
name: example-sa
61+
install is an optional field used to configure the installation options
62+
for the ClusterExtension such as the pre-flight check configuration.
7063
properties:
71-
namespace:
72-
description: |-
73-
namespace designates the kubernetes Namespace where bundle content
74-
for the package, referenced in the 'packageName' field, will be applied and the necessary
75-
service account can be found.
76-
The bundle may contain cluster-scoped resources or resources that are
77-
applied to other Namespaces. This Namespace is expected to exist.
78-
79-
namespace is required, immutable, and follows the DNS label standard
80-
as defined in [RFC 1123]. It must contain only lowercase alphanumeric characters or hyphens (-),
81-
start and end with an alphanumeric character, and be no longer than 63 characters
82-
83-
[RFC 1123]: https://tools.ietf.org/html/rfc1123
84-
maxLength: 63
85-
type: string
86-
x-kubernetes-validations:
87-
- message: namespace is immutable
88-
rule: self == oldSelf
89-
- message: namespace must be a valid DNS1123 label. It must contain
90-
only lowercase alphanumeric characters or hyphens (-), start
91-
and end with an alphanumeric character, and be no longer than
92-
63 characters
93-
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
9464
preflight:
9565
description: |-
9666
preflight is an optional field that can be used to configure the checks that are
@@ -133,58 +103,77 @@ spec:
133103
- message: at least one of [crdUpgradeSafety] are required when
134104
preflight is specified
135105
rule: has(self.crdUpgradeSafety)
136-
serviceAccount:
106+
type: object
107+
x-kubernetes-validations:
108+
- message: at least one of [preflight] are required when install is
109+
specified
110+
rule: has(self.preflight)
111+
namespace:
112+
description: |-
113+
namespace is a reference to a Kubernetes namespace.
114+
This is the namespace in which the provided ServiceAccount must exist.
115+
It also designates the default namespace where namespace-scoped resources
116+
for the extension are applied to the cluster.
117+
Some extensions may contain namespace-scoped resources to be applied in other namespaces.
118+
This namespace must exist.
119+
120+
namespace is required, immutable, and follows the DNS label standard
121+
as defined in [RFC 1123]. It must contain only lowercase alphanumeric characters or hyphens (-),
122+
start and end with an alphanumeric character, and be no longer than 63 characters
123+
124+
[RFC 1123]: https://tools.ietf.org/html/rfc1123
125+
maxLength: 63
126+
type: string
127+
x-kubernetes-validations:
128+
- message: namespace is immutable
129+
rule: self == oldSelf
130+
- message: namespace must be a valid DNS1123 label
131+
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
132+
serviceAccount:
133+
description: |-
134+
serviceAccount is a reference to a ServiceAccount used to perform all interactions
135+
with the cluster that are required to manage the extension.
136+
The ServiceAccount must be configured with the necessary permissions to perform these interactions.
137+
The ServiceAccount must exist in the namespace referenced in the spec.
138+
serviceAccount is required.
139+
properties:
140+
name:
137141
description: |-
138-
serviceAccount is a required reference to a ServiceAccount that exists
139-
in the installNamespace which is used to install and
140-
manage the content for the package specified in the packageName field.
141-
142-
In order to successfully install and manage the content for the package,
143-
the ServiceAccount provided via this field should be configured with the
144-
appropriate permissions to perform the necessary operations on all the
145-
resources that are included in the bundle of content being applied.
146-
properties:
147-
name:
148-
description: |-
149-
name is a required, immutable reference to the name of the ServiceAccount
150-
to be used for installation and management of the content for the package
151-
specified in the packageName field.
142+
name is a required, immutable reference to the name of the ServiceAccount
143+
to be used for installation and management of the content for the package
144+
specified in the packageName field.
152145
153-
This ServiceAccount must exist in the installNamespace.
146+
This ServiceAccount must exist in the installNamespace.
154147
155-
name follows the DNS subdomain standard as defined in [RFC 1123].
156-
It must contain only lowercase alphanumeric characters,
157-
hyphens (-) or periods (.), start and end with an alphanumeric character,
158-
and be no longer than 253 characters.
148+
name follows the DNS subdomain standard as defined in [RFC 1123].
149+
It must contain only lowercase alphanumeric characters,
150+
hyphens (-) or periods (.), start and end with an alphanumeric character,
151+
and be no longer than 253 characters.
159152
160-
Some examples of valid values are:
161-
- some-serviceaccount
162-
- 123-serviceaccount
163-
- 1-serviceaccount-2
164-
- someserviceaccount
165-
- some.serviceaccount
153+
Some examples of valid values are:
154+
- some-serviceaccount
155+
- 123-serviceaccount
156+
- 1-serviceaccount-2
157+
- someserviceaccount
158+
- some.serviceaccount
166159
167-
Some examples of invalid values are:
168-
- -some-serviceaccount
169-
- some-serviceaccount-
160+
Some examples of invalid values are:
161+
- -some-serviceaccount
162+
- some-serviceaccount-
170163
171-
[RFC 1123]: https://tools.ietf.org/html/rfc1123
172-
maxLength: 253
173-
type: string
174-
x-kubernetes-validations:
175-
- message: name is immutable
176-
rule: self == oldSelf
177-
- message: name must be a valid DNS1123 subdomain. It must
178-
contain only lowercase alphanumeric characters, hyphens
179-
(-) or periods (.), start and end with an alphanumeric
180-
character, and be no longer than 253 characters
181-
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
182-
required:
183-
- name
184-
type: object
164+
[RFC 1123]: https://tools.ietf.org/html/rfc1123
165+
maxLength: 253
166+
type: string
167+
x-kubernetes-validations:
168+
- message: name is immutable
169+
rule: self == oldSelf
170+
- message: name must be a valid DNS1123 subdomain. It must contain
171+
only lowercase alphanumeric characters, hyphens (-) or periods
172+
(.), start and end with an alphanumeric character, and be
173+
no longer than 253 characters
174+
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
185175
required:
186-
- namespace
187-
- serviceAccount
176+
- name
188177
type: object
189178
source:
190179
description: |-
@@ -468,7 +457,8 @@ spec:
468457
rule: 'has(self.sourceType) && self.sourceType == ''Catalog'' ?
469458
has(self.catalog) : !has(self.catalog)'
470459
required:
471-
- install
460+
- namespace
461+
- serviceAccount
472462
- source
473463
type: object
474464
status:

config/samples/olm_v1alpha1_clusterextension.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,11 @@ kind: ClusterExtension
272272
metadata:
273273
name: argocd
274274
spec:
275+
namespace: argocd
276+
serviceAccount:
277+
name: argocd-installer
275278
source:
276279
sourceType: Catalog
277280
catalog:
278281
packageName: argocd-operator
279282
version: 0.6.0
280-
install:
281-
namespace: argocd
282-
serviceAccount:
283-
name: argocd-installer

0 commit comments

Comments
 (0)