Skip to content

Commit 8d859ca

Browse files
authored
Merge pull request #3580 from dragon-flyings/fixPatchYaml
🐛 (kustomize/v2,go/v4): fix kustomization yaml's webhooks patches file names for multgroup layouts
2 parents a8ad43f + 0384064 commit 8d859ca

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var (
3131
// Kustomization scaffolds a file that defines the kustomization scheme for the crd folder
3232
type Kustomization struct {
3333
machinery.TemplateMixin
34+
machinery.MultiGroupMixin
3435
machinery.ResourceMixin
3536
}
3637

@@ -82,13 +83,17 @@ func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
8283
res := make([]string, 0)
8384
res = append(res, fmt.Sprintf(resourceCodeFragment, f.Resource.QualifiedGroup(), f.Resource.Plural))
8485

86+
suffix := f.Resource.Plural
87+
if f.MultiGroup {
88+
suffix = f.Resource.Group + "_" + f.Resource.Plural
89+
}
8590
// Generate resource code fragments
8691
webhookPatch := make([]string, 0)
87-
webhookPatch = append(webhookPatch, fmt.Sprintf(webhookPatchCodeFragment, f.Resource.Plural))
92+
webhookPatch = append(webhookPatch, fmt.Sprintf(webhookPatchCodeFragment, suffix))
8893

8994
// Generate resource code fragments
9095
caInjectionPatch := make([]string, 0)
91-
caInjectionPatch = append(caInjectionPatch, fmt.Sprintf(caInjectionPatchCodeFragment, f.Resource.Plural))
96+
caInjectionPatch = append(caInjectionPatch, fmt.Sprintf(caInjectionPatchCodeFragment, suffix))
9297

9398
// Only store code fragments in the map if the slices are non-empty
9499
if len(res) != 0 {

pkg/plugins/golang/v2/scaffolds/internal/templates/config/crd/patches/enablecainjection_patch.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ var _ machinery.Template = &EnableCAInjectionPatch{}
2727
// EnableCAInjectionPatch scaffolds a file that defines the patch that injects CA into the CRD
2828
type EnableCAInjectionPatch struct {
2929
machinery.TemplateMixin
30+
machinery.MultiGroupMixin
3031
machinery.ResourceMixin
3132
}
3233

3334
// SetTemplateDefaults implements file.Template
3435
func (f *EnableCAInjectionPatch) SetTemplateDefaults() error {
3536
if f.Path == "" {
36-
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[plural].yaml")
37+
if f.MultiGroup {
38+
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[group]_%[plural].yaml")
39+
} else {
40+
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[plural].yaml")
41+
}
3742
}
3843
f.Path = f.Resource.Replacer().Replace(f.Path)
3944

testdata/project-v4-multigroup/config/crd/kustomization.yaml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,34 @@ resources:
1919
patches:
2020
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
2121
# patches here are for enabling the conversion webhook for each CRD
22-
#- path: patches/webhook_in_captains.yaml
23-
#- path: patches/webhook_in_frigates.yaml
24-
#- path: patches/webhook_in_destroyers.yaml
25-
#- path: patches/webhook_in_cruisers.yaml
26-
#- path: patches/webhook_in_krakens.yaml
27-
#- path: patches/webhook_in_leviathans.yaml
28-
#- path: patches/webhook_in_healthcheckpolicies.yaml
29-
#- path: patches/webhook_in_bars.yaml
30-
#- path: patches/webhook_in_lakers.yaml
31-
#- path: patches/webhook_in_memcacheds.yaml
32-
#- path: patches/webhook_in_busyboxes.yaml
22+
#- path: patches/webhook_in_crew_captains.yaml
23+
#- path: patches/webhook_in_ship_frigates.yaml
24+
#- path: patches/webhook_in_ship_destroyers.yaml
25+
#- path: patches/webhook_in_ship_cruisers.yaml
26+
#- path: patches/webhook_in_sea-creatures_krakens.yaml
27+
#- path: patches/webhook_in_sea-creatures_leviathans.yaml
28+
#- path: patches/webhook_in_foo.policy_healthcheckpolicies.yaml
29+
#- path: patches/webhook_in_foo_bars.yaml
30+
#- path: patches/webhook_in_fiz_bars.yaml
31+
#- path: patches/webhook_in__lakers.yaml
32+
#- path: patches/webhook_in_example.com_memcacheds.yaml
33+
#- path: patches/webhook_in_example.com_busyboxes.yaml
3334
#+kubebuilder:scaffold:crdkustomizewebhookpatch
3435

3536
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
3637
# patches here are for enabling the CA injection for each CRD
37-
#- path: patches/cainjection_in_captains.yaml
38-
#- path: patches/cainjection_in_frigates.yaml
39-
#- path: patches/cainjection_in_destroyers.yaml
40-
#- path: patches/cainjection_in_cruisers.yaml
41-
#- path: patches/cainjection_in_krakens.yaml
42-
#- path: patches/cainjection_in_leviathans.yaml
43-
#- path: patches/cainjection_in_healthcheckpolicies.yaml
44-
#- path: patches/cainjection_in_bars.yaml
45-
#- path: patches/cainjection_in_lakers.yaml
46-
#- path: patches/cainjection_in_memcacheds.yaml
47-
#- path: patches/cainjection_in_busyboxes.yaml
38+
#- path: patches/cainjection_in_crew_captains.yaml
39+
#- path: patches/cainjection_in_ship_frigates.yaml
40+
#- path: patches/cainjection_in_ship_destroyers.yaml
41+
#- path: patches/cainjection_in_ship_cruisers.yaml
42+
#- path: patches/cainjection_in_sea-creatures_krakens.yaml
43+
#- path: patches/cainjection_in_sea-creatures_leviathans.yaml
44+
#- path: patches/cainjection_in_foo.policy_healthcheckpolicies.yaml
45+
#- path: patches/cainjection_in_foo_bars.yaml
46+
#- path: patches/cainjection_in_fiz_bars.yaml
47+
#- path: patches/cainjection_in__lakers.yaml
48+
#- path: patches/cainjection_in_example.com_memcacheds.yaml
49+
#- path: patches/cainjection_in_example.com_busyboxes.yaml
4850
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
4951

5052
# the following config is for teaching kustomize how to do kustomization for CRDs.

0 commit comments

Comments
 (0)