Skip to content

Commit 8c6db5d

Browse files
authored
Merge pull request kubernetes-sigs#1726 from shiftstack/kustomize
🌱 Replace kustomize vars with replacements
2 parents ca07cfc + 661c0ff commit 8c6db5d

10 files changed

+121
-69
lines changed

config/certmanager/certificate.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ metadata:
1414
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
1515
namespace: system
1616
spec:
17-
# $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize
17+
# SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize
1818
dnsNames:
19-
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc
20-
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local
19+
- SERVICE_NAME.SERVICE_NAMESPACE.svc
20+
- SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local
2121
issuerRef:
2222
kind: Issuer
2323
name: selfsigned-issuer
24-
secretName: $(SERVICE_NAME)-cert # this secret will not be prefixed, since it's not managed by kustomize
24+
secretName: SERVICE_NAME-cert # this secret will not be prefixed, since it's not managed by kustomize

config/crd/kustomization.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ patches:
2020
- path: patches/webhook_in_openstackclustertemplates.yaml
2121
# +kubebuilder:scaffold:crdkustomizewebhookpatch
2222

23-
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
24-
# patches here are for enabling the CA injection for each CRD
25-
- path: patches/cainjection_in_openstackclusters.yaml
26-
- path: patches/cainjection_in_openstackmachines.yaml
27-
- path: patches/cainjection_in_openstackmachinetemplates.yaml
28-
- path: patches/cainjection_in_openstackclustertemplates.yaml
29-
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
30-
3123
# the following config is for teaching kustomize how to do kustomization for CRDs.
3224
configurations:
3325
- kustomizeconfig.yaml

config/crd/patches/cainjection_in_openstackclusters.yaml

-8
This file was deleted.

config/crd/patches/cainjection_in_openstackclustertemplates.yaml

-8
This file was deleted.

config/crd/patches/cainjection_in_openstackmachines.yaml

-8
This file was deleted.

config/crd/patches/cainjection_in_openstackmachinetemplates.yaml

-8
This file was deleted.

config/default/kustomization.yaml

+115-13
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,135 @@ patches:
2020
# Enable webhook.
2121
- path: manager_webhook_patch.yaml
2222

23-
vars:
24-
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
25-
objref:
23+
replacements:
24+
- source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs
2625
kind: Certificate
2726
group: cert-manager.io
2827
version: v1
2928
name: serving-cert # this name should match the one in certificate.yaml
30-
fieldref:
31-
fieldpath: metadata.namespace
32-
- name: CERTIFICATE_NAME
33-
objref:
29+
fieldPath: .metadata.namespace # namespace of the certificate CR
30+
targets:
31+
- select:
32+
kind: ValidatingWebhookConfiguration
33+
fieldPaths:
34+
- .metadata.annotations.[cert-manager.io/inject-ca-from]
35+
options:
36+
delimiter: '/'
37+
index: 0
38+
create: true
39+
- select:
40+
kind: MutatingWebhookConfiguration
41+
fieldPaths:
42+
- .metadata.annotations.[cert-manager.io/inject-ca-from]
43+
options:
44+
delimiter: '/'
45+
index: 0
46+
create: true
47+
- select:
48+
kind: CustomResourceDefinition
49+
fieldPaths:
50+
- .metadata.annotations.[cert-manager.io/inject-ca-from]
51+
options:
52+
delimiter: '/'
53+
index: 0
54+
create: true
55+
- source:
3456
kind: Certificate
3557
group: cert-manager.io
3658
version: v1
3759
name: serving-cert # this name should match the one in certificate.yaml
38-
- name: SERVICE_NAMESPACE # namespace of the service
39-
objref:
60+
fieldPath: .metadata.name
61+
targets:
62+
- select:
63+
kind: ValidatingWebhookConfiguration
64+
fieldPaths:
65+
- .metadata.annotations.[cert-manager.io/inject-ca-from]
66+
options:
67+
delimiter: '/'
68+
index: 1
69+
create: true
70+
- select:
71+
kind: MutatingWebhookConfiguration
72+
fieldPaths:
73+
- .metadata.annotations.[cert-manager.io/inject-ca-from]
74+
options:
75+
delimiter: '/'
76+
index: 1
77+
create: true
78+
- select:
79+
kind: CustomResourceDefinition
80+
fieldPaths:
81+
- .metadata.annotations.[cert-manager.io/inject-ca-from]
82+
options:
83+
delimiter: '/'
84+
index: 1
85+
create: true
86+
- source: # Add cert-manager annotation to the webhook Service
4087
kind: Service
4188
version: v1
4289
name: webhook-service
43-
fieldref:
44-
fieldpath: metadata.namespace
45-
- name: SERVICE_NAME
46-
objref:
90+
fieldPath: .metadata.name # namespace of the service
91+
targets:
92+
- select:
93+
kind: Certificate
94+
group: cert-manager.io
95+
version: v1
96+
name: serving-cert
97+
fieldPaths:
98+
- .spec.dnsNames.0
99+
- .spec.dnsNames.1
100+
options:
101+
delimiter: '.'
102+
index: 0
103+
create: false
104+
- source:
47105
kind: Service
48106
version: v1
49107
name: webhook-service
108+
fieldPath: .metadata.namespace # namespace of the service
109+
targets:
110+
- select:
111+
kind: Certificate
112+
group: cert-manager.io
113+
version: v1
114+
name: serving-cert
115+
fieldPaths:
116+
- .spec.dnsNames.0
117+
- .spec.dnsNames.1
118+
options:
119+
delimiter: '.'
120+
index: 1
121+
create: false
122+
- source: # Prefix the certificate secret name with the name of service
123+
kind: Service
124+
version: v1
125+
name: webhook-service
126+
fieldPath: .metadata.name # namespace of the service
127+
targets:
128+
- select:
129+
kind: Certificate
130+
group: cert-manager.io
131+
version: v1
132+
fieldPaths:
133+
- .spec.secretName
134+
options:
135+
delimiter: '-'
136+
index: 0
137+
create: false
138+
- source: # Certificate secret name
139+
kind: Certificate
140+
group: cert-manager.io
141+
version: v1
142+
name: serving-cert
143+
fieldPath: .spec.secretName
144+
targets:
145+
- select:
146+
kind: Deployment
147+
group: apps
148+
version: v1
149+
name: controller-manager
150+
fieldPaths:
151+
- .spec.template.spec.volumes.[name=cert].secret.secretName
50152

51153
configurations:
52154
- kustomizeconfig.yaml

config/default/manager_webhook_patch.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ spec:
2020
- name: cert
2121
secret:
2222
defaultMode: 420
23-
secretName: $(SERVICE_NAME)-cert
23+
# kustomize will populate this from the Certificate secretName
24+
secretName: CERT_SECRET_NAME

config/webhook/cainjection_patch.yaml

-3
This file was deleted.

config/webhook/kustomization.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,3 @@ resources:
44

55
configurations:
66
- kustomizeconfig.yaml
7-
8-
patches:
9-
# Inject certificate in the webhook definition.
10-
- target:
11-
group: admissionregistration.k8s.io
12-
version: v1
13-
name: mutating-webhook-configuration|validating-webhook-configuration
14-
path: cainjection_patch.yaml

0 commit comments

Comments
 (0)