From 9444a67cbccbbe66be369f46f8d2ec46f1c61f56 Mon Sep 17 00:00:00 2001 From: Michael Shen Date: Tue, 13 Jun 2023 22:15:25 -0400 Subject: [PATCH 1/2] Fix kustomize syntax during conversion to patches This commit fixes the syntax error introduced in #3374 where pathcesStrategicMerge was replaced with patches, which now requires that every patch additionally have a "path" key when multiple patches are specified in a file. Signed-off-by: Michael Shen --- .../project/config/crd/kustomization.yaml | 4 +-- .../project/config/crd/kustomization.yaml | 4 +-- .../cronjob-tutorial/generate_cronjob.go | 4 +-- .../templates/config/crd/kustomization.go | 4 +-- pkg/plugins/golang/declarative/v1/api.go | 3 +- test/e2e/v4/generate_test.go | 6 ++++ .../config/crd/kustomization.yaml | 12 +++---- .../config/crd/kustomization.yaml | 36 +++++++++---------- .../config/crd/kustomization.yaml | 8 ++--- .../project-v4/config/crd/kustomization.yaml | 12 +++---- 10 files changed, 49 insertions(+), 44 deletions(-) diff --git a/docs/book/src/component-config-tutorial/testdata/project/config/crd/kustomization.yaml b/docs/book/src/component-config-tutorial/testdata/project/config/crd/kustomization.yaml index 22fff65b92c..97cb6432412 100644 --- a/docs/book/src/component-config-tutorial/testdata/project/config/crd/kustomization.yaml +++ b/docs/book/src/component-config-tutorial/testdata/project/config/crd/kustomization.yaml @@ -8,12 +8,12 @@ resources: patches: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD -#- patches/webhook_in_projectconfigs.yaml +#- path: patches/webhook_in_projectconfigs.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD -#- patches/cainjection_in_projectconfigs.yaml +#- path: patches/cainjection_in_projectconfigs.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/docs/book/src/cronjob-tutorial/testdata/project/config/crd/kustomization.yaml b/docs/book/src/cronjob-tutorial/testdata/project/config/crd/kustomization.yaml index ed16f6b985b..726852ee68b 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/config/crd/kustomization.yaml +++ b/docs/book/src/cronjob-tutorial/testdata/project/config/crd/kustomization.yaml @@ -8,12 +8,12 @@ resources: patches: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD -- patches/webhook_in_cronjobs.yaml +- path: patches/webhook_in_cronjobs.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD -- patches/cainjection_in_cronjobs.yaml +- path: patches/cainjection_in_cronjobs.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/hack/docs/internal/cronjob-tutorial/generate_cronjob.go b/hack/docs/internal/cronjob-tutorial/generate_cronjob.go index 9a404a6fc2a..3eb13ea54c3 100644 --- a/hack/docs/internal/cronjob-tutorial/generate_cronjob.go +++ b/hack/docs/internal/cronjob-tutorial/generate_cronjob.go @@ -581,12 +581,12 @@ func updateKustomization(sp *Sample) { // uncomment crd/kustomization err = pluginutil.UncommentCode( filepath.Join(sp.ctx.Dir, "config/crd/kustomization.yaml"), - `#- patches/webhook_in_cronjobs.yaml`, `#`) + `#- path: patches/webhook_in_cronjobs.yaml`, `#`) CheckError("fixing crd/kustomization", err) err = pluginutil.UncommentCode( filepath.Join(sp.ctx.Dir, "config/crd/kustomization.yaml"), - `#- patches/cainjection_in_cronjobs.yaml`, `#`) + `#- path: patches/cainjection_in_cronjobs.yaml`, `#`) CheckError("fixing crd/kustomization", err) } diff --git a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go index 0cdca88ad14..960ad2c5da3 100644 --- a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go +++ b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go @@ -68,9 +68,9 @@ func (f *Kustomization) GetMarkers() []machinery.Marker { const ( resourceCodeFragment = `- bases/%s_%s.yaml ` - webhookPatchCodeFragment = `#- patches/webhook_in_%s.yaml + webhookPatchCodeFragment = `#- path: patches/webhook_in_%s.yaml ` - caInjectionPatchCodeFragment = `#- patches/cainjection_in_%s.yaml + caInjectionPatchCodeFragment = `#- path: patches/cainjection_in_%s.yaml ` ) diff --git a/pkg/plugins/golang/declarative/v1/api.go b/pkg/plugins/golang/declarative/v1/api.go index ee70095da32..998f39eebc9 100644 --- a/pkg/plugins/golang/declarative/v1/api.go +++ b/pkg/plugins/golang/declarative/v1/api.go @@ -20,8 +20,6 @@ import ( "errors" "fmt" - goPluginV3 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3" - "sigs.k8s.io/kubebuilder/v3/pkg/config" "sigs.k8s.io/kubebuilder/v3/pkg/machinery" "sigs.k8s.io/kubebuilder/v3/pkg/model/resource" @@ -29,6 +27,7 @@ import ( "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util" "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/declarative/v1/scaffolds" goPluginV2 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v2" + goPluginV3 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3" ) const ( diff --git a/test/e2e/v4/generate_test.go b/test/e2e/v4/generate_test.go index fb2deba6240..d4fc718bc25 100644 --- a/test/e2e/v4/generate_test.go +++ b/test/e2e/v4/generate_test.go @@ -83,6 +83,12 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+` ExpectWithOffset(1, err).NotTo(HaveOccurred()) By("uncomment kustomization.yaml to enable webhook and ca injection") + ExpectWithOffset(1, pluginutil.UncommentCode( + filepath.Join(kbc.Dir, "config", "crd", "kustomization.yaml"), + fmt.Sprintf("#- path: patches/webhook_in_%s.yaml", kbc.Resources), "#")).To(Succeed()) + ExpectWithOffset(1, pluginutil.UncommentCode( + filepath.Join(kbc.Dir, "config", "crd", "kustomization.yaml"), + fmt.Sprintf("#- path: patches/cainjection_in_%s.yaml", kbc.Resources), "#")).To(Succeed()) ExpectWithOffset(1, pluginutil.UncommentCode( filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), "#- ../webhook", "#")).To(Succeed()) diff --git a/testdata/project-v4-declarative-v1/config/crd/kustomization.yaml b/testdata/project-v4-declarative-v1/config/crd/kustomization.yaml index bf4c93a811c..687526d8e7c 100644 --- a/testdata/project-v4-declarative-v1/config/crd/kustomization.yaml +++ b/testdata/project-v4-declarative-v1/config/crd/kustomization.yaml @@ -10,16 +10,16 @@ resources: patches: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD -#- patches/webhook_in_captains.yaml -#- patches/webhook_in_firstmates.yaml -#- patches/webhook_in_admirals.yaml +#- path: patches/webhook_in_captains.yaml +#- path: patches/webhook_in_firstmates.yaml +#- path: patches/webhook_in_admirals.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD -#- patches/cainjection_in_captains.yaml -#- patches/cainjection_in_firstmates.yaml -#- patches/cainjection_in_admirals.yaml +#- path: patches/cainjection_in_captains.yaml +#- path: patches/cainjection_in_firstmates.yaml +#- path: patches/cainjection_in_admirals.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/testdata/project-v4-multigroup/config/crd/kustomization.yaml b/testdata/project-v4-multigroup/config/crd/kustomization.yaml index 8c2e5c49499..633e725aa1a 100644 --- a/testdata/project-v4-multigroup/config/crd/kustomization.yaml +++ b/testdata/project-v4-multigroup/config/crd/kustomization.yaml @@ -17,28 +17,28 @@ resources: patches: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD -#- patches/webhook_in_captains.yaml -#- patches/webhook_in_frigates.yaml -#- patches/webhook_in_destroyers.yaml -#- patches/webhook_in_cruisers.yaml -#- patches/webhook_in_krakens.yaml -#- patches/webhook_in_leviathans.yaml -#- patches/webhook_in_healthcheckpolicies.yaml -#- patches/webhook_in_bars.yaml -#- patches/webhook_in_lakers.yaml +#- path: patches/webhook_in_captains.yaml +#- path: patches/webhook_in_frigates.yaml +#- path: patches/webhook_in_destroyers.yaml +#- path: patches/webhook_in_cruisers.yaml +#- path: patches/webhook_in_krakens.yaml +#- path: patches/webhook_in_leviathans.yaml +#- path: patches/webhook_in_healthcheckpolicies.yaml +#- path: patches/webhook_in_bars.yaml +#- path: patches/webhook_in_lakers.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD -#- patches/cainjection_in_captains.yaml -#- patches/cainjection_in_frigates.yaml -#- patches/cainjection_in_destroyers.yaml -#- patches/cainjection_in_cruisers.yaml -#- patches/cainjection_in_krakens.yaml -#- patches/cainjection_in_leviathans.yaml -#- patches/cainjection_in_healthcheckpolicies.yaml -#- patches/cainjection_in_bars.yaml -#- patches/cainjection_in_lakers.yaml +#- path: patches/cainjection_in_captains.yaml +#- path: patches/cainjection_in_frigates.yaml +#- path: patches/cainjection_in_destroyers.yaml +#- path: patches/cainjection_in_cruisers.yaml +#- path: patches/cainjection_in_krakens.yaml +#- path: patches/cainjection_in_leviathans.yaml +#- path: patches/cainjection_in_healthcheckpolicies.yaml +#- path: patches/cainjection_in_bars.yaml +#- path: patches/cainjection_in_lakers.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/testdata/project-v4-with-deploy-image/config/crd/kustomization.yaml b/testdata/project-v4-with-deploy-image/config/crd/kustomization.yaml index 4d4c5a9212d..1385006e680 100644 --- a/testdata/project-v4-with-deploy-image/config/crd/kustomization.yaml +++ b/testdata/project-v4-with-deploy-image/config/crd/kustomization.yaml @@ -9,14 +9,14 @@ resources: patches: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD -#- patches/webhook_in_memcacheds.yaml -#- patches/webhook_in_busyboxes.yaml +#- path: patches/webhook_in_memcacheds.yaml +#- path: patches/webhook_in_busyboxes.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD -#- patches/cainjection_in_memcacheds.yaml -#- patches/cainjection_in_busyboxes.yaml +#- path: patches/cainjection_in_memcacheds.yaml +#- path: patches/cainjection_in_busyboxes.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/testdata/project-v4/config/crd/kustomization.yaml b/testdata/project-v4/config/crd/kustomization.yaml index 75e0b8e4258..a67f99e5ea3 100644 --- a/testdata/project-v4/config/crd/kustomization.yaml +++ b/testdata/project-v4/config/crd/kustomization.yaml @@ -10,16 +10,16 @@ resources: patches: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD -#- patches/webhook_in_captains.yaml -#- patches/webhook_in_firstmates.yaml -#- patches/webhook_in_admirales.yaml +#- path: patches/webhook_in_captains.yaml +#- path: patches/webhook_in_firstmates.yaml +#- path: patches/webhook_in_admirales.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD -#- patches/cainjection_in_captains.yaml -#- patches/cainjection_in_firstmates.yaml -#- patches/cainjection_in_admirales.yaml +#- path: patches/cainjection_in_captains.yaml +#- path: patches/cainjection_in_firstmates.yaml +#- path: patches/cainjection_in_admirales.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. From ad518e7bb241af070e05010b2980592535503207 Mon Sep 17 00:00:00 2001 From: Jakub Warczarek Date: Wed, 28 Jun 2023 15:33:01 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20Add=20.vscode=20to=20autogenera?= =?UTF-8?q?ted=20.gitignore=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/component-config-tutorial/testdata/project/.gitignore | 1 + docs/book/src/cronjob-tutorial/testdata/project/.gitignore | 1 + pkg/plugins/golang/v2/scaffolds/internal/templates/gitignore.go | 1 + pkg/plugins/golang/v3/scaffolds/internal/templates/gitignore.go | 1 + pkg/plugins/golang/v4/scaffolds/internal/templates/gitignore.go | 1 + testdata/project-v2/.gitignore | 1 + testdata/project-v3/.gitignore | 1 + testdata/project-v4-declarative-v1/.gitignore | 1 + testdata/project-v4-with-deploy-image/.gitignore | 1 + testdata/project-v4-with-grafana/.gitignore | 1 + 10 files changed, 10 insertions(+) diff --git a/docs/book/src/component-config-tutorial/testdata/project/.gitignore b/docs/book/src/component-config-tutorial/testdata/project/.gitignore index 3827d421791..7f02333db7a 100644 --- a/docs/book/src/component-config-tutorial/testdata/project/.gitignore +++ b/docs/book/src/component-config-tutorial/testdata/project/.gitignore @@ -20,6 +20,7 @@ Dockerfile.cross # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/docs/book/src/cronjob-tutorial/testdata/project/.gitignore b/docs/book/src/cronjob-tutorial/testdata/project/.gitignore index 3827d421791..7f02333db7a 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/.gitignore +++ b/docs/book/src/cronjob-tutorial/testdata/project/.gitignore @@ -20,6 +20,7 @@ Dockerfile.cross # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/pkg/plugins/golang/v2/scaffolds/internal/templates/gitignore.go b/pkg/plugins/golang/v2/scaffolds/internal/templates/gitignore.go index a60f46d6760..b4a5c691167 100644 --- a/pkg/plugins/golang/v2/scaffolds/internal/templates/gitignore.go +++ b/pkg/plugins/golang/v2/scaffolds/internal/templates/gitignore.go @@ -59,6 +59,7 @@ bin # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/pkg/plugins/golang/v3/scaffolds/internal/templates/gitignore.go b/pkg/plugins/golang/v3/scaffolds/internal/templates/gitignore.go index 8b194d955f6..f79f6a32d65 100644 --- a/pkg/plugins/golang/v3/scaffolds/internal/templates/gitignore.go +++ b/pkg/plugins/golang/v3/scaffolds/internal/templates/gitignore.go @@ -61,6 +61,7 @@ Dockerfile.cross # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/gitignore.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/gitignore.go index 0e156e463e1..b88cf76c024 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/gitignore.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/gitignore.go @@ -60,6 +60,7 @@ Dockerfile.cross # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/testdata/project-v2/.gitignore b/testdata/project-v2/.gitignore index d97ffc5159b..4f592d7553b 100644 --- a/testdata/project-v2/.gitignore +++ b/testdata/project-v2/.gitignore @@ -19,6 +19,7 @@ bin # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/testdata/project-v3/.gitignore b/testdata/project-v3/.gitignore index e917e5cefe5..c1c593e67e1 100644 --- a/testdata/project-v3/.gitignore +++ b/testdata/project-v3/.gitignore @@ -21,6 +21,7 @@ Dockerfile.cross # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/testdata/project-v4-declarative-v1/.gitignore b/testdata/project-v4-declarative-v1/.gitignore index 3827d421791..7f02333db7a 100644 --- a/testdata/project-v4-declarative-v1/.gitignore +++ b/testdata/project-v4-declarative-v1/.gitignore @@ -20,6 +20,7 @@ Dockerfile.cross # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/testdata/project-v4-with-deploy-image/.gitignore b/testdata/project-v4-with-deploy-image/.gitignore index 3827d421791..7f02333db7a 100644 --- a/testdata/project-v4-with-deploy-image/.gitignore +++ b/testdata/project-v4-with-deploy-image/.gitignore @@ -20,6 +20,7 @@ Dockerfile.cross # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~ diff --git a/testdata/project-v4-with-grafana/.gitignore b/testdata/project-v4-with-grafana/.gitignore index 3827d421791..7f02333db7a 100644 --- a/testdata/project-v4-with-grafana/.gitignore +++ b/testdata/project-v4-with-grafana/.gitignore @@ -20,6 +20,7 @@ Dockerfile.cross # editor and IDE paraphernalia .idea +.vscode *.swp *.swo *~