Skip to content

Commit 777f588

Browse files
authored
Merge pull request #3837 from camilamacedo86/fix-path-core-types
🐛 fix resource path generation for resources without a specified group
2 parents f3159c6 + d93a1ca commit 777f588

File tree

22 files changed

+26
-14
lines changed

22 files changed

+26
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
8585
res = append(res, fmt.Sprintf(resourceCodeFragment, f.Resource.QualifiedGroup(), f.Resource.Plural))
8686

8787
suffix := f.Resource.Plural
88-
if f.MultiGroup {
88+
if f.MultiGroup && f.Resource.Group != "" {
8989
suffix = f.Resource.Group + "_" + f.Resource.Plural
9090
}
9191
// Generate resource code fragments

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type EnableCAInjectionPatch struct {
3434
// SetTemplateDefaults implements file.Template
3535
func (f *EnableCAInjectionPatch) SetTemplateDefaults() error {
3636
if f.Path == "" {
37-
if f.MultiGroup {
37+
if f.MultiGroup && f.Resource.Group != "" {
3838
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[group]_%[plural].yaml")
3939
} else {
4040
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[plural].yaml")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type EnableWebhookPatch struct {
3434
// SetTemplateDefaults implements file.Template
3535
func (f *EnableWebhookPatch) SetTemplateDefaults() error {
3636
if f.Path == "" {
37-
if f.MultiGroup {
37+
if f.MultiGroup && f.Resource.Group != "" {
3838
f.Path = filepath.Join("config", "crd", "patches", "webhook_in_%[group]_%[plural].yaml")
3939
} else {
4040
f.Path = filepath.Join("config", "crd", "patches", "webhook_in_%[plural].yaml")

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/crd_editor_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type CRDEditorRole struct {
3535
// SetTemplateDefaults implements file.Template
3636
func (f *CRDEditorRole) SetTemplateDefaults() error {
3737
if f.Path == "" {
38-
if f.MultiGroup {
38+
if f.MultiGroup && f.Resource.Group != "" {
3939
f.Path = filepath.Join("config", "rbac", "%[group]_%[kind]_editor_role.yaml")
4040
} else {
4141
f.Path = filepath.Join("config", "rbac", "%[kind]_editor_role.yaml")

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/crd_viewer_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type CRDViewerRole struct {
3535
// SetTemplateDefaults implements file.Template
3636
func (f *CRDViewerRole) SetTemplateDefaults() error {
3737
if f.Path == "" {
38-
if f.MultiGroup {
38+
if f.MultiGroup && f.Resource.Group != "" {
3939
f.Path = filepath.Join("config", "rbac", "%[group]_%[kind]_viewer_role.yaml")
4040
} else {
4141
f.Path = filepath.Join("config", "rbac", "%[kind]_viewer_role.yaml")

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/samples/crd_sample.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ type CRDSample struct {
3636
// SetTemplateDefaults implements file.Template
3737
func (f *CRDSample) SetTemplateDefaults() error {
3838
if f.Path == "" {
39-
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
39+
if f.Resource.Group != "" {
40+
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
41+
} else {
42+
f.Path = filepath.Join("config", "samples", "%[version]_%[kind].yaml")
43+
}
4044
}
4145
f.Path = f.Resource.Replacer().Replace(f.Path)
4246

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ const samplesCodeFragment = `- %s
5959
// makeCRFileName returns a Custom Resource example file name in the same format
6060
// as kubebuilder's CreateAPI plugin for a gvk.
6161
func (f Kustomization) makeCRFileName() string {
62-
return f.Resource.Replacer().Replace("%[group]_%[version]_%[kind].yaml")
62+
if f.Resource.Group != "" {
63+
return f.Resource.Replacer().Replace("%[group]_%[version]_%[kind].yaml")
64+
}
65+
return f.Resource.Replacer().Replace("%[version]_%[kind].yaml")
66+
6367
}
6468

6569
// GetCodeFragments implements file.Inserter

pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/config/samples/crd_sample.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ type CRDSample struct {
3535
// SetTemplateDefaults implements file.Template
3636
func (f *CRDSample) SetTemplateDefaults() error {
3737
if f.Path == "" {
38-
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
38+
if f.Resource.Group != "" {
39+
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
40+
} else {
41+
f.Path = filepath.Join("config", "samples", "%[version]_%[kind].yaml")
42+
}
3943
}
4044
f.Path = f.Resource.Replacer().Replace(f.Path)
4145
log.Println(f.Path)

testdata/project-v4-multigroup-with-deploy-image/config/crd/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ patches:
2626
#- path: patches/webhook_in_foo.policy_healthcheckpolicies.yaml
2727
#- path: patches/webhook_in_foo_bars.yaml
2828
#- path: patches/webhook_in_fiz_bars.yaml
29-
#- path: patches/webhook_in__lakers.yaml
29+
#- path: patches/webhook_in_lakers.yaml
3030
#+kubebuilder:scaffold:crdkustomizewebhookpatch
3131

3232
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
@@ -40,7 +40,7 @@ patches:
4040
#- path: patches/cainjection_in_foo.policy_healthcheckpolicies.yaml
4141
#- path: patches/cainjection_in_foo_bars.yaml
4242
#- path: patches/cainjection_in_fiz_bars.yaml
43-
#- path: patches/cainjection_in__lakers.yaml
43+
#- path: patches/cainjection_in_lakers.yaml
4444
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
4545

4646
# [WEBHOOK] To enable webhook, uncomment the following section

0 commit comments

Comments
 (0)