Skip to content

Commit

Permalink
Fix resource path when group is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Mar 31, 2024
1 parent cdc9c48 commit a68b6ea
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ func (f *Kustomization) GetCodeFragments() machinery.CodeFragmentsMap {
res = append(res, fmt.Sprintf(resourceCodeFragment, f.Resource.QualifiedGroup(), f.Resource.Plural))

suffix := f.Resource.Plural

Check failure on line 87 in pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/kustomization.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to suffix (ineffassign)
if f.MultiGroup {
if f.MultiGroup && f.Resource.Group != "" {
suffix = f.Resource.Group + "_" + f.Resource.Plural
} else {
suffix = f.Resource.Plural
}
// Generate resource code fragments
webhookPatch := make([]string, 0)
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 == "" {
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

0 comments on commit a68b6ea

Please sign in to comment.