@@ -20,46 +20,50 @@ import (
20
20
"sigs.k8s.io/kubebuilder/pkg/model/resource"
21
21
)
22
22
23
- // Template is a scaffoldable file template
24
- type Template interface {
25
- // GetPath returns the path to the file location
26
- GetPath () string
27
- // GetBody returns the template body
28
- GetBody () string
29
- // GetIfExistsAction returns the behavior when creating a file that already exists
30
- GetIfExistsAction () IfExistsAction
31
- // SetTemplateDefaults returns the TemplateMixin for creating a scaffold file
32
- SetTemplateDefaults () error
33
- }
34
-
35
- // TemplateMixin is the input for scaffolding a file
36
- type TemplateMixin struct {
37
- // Path is the file to write
23
+ // PathMixin provides file builders with a path field
24
+ type PathMixin struct {
25
+ // Path is the of the file
38
26
Path string
27
+ }
39
28
40
- // TemplateBody is the template body to execute
41
- TemplateBody string
29
+ // GetPath implements Builder
30
+ func (t * PathMixin ) GetPath () string {
31
+ return t .Path
32
+ }
42
33
34
+ // IfExistsActionMixin provides file builders with a if-exists-action field
35
+ type IfExistsActionMixin struct {
43
36
// IfExistsAction determines what to do if the file exists
44
37
IfExistsAction IfExistsAction
45
38
}
46
39
47
- func (t * TemplateMixin ) GetPath () string {
48
- return t .Path
40
+ // GetIfExistsAction implements Builder
41
+ func (t * IfExistsActionMixin ) GetIfExistsAction () IfExistsAction {
42
+ return t .IfExistsAction
43
+ }
44
+
45
+ // TemplateMixin is the mixin that should be embedded in Template builders
46
+ type TemplateMixin struct {
47
+ PathMixin
48
+ IfExistsActionMixin
49
+
50
+ // TemplateBody is the template body to execute
51
+ TemplateBody string
49
52
}
50
53
51
54
func (t * TemplateMixin ) GetBody () string {
52
55
return t .TemplateBody
53
56
}
54
57
55
- func (t * TemplateMixin ) GetIfExistsAction () IfExistsAction {
56
- return t .IfExistsAction
58
+ // InserterMixin is the mixin that should be embedded in Inserter builders
59
+ type InserterMixin struct {
60
+ PathMixin
57
61
}
58
62
59
- // HasDomain allows the domain to be used on a template
60
- type HasDomain interface {
61
- // InjectDomain sets the template domain
62
- InjectDomain ( string )
63
+ // GetIfExistsAction implements Builder
64
+ func ( t * InserterMixin ) GetIfExistsAction () IfExistsAction {
65
+ // Inserter builders always need to overwrite previous files
66
+ return Overwrite
63
67
}
64
68
65
69
// DomainMixin provides templates with a injectable domain field
@@ -75,12 +79,6 @@ func (m *DomainMixin) InjectDomain(domain string) {
75
79
}
76
80
}
77
81
78
- // HasRepository allows the repository to be used on a template
79
- type HasRepository interface {
80
- // InjectRepository sets the template repository
81
- InjectRepository (string )
82
- }
83
-
84
82
// RepositoryMixin provides templates with a injectable repository field
85
83
type RepositoryMixin struct {
86
84
// Repo is the go project package path
@@ -94,12 +92,6 @@ func (m *RepositoryMixin) InjectRepository(repository string) {
94
92
}
95
93
}
96
94
97
- // HasMultiGroup allows the multi-group flag to be used on a template
98
- type HasMultiGroup interface {
99
- // InjectMultiGroup sets the template multi-group flag
100
- InjectMultiGroup (bool )
101
- }
102
-
103
95
// MultiGroupMixin provides templates with a injectable multi-group flag field
104
96
type MultiGroupMixin struct {
105
97
// MultiGroup is the multi-group flag
@@ -111,12 +103,6 @@ func (m *MultiGroupMixin) InjectMultiGroup(flag bool) {
111
103
m .MultiGroup = flag
112
104
}
113
105
114
- // HasBoilerplate allows a boilerplate to be used on a template
115
- type HasBoilerplate interface {
116
- // InjectBoilerplate sets the template boilerplate
117
- InjectBoilerplate (string )
118
- }
119
-
120
106
// BoilerplateMixin provides templates with a injectable boilerplate field
121
107
type BoilerplateMixin struct {
122
108
// Boilerplate is the contents of a Boilerplate go header file
@@ -130,12 +116,6 @@ func (m *BoilerplateMixin) InjectBoilerplate(boilerplate string) {
130
116
}
131
117
}
132
118
133
- // HasResource allows a resource to be used on a template
134
- type HasResource interface {
135
- // InjectResource sets the template resource
136
- InjectResource (* resource.Resource )
137
- }
138
-
139
119
// ResourceMixin provides templates with a injectable resource field
140
120
type ResourceMixin struct {
141
121
Resource * resource.Resource
@@ -147,10 +127,3 @@ func (m *ResourceMixin) InjectResource(res *resource.Resource) {
147
127
m .Resource = res
148
128
}
149
129
}
150
-
151
- // RequiresValidation is a file that requires validation
152
- type RequiresValidation interface {
153
- Template
154
- // Validate returns true if the template has valid values
155
- Validate () error
156
- }
0 commit comments