Skip to content

Commit 63ada1d

Browse files
authored
Merge pull request #30 from muvaf/fix-cp-tmpl
crossplane: fix the template paths to include crossplane prefix
2 parents a4e3fec + 0e593f7 commit 63ada1d

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

pkg/generate/crossplane/crossplane.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ import (
2626
)
2727

2828
var (
29-
apisTemplatePaths = []string{
29+
apisGenericTemplatesPaths = []string{
3030
"crossplane/apis/doc.go.tpl",
3131
"crossplane/apis/enums.go.tpl",
3232
"crossplane/apis/groupversion_info.go.tpl",
3333
"crossplane/apis/types.go.tpl",
3434
}
35+
crdTemplatePath = "crossplane/apis/crd.go.tpl"
36+
controllerTmplPath = "crossplane/pkg/controller.go.tpl"
37+
conversionsTmplPath = "crossplane/pkg/conversions.go.tpl"
3538
includePaths = []string{
3639
"crossplane/boilerplate.go.tpl",
3740
"crossplane/apis/enum_def.go.tpl",
@@ -142,7 +145,7 @@ func Crossplane(
142145
typeDefs,
143146
typeImports,
144147
}
145-
for _, path := range apisTemplatePaths {
148+
for _, path := range apisGenericTemplatesPaths {
146149
outPath := filepath.Join(
147150
"apis",
148151
metaVars.ServiceIDClean,
@@ -162,29 +165,34 @@ func Crossplane(
162165
metaVars,
163166
crd,
164167
}
165-
if err = ts.Add(crdFileName, "apis/crd.go.tpl", crdVars); err != nil {
168+
if err = ts.Add(crdFileName, crdTemplatePath, crdVars); err != nil {
166169
return nil, err
167170
}
168171
}
169172

170173
// Next add the controller package for each CRD
171-
targets := []string{
172-
"controller.go.tpl",
173-
"conversions.go.tpl",
174-
}
175174
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
188196
}
189197
}
190198

0 commit comments

Comments
 (0)