Skip to content

Commit 327fc52

Browse files
author
Mengqi Yu
committed
✨ kustomize restricts about the scope of var definition
We move var definition one level up to work around this restriction.
1 parent 450508e commit 327fc52

31 files changed

+261
-262
lines changed

docs/book/src/cronjob-tutorial/testdata/project/config/certmanager/certificate.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ metadata:
1414
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
1515
namespace: system
1616
spec:
17-
# $(SERVICENAME) and $(NAMESPACE) will be substituted by kustomize
18-
commonName: $(SERVICENAME).$(NAMESPACE).svc
17+
# $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize
18+
commonName: $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc
1919
dnsNames:
20-
- $(SERVICENAME).$(NAMESPACE).svc.cluster.local
20+
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local
2121
issuerRef:
2222
kind: Issuer
2323
name: selfsigned-issuer
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
resources:
22
- certificate.yaml
33

4-
vars:
5-
- name: CERTIFICATENAME
6-
objref:
7-
kind: Certificate
8-
group: certmanager.k8s.io
9-
version: v1alpha1
10-
name: serving-cert # this name should match the one in certificate.yaml
11-
124
configurations:
135
- kustomizeconfig.yaml

docs/book/src/cronjob-tutorial/testdata/project/config/crd/kustomization.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ resources:
66
# +kubebuilder:scaffold:kustomizeresource
77

88
patches:
9+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
910
# patches here are for enabling the conversion webhook for each CRD
1011
#- patches/webhook_in_cronjobs.yaml
1112
# +kubebuilder:scaffold:kustomizepatch
1213

14+
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
15+
# patches here are for enabling the CA injection for each CRD
16+
#- patches/cainjection_in_cronjobs.yaml
17+
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
18+
1319
# the following config is for teaching kustomize how to do kustomization for CRDs.
1420
configurations:
1521
- kustomizeconfig.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: cronjobs.batch.tutorial.kubebuilder.io

docs/book/src/cronjob-tutorial/testdata/project/config/crd/patches/webhook_in_cronjob.yaml docs/book/src/cronjob-tutorial/testdata/project/config/crd/patches/webhook_in_cronjobs.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
certmanager.k8s.io/inject-ca-from: $(NAMESPACE)/$(CERTIFICATENAME)
6+
certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
77
name: cronjobs.batch.tutorial.kubebuilder.io
88
spec:
99
conversion:
@@ -13,6 +13,6 @@ spec:
1313
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
1414
caBundle: XG4=
1515
service:
16-
namespace: $(NAMESPACE)
16+
namespace: $(CERTIFICATE_NAMESPACE)
1717
name: webhook-service
1818
path: /convert-cronjob

docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml

+36-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bases:
1818
- ../manager
1919
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
2020
- ../webhook
21-
# [CERTMANAGER] To enable cert-manager, uncomment next line. 'WEBHOOK' components are required.
21+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
2222
- ../certmanager
2323

2424
patches:
@@ -41,3 +41,38 @@ patches:
4141
# Uncomment 'CAINJECTION' in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
4242
# 'CERTMANAGER' needs to be enabled to use ca injection
4343
- webhookcainjection_patch.yaml
44+
45+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
46+
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
47+
# 'CERTMANAGER' needs to be enabled to use ca injection
48+
#- webhookcainjection_patch.yaml
49+
50+
# the following config is for teaching kustomize how to do var substitution
51+
vars:
52+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
53+
#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
54+
# objref:
55+
# kind: Certificate
56+
# group: certmanager.k8s.io
57+
# version: v1alpha1
58+
# name: serving-cert # this name should match the one in certificate.yaml
59+
# fieldref:
60+
# fieldpath: metadata.namespace
61+
#- name: CERTIFICATE_NAME
62+
# objref:
63+
# kind: Certificate
64+
# group: certmanager.k8s.io
65+
# version: v1alpha1
66+
# name: serving-cert # this name should match the one in certificate.yaml
67+
#- name: SERVICE_NAMESPACE # namespace of the service
68+
# objref:
69+
# kind: Service
70+
# version: v1
71+
# name: webhook-service
72+
# fieldref:
73+
# fieldpath: metadata.namespace
74+
#- name: SERVICE_NAME
75+
# objref:
76+
# kind: Service
77+
# version: v1
78+
# name: webhook-service
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# This patch add annotation to admission webhook config and
2-
# the variables $(NAMESPACE) and $(CERTIFICATENAME) will be substituted by kustomize.
2+
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
33
apiVersion: admissionregistration.k8s.io/v1beta1
44
kind: MutatingWebhookConfiguration
55
metadata:
66
name: mutating-webhook-configuration
77
annotations:
8-
certmanager.k8s.io/inject-ca-from: $(NAMESPACE)/$(CERTIFICATENAME)
8+
certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
99
---
1010
apiVersion: admissionregistration.k8s.io/v1beta1
1111
kind: ValidatingWebhookConfiguration
1212
metadata:
1313
name: validating-webhook-configuration
1414
annotations:
15-
certmanager.k8s.io/inject-ca-from: $(NAMESPACE)/$(CERTIFICATENAME)
15+
certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)

go.mod

+7-18
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,19 @@ module sigs.k8s.io/kubebuilder
33
go 1.12
44

55
require (
6-
github.com/go-logr/logr v0.1.0 // indirect
7-
github.com/go-logr/zapr v0.1.1 // indirect
8-
github.com/gobuffalo/envy v1.6.15 // indirect
96
github.com/gobuffalo/flect v0.1.5
10-
github.com/imdario/mergo v0.3.7 // indirect
7+
github.com/golang/protobuf v1.3.1 // indirect
118
github.com/inconshreveable/mousetrap v1.0.0 // indirect
9+
github.com/kr/pretty v0.1.0 // indirect
1210
github.com/onsi/ginkgo v1.8.0
1311
github.com/onsi/gomega v1.5.0
14-
github.com/prometheus/client_golang v1.0.0 // indirect
15-
github.com/robfig/cron v1.2.0 // indirect
16-
github.com/rogpeppe/go-internal v1.2.2 // indirect
1712
github.com/spf13/afero v1.2.2
1813
github.com/spf13/cobra v0.0.3
1914
github.com/spf13/pflag v1.0.3
20-
go.uber.org/atomic v1.4.0 // indirect
21-
go.uber.org/multierr v1.1.0 // indirect
22-
go.uber.org/zap v1.10.0 // indirect
23-
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
24-
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
25-
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c
15+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
16+
golang.org/x/sys v0.0.0-20190621203818-d432491b9138 // indirect
17+
golang.org/x/text v0.3.2 // indirect
18+
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59
19+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
2620
gopkg.in/yaml.v2 v2.2.2
27-
k8s.io/api v0.0.0-20190627205229-acea843d18eb // indirect
28-
k8s.io/apimachinery v0.0.0-20190628045107-49e757626700 // indirect
29-
k8s.io/client-go v11.0.0+incompatible // indirect
30-
k8s.io/utils v0.0.0-20190607212802-c55fbcfc754a // indirect
31-
sigs.k8s.io/controller-runtime v0.1.12 // indirect
3221
)

0 commit comments

Comments
 (0)