Skip to content

Commit

Permalink
Merge pull request #3837 from camilamacedo86/fix-path-core-types
Browse files Browse the repository at this point in the history
🐛 fix resource path generation for resources without a specified group
  • Loading branch information
k8s-ci-robot authored Apr 1, 2024
2 parents f3159c6 + d93a1ca commit 777f588
Show file tree
Hide file tree
Showing 22 changed files with 26 additions and 14 deletions.
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 == "" {
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 777f588

Please sign in to comment.