@@ -26,12 +26,15 @@ import (
26
26
)
27
27
28
28
var (
29
- apisTemplatePaths = []string {
29
+ apisGenericTemplatesPaths = []string {
30
30
"crossplane/apis/doc.go.tpl" ,
31
31
"crossplane/apis/enums.go.tpl" ,
32
32
"crossplane/apis/groupversion_info.go.tpl" ,
33
33
"crossplane/apis/types.go.tpl" ,
34
34
}
35
+ crdTemplatePath = "crossplane/apis/crd.go.tpl"
36
+ controllerTmplPath = "crossplane/pkg/controller.go.tpl"
37
+ conversionsTmplPath = "crossplane/pkg/conversions.go.tpl"
35
38
includePaths = []string {
36
39
"crossplane/boilerplate.go.tpl" ,
37
40
"crossplane/apis/enum_def.go.tpl" ,
@@ -142,7 +145,7 @@ func Crossplane(
142
145
typeDefs ,
143
146
typeImports ,
144
147
}
145
- for _ , path := range apisTemplatePaths {
148
+ for _ , path := range apisGenericTemplatesPaths {
146
149
outPath := filepath .Join (
147
150
"apis" ,
148
151
metaVars .ServiceIDClean ,
@@ -162,29 +165,34 @@ func Crossplane(
162
165
metaVars ,
163
166
crd ,
164
167
}
165
- if err = ts .Add (crdFileName , "apis/crd.go.tpl" , crdVars ); err != nil {
168
+ if err = ts .Add (crdFileName , crdTemplatePath , crdVars ); err != nil {
166
169
return nil , err
167
170
}
168
171
}
169
172
170
173
// Next add the controller package for each CRD
171
- targets := []string {
172
- "controller.go.tpl" ,
173
- "conversions.go.tpl" ,
174
- }
175
174
for _ , crd := range crds {
176
- for _ , target := range targets {
177
- outPath := filepath .Join (
178
- "pkg" , "controller" , metaVars .ServiceIDClean , crd .Names .Lower ,
179
- "zz_" + strings .TrimSuffix (filepath .Base (target ), ".tpl" ),
180
- )
181
- crdVars := & templateCRDVars {
182
- metaVars ,
183
- crd ,
184
- }
185
- if err = ts .Add (outPath , "pkg/" + target , crdVars ); err != nil {
186
- return nil , err
187
- }
175
+ outPath := filepath .Join (
176
+ "pkg" , "controller" , metaVars .ServiceIDClean , crd .Names .Lower ,
177
+ "zz_controller.go" ,
178
+ )
179
+ crdVars := & templateCRDVars {
180
+ metaVars ,
181
+ crd ,
182
+ }
183
+ if err = ts .Add (outPath , controllerTmplPath , crdVars ); err != nil {
184
+ return nil , err
185
+ }
186
+ outPath = filepath .Join (
187
+ "pkg" , "controller" , metaVars .ServiceIDClean , crd .Names .Lower ,
188
+ "zz_conversions.go" ,
189
+ )
190
+ crdVars = & templateCRDVars {
191
+ metaVars ,
192
+ crd ,
193
+ }
194
+ if err = ts .Add (outPath , conversionsTmplPath , crdVars ); err != nil {
195
+ return nil , err
188
196
}
189
197
}
190
198
0 commit comments