Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix resource path generation for resources without a specified group #3837

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
res = append(res, fmt.Sprintf(resourceCodeFragment, f.Resource.QualifiedGroup(), f.Resource.Plural))

suffix := f.Resource.Plural
if f.MultiGroup {
if f.MultiGroup && f.Resource.Group != "" {
suffix = f.Resource.Group + "_" + f.Resource.Plural
}
// Generate resource code fragments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type EnableCAInjectionPatch struct {
// SetTemplateDefaults implements file.Template
func (f *EnableCAInjectionPatch) SetTemplateDefaults() error {
if f.Path == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would it be more readable to trim nested if-else statement like:

Suggested change
if f.Path == "" {
if f.Path == "" {
pathTemplate := "config/crd/patches/cainjection_in_%[plural].yaml"
if f.MultiGroup && f.Resource.Group != "" {
pathTemplate = "config/crd/patches/cainjection_in_%[group]_%[plural].yaml"
}
f.Path = filepath.Join(pathTemplate)
}

if f.MultiGroup {
if f.MultiGroup && f.Resource.Group != "" {
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[group]_%[plural].yaml")
} else {
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[plural].yaml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type EnableWebhookPatch struct {
// SetTemplateDefaults implements file.Template
func (f *EnableWebhookPatch) SetTemplateDefaults() error {
if f.Path == "" {
if f.MultiGroup {
if f.MultiGroup && f.Resource.Group != "" {
f.Path = filepath.Join("config", "crd", "patches", "webhook_in_%[group]_%[plural].yaml")
} else {
f.Path = filepath.Join("config", "crd", "patches", "webhook_in_%[plural].yaml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type CRDEditorRole struct {
// SetTemplateDefaults implements file.Template
func (f *CRDEditorRole) SetTemplateDefaults() error {
if f.Path == "" {
if f.MultiGroup {
if f.MultiGroup && f.Resource.Group != "" {
f.Path = filepath.Join("config", "rbac", "%[group]_%[kind]_editor_role.yaml")
} else {
f.Path = filepath.Join("config", "rbac", "%[kind]_editor_role.yaml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type CRDViewerRole struct {
// SetTemplateDefaults implements file.Template
func (f *CRDViewerRole) SetTemplateDefaults() error {
if f.Path == "" {
if f.MultiGroup {
if f.MultiGroup && f.Resource.Group != "" {
f.Path = filepath.Join("config", "rbac", "%[group]_%[kind]_viewer_role.yaml")
} else {
f.Path = filepath.Join("config", "rbac", "%[kind]_viewer_role.yaml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ type CRDSample struct {
// SetTemplateDefaults implements file.Template
func (f *CRDSample) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
if f.Resource.Group != "" {
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
} else {
f.Path = filepath.Join("config", "samples", "%[version]_%[kind].yaml")
}
}
f.Path = f.Resource.Replacer().Replace(f.Path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ const samplesCodeFragment = `- %s
// makeCRFileName returns a Custom Resource example file name in the same format
// as kubebuilder's CreateAPI plugin for a gvk.
func (f Kustomization) makeCRFileName() string {
return f.Resource.Replacer().Replace("%[group]_%[version]_%[kind].yaml")
if f.Resource.Group != "" {
return f.Resource.Replacer().Replace("%[group]_%[version]_%[kind].yaml")
}
return f.Resource.Replacer().Replace("%[version]_%[kind].yaml")

}

// GetCodeFragments implements file.Inserter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ type CRDSample struct {
// SetTemplateDefaults implements file.Template
func (f *CRDSample) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
if f.Resource.Group != "" {
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
} else {
f.Path = filepath.Join("config", "samples", "%[version]_%[kind].yaml")
}
}
f.Path = f.Resource.Replacer().Replace(f.Path)
log.Println(f.Path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ patches:
#- path: patches/webhook_in_foo.policy_healthcheckpolicies.yaml
#- path: patches/webhook_in_foo_bars.yaml
#- path: patches/webhook_in_fiz_bars.yaml
#- path: patches/webhook_in__lakers.yaml
#- path: patches/webhook_in_lakers.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -40,7 +40,7 @@ patches:
#- path: patches/cainjection_in_foo.policy_healthcheckpolicies.yaml
#- path: patches/cainjection_in_foo_bars.yaml
#- path: patches/cainjection_in_fiz_bars.yaml
#- path: patches/cainjection_in__lakers.yaml
#- path: patches/cainjection_in_lakers.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ resources:
- foo.policy_v1_healthcheckpolicy.yaml
- foo_v1_bar.yaml
- fiz_v1_bar.yaml
- _v1_lakers.yaml
- v1_lakers.yaml
#+kubebuilder:scaffold:manifestskustomizesamples
4 changes: 2 additions & 2 deletions testdata/project-v4-multigroup/config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ patches:
#- path: patches/webhook_in_foo.policy_healthcheckpolicies.yaml
#- path: patches/webhook_in_foo_bars.yaml
#- path: patches/webhook_in_fiz_bars.yaml
#- path: patches/webhook_in__lakers.yaml
#- path: patches/webhook_in_lakers.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -40,7 +40,7 @@ patches:
#- path: patches/cainjection_in_foo.policy_healthcheckpolicies.yaml
#- path: patches/cainjection_in_foo_bars.yaml
#- path: patches/cainjection_in_fiz_bars.yaml
#- path: patches/cainjection_in__lakers.yaml
#- path: patches/cainjection_in_lakers.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ resources:
- foo.policy_v1_healthcheckpolicy.yaml
- foo_v1_bar.yaml
- fiz_v1_bar.yaml
- _v1_lakers.yaml
- v1_lakers.yaml
#+kubebuilder:scaffold:manifestskustomizesamples
Loading