@@ -2,22 +2,23 @@ package composite
22
33import (
44 "bytes"
5- "encoding/json"
65 "fmt"
76 "io"
87 "os"
98 "os/exec"
109 "path"
1110 "strings"
1211
12+ "sigs.k8s.io/yaml"
13+
1314 "github.com/operator-framework/operator-registry/alpha/declcfg"
1415)
1516
1617const (
17- BasicVeneerBuilderSchema = "olm.veneer .basic"
18- SemverVeneerBuilderSchema = "olm.veneer .semver"
19- RawVeneerBuilderSchema = "olm.veneer .raw"
20- CustomVeneerBuilderSchema = "olm.veneer .custom"
18+ BasicBuilderSchema = "olm.builder .basic"
19+ SemverBuilderSchema = "olm.builder .semver"
20+ RawBuilderSchema = "olm.builder .raw"
21+ CustomBuilderSchema = "olm.builder .custom"
2122)
2223
2324type ContainerConfig struct {
@@ -33,7 +34,7 @@ type BuilderConfig struct {
3334}
3435
3536type Builder interface {
36- Build (dir string , vd VeneerDefinition ) error
37+ Build (dir string , td TemplateDefinition ) error
3738 Validate (dir string ) error
3839}
3940
@@ -49,32 +50,32 @@ func NewBasicBuilder(builderCfg BuilderConfig) *BasicBuilder {
4950 }
5051}
5152
52- func (bb * BasicBuilder ) Build (dir string , vd VeneerDefinition ) error {
53- if vd .Schema != BasicVeneerBuilderSchema {
54- return fmt .Errorf ("schema %q does not match the basic veneer builder schema %q" , vd .Schema , BasicVeneerBuilderSchema )
53+ func (bb * BasicBuilder ) Build (dir string , td TemplateDefinition ) error {
54+ if td .Schema != BasicBuilderSchema {
55+ return fmt .Errorf ("schema %q does not match the basic template builder schema %q" , td .Schema , BasicBuilderSchema )
5556 }
56- // Parse out the basic veneer configuration
57- basicConfig := & BasicVeneerConfig {}
58- err := json . Unmarshal ( vd .Config , basicConfig )
57+ // Parse out the basic template configuration
58+ basicConfig := & BasicConfig {}
59+ err := yaml . UnmarshalStrict ( td .Config , basicConfig )
5960 if err != nil {
60- return fmt .Errorf ("unmarshalling basic veneer config: %w" , err )
61+ return fmt .Errorf ("unmarshalling basic template config: %w" , err )
6162 }
6263
6364 // validate the basic config fields
6465 valid := true
6566 validationErrs := []string {}
6667 if basicConfig .Input == "" {
6768 valid = false
68- validationErrs = append (validationErrs , "basic veneer config must have a non-empty input (veneerDefinition .config.input)" )
69+ validationErrs = append (validationErrs , "basic template config must have a non-empty input (templateDefinition .config.input)" )
6970 }
7071
7172 if basicConfig .Output == "" {
7273 valid = false
73- validationErrs = append (validationErrs , "basic veneer config must have a non-empty output (veneerDefinition .config.output)" )
74+ validationErrs = append (validationErrs , "basic template config must have a non-empty output (templateDefinition .config.output)" )
7475 }
7576
7677 if ! valid {
77- return fmt .Errorf ("basic veneer configuration is invalid: %s" , strings .Join (validationErrs , "," ))
78+ return fmt .Errorf ("basic template configuration is invalid: %s" , strings .Join (validationErrs , "," ))
7879 }
7980
8081 // build the container command
@@ -85,7 +86,7 @@ func (bb *BasicBuilder) Build(dir string, vd VeneerDefinition) error {
8586 fmt .Sprintf ("%s:%s:Z" , bb .builderCfg .CurrentDirectory , bb .builderCfg .ContainerCfg .WorkingDir ),
8687 bb .builderCfg .ContainerCfg .BaseImage ,
8788 "alpha" ,
88- "render-veneer " ,
89+ "render-template " ,
8990 "basic" ,
9091 path .Join (bb .builderCfg .ContainerCfg .WorkingDir , basicConfig .Input ))
9192
@@ -108,32 +109,32 @@ func NewSemverBuilder(builderCfg BuilderConfig) *SemverBuilder {
108109 }
109110}
110111
111- func (sb * SemverBuilder ) Build (dir string , vd VeneerDefinition ) error {
112- if vd .Schema != SemverVeneerBuilderSchema {
113- return fmt .Errorf ("schema %q does not match the semver veneer builder schema %q" , vd .Schema , SemverVeneerBuilderSchema )
112+ func (sb * SemverBuilder ) Build (dir string , td TemplateDefinition ) error {
113+ if td .Schema != SemverBuilderSchema {
114+ return fmt .Errorf ("schema %q does not match the semver template builder schema %q" , td .Schema , SemverBuilderSchema )
114115 }
115- // Parse out the semver veneer configuration
116- semverConfig := & SemverVeneerConfig {}
117- err := json . Unmarshal ( vd .Config , semverConfig )
116+ // Parse out the semver template configuration
117+ semverConfig := & SemverConfig {}
118+ err := yaml . UnmarshalStrict ( td .Config , semverConfig )
118119 if err != nil {
119- return fmt .Errorf ("unmarshalling semver veneer config: %w" , err )
120+ return fmt .Errorf ("unmarshalling semver template config: %w" , err )
120121 }
121122
122123 // validate the semver config fields
123124 valid := true
124125 validationErrs := []string {}
125126 if semverConfig .Input == "" {
126127 valid = false
127- validationErrs = append (validationErrs , "semver veneer config must have a non-empty input (veneerDefinition .config.input)" )
128+ validationErrs = append (validationErrs , "semver template config must have a non-empty input (templateDefinition .config.input)" )
128129 }
129130
130131 if semverConfig .Output == "" {
131132 valid = false
132- validationErrs = append (validationErrs , "semver veneer config must have a non-empty output (veneerDefinition .config.output)" )
133+ validationErrs = append (validationErrs , "semver template config must have a non-empty output (templateDefinition .config.output)" )
133134 }
134135
135136 if ! valid {
136- return fmt .Errorf ("semver veneer configuration is invalid: %s" , strings .Join (validationErrs , "," ))
137+ return fmt .Errorf ("semver template configuration is invalid: %s" , strings .Join (validationErrs , "," ))
137138 }
138139
139140 // build the container command
@@ -144,7 +145,7 @@ func (sb *SemverBuilder) Build(dir string, vd VeneerDefinition) error {
144145 fmt .Sprintf ("%s:%s:Z" , sb .builderCfg .CurrentDirectory , sb .builderCfg .ContainerCfg .WorkingDir ),
145146 sb .builderCfg .ContainerCfg .BaseImage ,
146147 "alpha" ,
147- "render-veneer " ,
148+ "render-template " ,
148149 "semver" ,
149150 path .Join (sb .builderCfg .ContainerCfg .WorkingDir , semverConfig .Input ))
150151
@@ -167,32 +168,32 @@ func NewRawBuilder(builderCfg BuilderConfig) *RawBuilder {
167168 }
168169}
169170
170- func (rb * RawBuilder ) Build (dir string , vd VeneerDefinition ) error {
171- if vd .Schema != RawVeneerBuilderSchema {
172- return fmt .Errorf ("schema %q does not match the raw veneer builder schema %q" , vd .Schema , RawVeneerBuilderSchema )
171+ func (rb * RawBuilder ) Build (dir string , td TemplateDefinition ) error {
172+ if td .Schema != RawBuilderSchema {
173+ return fmt .Errorf ("schema %q does not match the raw template builder schema %q" , td .Schema , RawBuilderSchema )
173174 }
174- // Parse out the raw veneer configuration
175- rawConfig := & RawVeneerConfig {}
176- err := json . Unmarshal ( vd .Config , rawConfig )
175+ // Parse out the raw template configuration
176+ rawConfig := & RawConfig {}
177+ err := yaml . UnmarshalStrict ( td .Config , rawConfig )
177178 if err != nil {
178- return fmt .Errorf ("unmarshalling raw veneer config: %w" , err )
179+ return fmt .Errorf ("unmarshalling raw template config: %w" , err )
179180 }
180181
181182 // validate the raw config fields
182183 valid := true
183184 validationErrs := []string {}
184185 if rawConfig .Input == "" {
185186 valid = false
186- validationErrs = append (validationErrs , "raw veneer config must have a non-empty input (veneerDefinition .config.input)" )
187+ validationErrs = append (validationErrs , "raw template config must have a non-empty input (templateDefinition .config.input)" )
187188 }
188189
189190 if rawConfig .Output == "" {
190191 valid = false
191- validationErrs = append (validationErrs , "raw veneer config must have a non-empty output (veneerDefinition .config.output)" )
192+ validationErrs = append (validationErrs , "raw template config must have a non-empty output (templateDefinition .config.output)" )
192193 }
193194
194195 if ! valid {
195- return fmt .Errorf ("raw veneer configuration is invalid: %s" , strings .Join (validationErrs , "," ))
196+ return fmt .Errorf ("raw template configuration is invalid: %s" , strings .Join (validationErrs , "," ))
196197 }
197198
198199 // build the container command
@@ -201,7 +202,7 @@ func (rb *RawBuilder) Build(dir string, vd VeneerDefinition) error {
201202 "--rm" ,
202203 "-v" ,
203204 fmt .Sprintf ("%s:%s:Z" , rb .builderCfg .CurrentDirectory , rb .builderCfg .ContainerCfg .WorkingDir ),
204- "--entrypoint=cat" , // This assumes that the `cat` command is available in the container -- Should we also build a `... render-veneer raw` command to ensure consistent operation? Does OPM already have a way to render a raw FBC?
205+ "--entrypoint=cat" , // This assumes that the `cat` command is available in the container -- Should we also build a `... render-template raw` command to ensure consistent operation? Does OPM already have a way to render a raw FBC?
205206 rb .builderCfg .ContainerCfg .BaseImage ,
206207 path .Join (rb .builderCfg .ContainerCfg .WorkingDir , rawConfig .Input ))
207208
@@ -224,39 +225,39 @@ func NewCustomBuilder(builderCfg BuilderConfig) *CustomBuilder {
224225 }
225226}
226227
227- func (cb * CustomBuilder ) Build (dir string , vd VeneerDefinition ) error {
228- if vd .Schema != CustomVeneerBuilderSchema {
229- return fmt .Errorf ("schema %q does not match the custom veneer builder schema %q" , vd .Schema , CustomVeneerBuilderSchema )
228+ func (cb * CustomBuilder ) Build (dir string , td TemplateDefinition ) error {
229+ if td .Schema != CustomBuilderSchema {
230+ return fmt .Errorf ("schema %q does not match the custom template builder schema %q" , td .Schema , CustomBuilderSchema )
230231 }
231- // Parse out the raw veneer configuration
232- customConfig := & CustomVeneerConfig {}
233- err := json . Unmarshal ( vd .Config , customConfig )
232+ // Parse out the raw template configuration
233+ customConfig := & CustomConfig {}
234+ err := yaml . UnmarshalStrict ( td .Config , customConfig )
234235 if err != nil {
235- return fmt .Errorf ("unmarshalling custom veneer config: %w" , err )
236+ return fmt .Errorf ("unmarshalling custom template config: %w" , err )
236237 }
237238
238239 // validate the custom config fields
239240 valid := true
240241 validationErrs := []string {}
241242 if customConfig .Command == "" {
242243 valid = false
243- validationErrs = append (validationErrs , "custom veneer config must have a non-empty command (veneerDefinition .config.command)" )
244+ validationErrs = append (validationErrs , "custom template config must have a non-empty command (templateDefinition .config.command)" )
244245 }
245246
246247 if customConfig .Output == "" {
247248 valid = false
248- validationErrs = append (validationErrs , "custom veneer config must have a non-empty output (veneerDefinition .config.output)" )
249+ validationErrs = append (validationErrs , "custom template config must have a non-empty output (templateDefinition .config.output)" )
249250 }
250251
251252 if ! valid {
252- return fmt .Errorf ("custom veneer configuration is invalid: %s" , strings .Join (validationErrs , "," ))
253+ return fmt .Errorf ("custom template configuration is invalid: %s" , strings .Join (validationErrs , "," ))
253254 }
254255 // build the command to execute
255256 cmd := exec .Command (customConfig .Command , customConfig .Args ... )
256257 cmd .Dir = cb .builderCfg .CurrentDirectory
257258
258- // custom veneer should output a valid FBC to STDOUT so we can
259- // build the FBC just like all the other veneers .
259+ // custom template should output a valid FBC to STDOUT so we can
260+ // build the FBC just like all the other templates .
260261 return build (cmd , path .Join (dir , customConfig .Output ), cb .builderCfg .OutputType )
261262}
262263
0 commit comments