Skip to content

Commit 0149acd

Browse files
authored
Merge pull request #1777 from Adirio/templates-directories
🌱Template folder cleanup
2 parents a3e0baf + 3092500 commit 0149acd

File tree

88 files changed

+308
-303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+308
-303
lines changed

pkg/plugin/v2/scaffolds/api.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ import (
2525
"sigs.k8s.io/kubebuilder/pkg/plugin/internal/machinery"
2626
"sigs.k8s.io/kubebuilder/pkg/plugin/scaffold"
2727
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates"
28-
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/controller"
29-
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/crd"
28+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/api"
29+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/crd"
30+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/crd/patches"
31+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/rbac"
32+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/samples"
33+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/controllers"
3034
)
3135

3236
// KbDeclarativePattern is the sigs.k8s.io/kubebuilder-declarative-pattern version
@@ -93,13 +97,13 @@ func (s *apiScaffolder) scaffold() error {
9397

9498
if err := machinery.NewScaffold(s.plugins...).Execute(
9599
s.newUniverse(),
96-
&templates.Types{},
97-
&templates.Group{},
98-
&templates.CRDSample{},
99-
&templates.CRDEditorRole{},
100-
&templates.CRDViewerRole{},
101-
&crd.EnableWebhookPatch{},
102-
&crd.EnableCAInjectionPatch{},
100+
&api.Types{},
101+
&api.Group{},
102+
&samples.CRDSample{},
103+
&rbac.CRDEditorRole{},
104+
&rbac.CRDViewerRole{},
105+
&patches.EnableWebhookPatch{},
106+
&patches.EnableCAInjectionPatch{},
103107
); err != nil {
104108
return fmt.Errorf("error scaffolding APIs: %v", err)
105109
}
@@ -117,8 +121,8 @@ func (s *apiScaffolder) scaffold() error {
117121
if s.doController {
118122
if err := machinery.NewScaffold(s.plugins...).Execute(
119123
s.newUniverse(),
120-
&controller.SuiteTest{WireResource: s.doResource},
121-
&controller.Controller{WireResource: s.doResource},
124+
&controllers.SuiteTest{WireResource: s.doResource},
125+
&controllers.Controller{WireResource: s.doResource},
122126
); err != nil {
123127
return fmt.Errorf("error scaffolding controller: %v", err)
124128
}

pkg/plugin/v2/scaffolds/init.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import (
2626
"sigs.k8s.io/kubebuilder/pkg/plugin/internal/machinery"
2727
"sigs.k8s.io/kubebuilder/pkg/plugin/scaffold"
2828
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates"
29-
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/certmanager"
30-
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/manager"
31-
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/metricsauth"
32-
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/prometheus"
33-
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/webhook"
29+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/certmanager"
30+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/kdefault"
31+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/manager"
32+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/prometheus"
33+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/rbac"
34+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/config/webhook"
35+
"sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/hack"
3436
)
3537

3638
const (
@@ -83,7 +85,7 @@ func (s *initScaffolder) Scaffold() error {
8385
}
8486

8587
func (s *initScaffolder) scaffold() error {
86-
bpFile := &templates.Boilerplate{}
88+
bpFile := &hack.Boilerplate{}
8789
bpFile.Path = s.boilerplatePath
8890
bpFile.License = s.license
8991
bpFile.Owner = s.owner
@@ -102,11 +104,11 @@ func (s *initScaffolder) scaffold() error {
102104
return machinery.NewScaffold().Execute(
103105
s.newUniverse(string(boilerplate)),
104106
&templates.GitIgnore{},
105-
&templates.AuthProxyRole{},
106-
&templates.AuthProxyRoleBinding{},
107-
&metricsauth.AuthProxyPatch{},
108-
&metricsauth.AuthProxyService{},
109-
&metricsauth.ClientClusterRole{},
107+
&rbac.AuthProxyRole{},
108+
&rbac.AuthProxyRoleBinding{},
109+
&kdefault.ManagerAuthProxyPatch{},
110+
&rbac.AuthProxyService{},
111+
&rbac.AuthProxyClientRole{},
110112
&manager.Config{Image: imageName},
111113
&templates.Main{},
112114
&templates.GoMod{ControllerRuntimeVersion: ControllerRuntimeVersion},
@@ -117,20 +119,20 @@ func (s *initScaffolder) scaffold() error {
117119
KustomizeVersion: KustomizeVersion,
118120
},
119121
&templates.Dockerfile{},
120-
&templates.Kustomize{},
121-
&templates.ManagerWebhookPatch{},
122-
&templates.ManagerRoleBinding{},
123-
&templates.LeaderElectionRole{},
124-
&templates.LeaderElectionRoleBinding{},
125-
&templates.KustomizeRBAC{},
122+
&kdefault.Kustomization{},
123+
&kdefault.ManagerWebhookPatch{},
124+
&rbac.RoleBinding{},
125+
&rbac.LeaderElectionRole{},
126+
&rbac.LeaderElectionRoleBinding{},
127+
&rbac.Kustomization{},
126128
&manager.Kustomization{},
127129
&webhook.Kustomization{},
128-
&webhook.KustomizeConfigWebhook{},
130+
&webhook.KustomizeConfig{},
129131
&webhook.Service{},
130-
&webhook.InjectCAPatch{},
132+
&kdefault.WebhookCAInjectionPatch{},
131133
&prometheus.Kustomization{},
132-
&prometheus.ServiceMonitor{},
133-
&certmanager.CertManager{},
134+
&prometheus.Monitor{},
135+
&certmanager.Certificate{},
134136
&certmanager.Kustomization{},
135137
&certmanager.KustomizeConfig{},
136138
)

pkg/plugin/v2/scaffolds/internal/templates/group.go renamed to pkg/plugin/v2/scaffolds/internal/templates/api/group.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package templates
17+
package api
1818

1919
import (
2020
"path/filepath"
@@ -24,15 +24,15 @@ import (
2424

2525
var _ file.Template = &Group{}
2626

27-
// Group scaffolds the api/<version>/groupversion_info.go
27+
// Group scaffolds the file that defines the registration methods for a certain group and version
2828
type Group struct {
2929
file.TemplateMixin
3030
file.MultiGroupMixin
3131
file.BoilerplateMixin
3232
file.ResourceMixin
3333
}
3434

35-
// SetTemplateDefaults implements input.Template
35+
// SetTemplateDefaults implements file.Template
3636
func (f *Group) SetTemplateDefaults() error {
3737
if f.Path == "" {
3838
if f.MultiGroup {

pkg/plugin/v2/scaffolds/internal/templates/types.go renamed to pkg/plugin/v2/scaffolds/internal/templates/api/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package templates
17+
package api
1818

1919
import (
2020
"fmt"
@@ -25,15 +25,15 @@ import (
2525

2626
var _ file.Template = &Types{}
2727

28-
// Types scaffolds the api/<version>/<kind>_types.go file to define the schema for an API
28+
// Types scaffolds the file that defines the schema for a CRD
2929
type Types struct {
3030
file.TemplateMixin
3131
file.MultiGroupMixin
3232
file.BoilerplateMixin
3333
file.ResourceMixin
3434
}
3535

36-
// SetTemplateDefaults implements input.Template
36+
// SetTemplateDefaults implements file.Template
3737
func (f *Types) SetTemplateDefaults() error {
3838
if f.Path == "" {
3939
if f.MultiGroup {

pkg/plugin/v2/scaffolds/internal/templates/webhook/webhook.go renamed to pkg/plugin/v2/scaffolds/internal/templates/api/webhook.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package webhook
17+
package api
1818

1919
import (
2020
"fmt"
@@ -26,7 +26,7 @@ import (
2626

2727
var _ file.Template = &Webhook{}
2828

29-
// Webhook scaffolds a Webhook for a Resource
29+
// Webhook scaffolds the file that defines a webhook for a CRD or a builtin resource
3030
type Webhook struct { // nolint:maligned
3131
file.TemplateMixin
3232
file.MultiGroupMixin
@@ -42,7 +42,7 @@ type Webhook struct { // nolint:maligned
4242
Validating bool
4343
}
4444

45-
// SetTemplateDefaults implements input.Template
45+
// SetTemplateDefaults implements file.Template
4646
func (f *Webhook) SetTemplateDefaults() error {
4747
if f.Path == "" {
4848
if f.MultiGroup {
@@ -78,7 +78,7 @@ package {{ .Resource.Version }}
7878
import (
7979
ctrl "sigs.k8s.io/controller-runtime"
8080
logf "sigs.k8s.io/controller-runtime/pkg/log"
81-
{{- if or .Validating }}
81+
{{- if .Validating }}
8282
"k8s.io/apimachinery/pkg/runtime"
8383
{{- end }}
8484
{{- if or .Validating .Defaulting }}

pkg/plugin/v2/scaffolds/internal/templates/certmanager/certificate.go renamed to pkg/plugin/v2/scaffolds/internal/templates/config/certmanager/certificate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import (
2222
"sigs.k8s.io/kubebuilder/pkg/model/file"
2323
)
2424

25-
var _ file.Template = &CertManager{}
25+
var _ file.Template = &Certificate{}
2626

27-
// CertManager scaffolds an issuer CR and a certificate CR
28-
type CertManager struct {
27+
// Certificate scaffolds a file that defines the issuer CR and the certificate CR
28+
type Certificate struct {
2929
file.TemplateMixin
3030
}
3131

32-
// SetTemplateDefaults implements input.Template
33-
func (f *CertManager) SetTemplateDefaults() error {
32+
// SetTemplateDefaults implements file.Template
33+
func (f *Certificate) SetTemplateDefaults() error {
3434
if f.Path == "" {
3535
f.Path = filepath.Join("config", "certmanager", "certificate.yaml")
3636
}

pkg/plugin/v2/scaffolds/internal/templates/certmanager/kustomize.go renamed to pkg/plugin/v2/scaffolds/internal/templates/config/certmanager/kustomization.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424

2525
var _ file.Template = &Kustomization{}
2626

27-
// Kustomization scaffolds the kustomizaiton in the certmanager folder
27+
// Kustomization scaffolds a file that defines the kustomization scheme for the certmanager folder
2828
type Kustomization struct {
2929
file.TemplateMixin
3030
}
3131

32-
// SetTemplateDefaults implements input.Template
32+
// SetTemplateDefaults implements file.Template
3333
func (f *Kustomization) SetTemplateDefaults() error {
3434
if f.Path == "" {
3535
f.Path = filepath.Join("config", "certmanager", "kustomization.yaml")

pkg/plugin/v2/scaffolds/internal/templates/certmanager/kustomizeconfig.go renamed to pkg/plugin/v2/scaffolds/internal/templates/config/certmanager/kustomizeconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424

2525
var _ file.Template = &KustomizeConfig{}
2626

27-
// KustomizeConfig scaffolds the kustomizeconfig in the certmanager folder
27+
// KustomizeConfig scaffolds a file that configures the kustomization for the certmanager folder
2828
type KustomizeConfig struct {
2929
file.TemplateMixin
3030
}
3131

32-
// SetTemplateDefaults implements input.Template
32+
// SetTemplateDefaults implements file.Template
3333
func (f *KustomizeConfig) SetTemplateDefaults() error {
3434
if f.Path == "" {
3535
f.Path = filepath.Join("config", "certmanager", "kustomizeconfig.yaml")

pkg/plugin/v2/scaffolds/internal/templates/crd/kustomization.go renamed to pkg/plugin/v2/scaffolds/internal/templates/config/crd/kustomization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
var _ file.Template = &Kustomization{}
2727
var _ file.Inserter = &Kustomization{}
2828

29-
// Kustomization scaffolds the kustomization file in manager folder.
29+
// Kustomization scaffolds a file that defines the kustomization scheme for the crd folder
3030
type Kustomization struct {
3131
file.TemplateMixin
3232
file.ResourceMixin

pkg/plugin/v2/scaffolds/internal/templates/crd/kustomizeconfig.go renamed to pkg/plugin/v2/scaffolds/internal/templates/config/crd/kustomizeconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424

2525
var _ file.Template = &KustomizeConfig{}
2626

27-
// KustomizeConfig scaffolds the kustomizeconfig file in crd folder.
27+
// KustomizeConfig scaffolds a file that configures the kustomization for the crd folder
2828
type KustomizeConfig struct {
2929
file.TemplateMixin
3030
}
3131

32-
// SetTemplateDefaults implements input.Template
32+
// SetTemplateDefaults implements file.Template
3333
func (f *KustomizeConfig) SetTemplateDefaults() error {
3434
if f.Path == "" {
3535
f.Path = filepath.Join("config", "crd", "kustomizeconfig.yaml")

0 commit comments

Comments
 (0)