Skip to content

Commit 9c380ac

Browse files
authored
Merge pull request #177 from alexander-demicev/secretnamespace
✨ Add ability to specify a namespace for provider secret
2 parents 2bb6847 + cb00b95 commit 9c380ac

18 files changed

+327
-18
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests for the operator e.g
294294
$(CONTROLLER_GEN) \
295295
paths=./api/... \
296296
paths=./internal/controller/... \
297+
paths=./internal/webhook/... \
297298
crd:crdVersions=v1 \
298299
rbac:roleName=manager-role \
299300
output:crd:dir=./config/crd/bases \

api/v1alpha1/provider_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ type ProviderSpec struct {
5151
// +optional
5252
SecretName string `json:"secretName,omitempty"`
5353

54+
// SecretNamespace is the namespace of the Secret providing the configuration variables. If not specified,
55+
// the namespace of the provider will be used.
56+
SecretNamespace string `json:"secretNamespace,omitempty"`
57+
5458
// FetchConfig determines how the operator will fetch the components and metadata for the provider.
5559
// If nil, the operator will try to fetch components according to default
5660
// embedded fetch configuration for the given kind and `ObjectMeta.Name`.

config/chart/webhookcainjection_patch.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# This patch add annotation to admission webhook config and
22
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
33
apiVersion: admissionregistration.k8s.io/v1
4+
kind: MutatingWebhookConfiguration
5+
metadata:
6+
name: mutating-webhook-configuration
7+
annotations:
8+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
9+
---
10+
apiVersion: admissionregistration.k8s.io/v1
411
kind: ValidatingWebhookConfiguration
512
metadata:
613
name: validating-webhook-configuration

config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,11 @@ spec:
14501450
name should be updated. The contents should be in the form of key:value.
14511451
This secret must be in the same namespace as the provider.
14521452
type: string
1453+
secretNamespace:
1454+
description: SecretNamespace is the namespace of the Secret providing
1455+
the configuration variables. If not specified, the namespace of
1456+
the provider will be used.
1457+
type: string
14531458
version:
14541459
description: Version indicates the provider version.
14551460
type: string

config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,11 @@ spec:
14511451
name should be updated. The contents should be in the form of key:value.
14521452
This secret must be in the same namespace as the provider.
14531453
type: string
1454+
secretNamespace:
1455+
description: SecretNamespace is the namespace of the Secret providing
1456+
the configuration variables. If not specified, the namespace of
1457+
the provider will be used.
1458+
type: string
14541459
version:
14551460
description: Version indicates the provider version.
14561461
type: string

config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,11 @@ spec:
14501450
name should be updated. The contents should be in the form of key:value.
14511451
This secret must be in the same namespace as the provider.
14521452
type: string
1453+
secretNamespace:
1454+
description: SecretNamespace is the namespace of the Secret providing
1455+
the configuration variables. If not specified, the namespace of
1456+
the provider will be used.
1457+
type: string
14531458
version:
14541459
description: Version indicates the provider version.
14551460
type: string

config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,11 @@ spec:
14511451
name should be updated. The contents should be in the form of key:value.
14521452
This secret must be in the same namespace as the provider.
14531453
type: string
1454+
secretNamespace:
1455+
description: SecretNamespace is the namespace of the Secret providing
1456+
the configuration variables. If not specified, the namespace of
1457+
the provider will be used.
1458+
type: string
14541459
version:
14551460
description: Version indicates the provider version.
14561461
type: string

config/default/webhookcainjection_patch.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# This patch add annotation to admission webhook config and
22
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
33
apiVersion: admissionregistration.k8s.io/v1
4+
kind: MutatingWebhookConfiguration
5+
metadata:
6+
name: mutating-webhook-configuration
7+
annotations:
8+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
9+
---
10+
apiVersion: admissionregistration.k8s.io/v1
411
kind: ValidatingWebhookConfiguration
512
metadata:
613
name: validating-webhook-configuration

config/webhook/manifests.yaml

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,113 @@
11
---
22
apiVersion: admissionregistration.k8s.io/v1
3+
kind: MutatingWebhookConfiguration
4+
metadata:
5+
name: mutating-webhook-configuration
6+
webhooks:
7+
- admissionReviewVersions:
8+
- v1
9+
- v1beta1
10+
clientConfig:
11+
service:
12+
name: webhook-service
13+
namespace: system
14+
path: /mutate-operator-cluster-x-k8s-io-v1alpha1-bootstrapprovider
15+
failurePolicy: Fail
16+
matchPolicy: Equivalent
17+
name: vbootstrapprovider.kb.io
18+
rules:
19+
- apiGroups:
20+
- operator.cluster.x-k8s.io
21+
apiVersions:
22+
- v1alpha1
23+
operations:
24+
- CREATE
25+
- UPDATE
26+
resources:
27+
- bootstrapproviders
28+
sideEffects: None
29+
- admissionReviewVersions:
30+
- v1
31+
- v1beta1
32+
clientConfig:
33+
service:
34+
name: webhook-service
35+
namespace: system
36+
path: /mutate-operator-cluster-x-k8s-io-v1alpha1-controlplaneprovider
37+
failurePolicy: Fail
38+
matchPolicy: Equivalent
39+
name: vcontrolplaneprovider.kb.io
40+
rules:
41+
- apiGroups:
42+
- operator.cluster.x-k8s.io
43+
apiVersions:
44+
- v1alpha1
45+
operations:
46+
- CREATE
47+
- UPDATE
48+
resources:
49+
- controlplaneproviders
50+
sideEffects: None
51+
- admissionReviewVersions:
52+
- v1
53+
- v1beta1
54+
clientConfig:
55+
service:
56+
name: webhook-service
57+
namespace: system
58+
path: /mutate-operator-cluster-x-k8s-io-v1alpha1-coreprovider
59+
failurePolicy: Fail
60+
matchPolicy: Equivalent
61+
name: vcoreprovider.kb.io
62+
rules:
63+
- apiGroups:
64+
- operator.cluster.x-k8s.io
65+
apiVersions:
66+
- v1alpha1
67+
operations:
68+
- CREATE
69+
- UPDATE
70+
resources:
71+
- coreproviders
72+
sideEffects: None
73+
- admissionReviewVersions:
74+
- v1
75+
- v1beta1
76+
clientConfig:
77+
service:
78+
name: webhook-service
79+
namespace: system
80+
path: /mutate-operator-cluster-x-k8s-io-v1alpha1-infrastructureprovider
81+
failurePolicy: Fail
82+
matchPolicy: Equivalent
83+
name: vinfrastructureprovider.kb.io
84+
rules:
85+
- apiGroups:
86+
- operator.cluster.x-k8s.io
87+
apiVersions:
88+
- v1alpha1
89+
operations:
90+
- CREATE
91+
- UPDATE
92+
resources:
93+
- infrastructureproviders
94+
sideEffects: None
95+
---
96+
apiVersion: admissionregistration.k8s.io/v1
397
kind: ValidatingWebhookConfiguration
498
metadata:
599
name: validating-webhook-configuration
6100
webhooks:
7101
- admissionReviewVersions:
8102
- v1
9-
- v1alpha1
103+
- v1beta1
10104
clientConfig:
11105
service:
12106
name: webhook-service
13107
namespace: system
14108
path: /validate-operator-cluster-x-k8s-io-v1alpha1-bootstrapprovider
15109
failurePolicy: Fail
110+
matchPolicy: Equivalent
16111
name: vbootstrapprovider.kb.io
17112
rules:
18113
- apiGroups:
@@ -27,13 +122,14 @@ webhooks:
27122
sideEffects: None
28123
- admissionReviewVersions:
29124
- v1
30-
- v1alpha1
125+
- v1beta1
31126
clientConfig:
32127
service:
33128
name: webhook-service
34129
namespace: system
35130
path: /validate-operator-cluster-x-k8s-io-v1alpha1-controlplaneprovider
36131
failurePolicy: Fail
132+
matchPolicy: Equivalent
37133
name: vcontrolplaneprovider.kb.io
38134
rules:
39135
- apiGroups:
@@ -48,13 +144,14 @@ webhooks:
48144
sideEffects: None
49145
- admissionReviewVersions:
50146
- v1
51-
- v1alpha1
147+
- v1beta1
52148
clientConfig:
53149
service:
54150
name: webhook-service
55151
namespace: system
56152
path: /validate-operator-cluster-x-k8s-io-v1alpha1-coreprovider
57153
failurePolicy: Fail
154+
matchPolicy: Equivalent
58155
name: vcoreprovider.kb.io
59156
rules:
60157
- apiGroups:
@@ -69,13 +166,14 @@ webhooks:
69166
sideEffects: None
70167
- admissionReviewVersions:
71168
- v1
72-
- v1alpha1
169+
- v1beta1
73170
clientConfig:
74171
service:
75172
name: webhook-service
76173
namespace: system
77174
path: /validate-operator-cluster-x-k8s-io-v1alpha1-infrastructureprovider
78175
failurePolicy: Fail
176+
matchPolicy: Equivalent
79177
name: vinfrastructureprovider.kb.io
80178
rules:
81179
- apiGroups:

internal/controller/phases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (p *phaseReconciler) secretReader(ctx context.Context) (configclient.Reader
195195
// Fetch configuration variables from the secret. See API field docs for more info.
196196
if p.provider.GetSpec().SecretName != "" {
197197
secret := &corev1.Secret{}
198-
key := types.NamespacedName{Namespace: p.provider.GetNamespace(), Name: p.provider.GetSpec().SecretName}
198+
key := types.NamespacedName{Namespace: p.provider.GetSpec().SecretNamespace, Name: p.provider.GetSpec().SecretName}
199199

200200
if err := p.ctrlClient.Get(ctx, key, secret); err != nil {
201201
return nil, err

0 commit comments

Comments
 (0)