Skip to content

Commit

Permalink
OPECO-2664: rename veneer to template (operator-framework#1066)
Browse files Browse the repository at this point in the history
* rename template to veneer

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>

* fixing some utest

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>

* adding cobra exit-status consistency through command hierarchy, adding temp skips of failing utests until we get the new release

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>

---------

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
  • Loading branch information
grokspawn committed Feb 21, 2023
1 parent 0aeffa3 commit 57a959d
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 310 deletions.
14 changes: 7 additions & 7 deletions alpha/veneer/basic/basic.go → alpha/template/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/operator-framework/operator-registry/pkg/image"
)

type Veneer struct {
type Template struct {
Registry image.Registry
}

func (v Veneer) Render(ctx context.Context, reader io.Reader) (*declcfg.DeclarativeConfig, error) {
func (t Template) Render(ctx context.Context, reader io.Reader) (*declcfg.DeclarativeConfig, error) {
cfg, err := declcfg.LoadReader(reader)
if err != nil {
return cfg, err
Expand All @@ -23,13 +23,13 @@ func (v Veneer) Render(ctx context.Context, reader io.Reader) (*declcfg.Declarat
outb := cfg.Bundles[:0] // allocate based on max size of input, but empty slice
// populate registry, incl any flags from CLI, and enforce only rendering bundle images
r := action.Render{
Registry: v.Registry,
Registry: t.Registry,
AllowedRefMask: action.RefBundleImage,
}

for _, b := range cfg.Bundles {
if !isBundleVeneer(&b) {
return nil, fmt.Errorf("unexpected fields present in basic veneer bundle")
if !isBundleTemplate(&b) {
return nil, fmt.Errorf("unexpected fields present in basic template bundle")
}
r.Refs = []string{b.Image}
contributor, err := r.Run(ctx)
Expand All @@ -43,8 +43,8 @@ func (v Veneer) Render(ctx context.Context, reader io.Reader) (*declcfg.Declarat
return cfg, nil
}

// isBundleVeneer identifies a Bundle veneer source as having a Schema and Image defined
// isBundleTemplate identifies a Bundle template source as having a Schema and Image defined
// but no Properties, RelatedImages or Package defined
func isBundleVeneer(b *declcfg.Bundle) bool {
func isBundleTemplate(b *declcfg.Bundle) bool {
return b.Schema != "" && b.Image != "" && b.Package == "" && len(b.Properties) == 0 && len(b.RelatedImages) == 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ package composite

import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
"path"
"strings"

"sigs.k8s.io/yaml"

"github.com/operator-framework/operator-registry/alpha/declcfg"
)

const (
BasicVeneerBuilderSchema = "olm.veneer.basic"
SemverVeneerBuilderSchema = "olm.veneer.semver"
RawVeneerBuilderSchema = "olm.veneer.raw"
CustomVeneerBuilderSchema = "olm.veneer.custom"
BasicBuilderSchema = "olm.builder.basic"
SemverBuilderSchema = "olm.builder.semver"
RawBuilderSchema = "olm.builder.raw"
CustomBuilderSchema = "olm.builder.custom"
)

type ContainerConfig struct {
Expand All @@ -33,7 +34,7 @@ type BuilderConfig struct {
}

type Builder interface {
Build(dir string, vd VeneerDefinition) error
Build(dir string, td TemplateDefinition) error
Validate(dir string) error
}

Expand All @@ -49,32 +50,32 @@ func NewBasicBuilder(builderCfg BuilderConfig) *BasicBuilder {
}
}

func (bb *BasicBuilder) Build(dir string, vd VeneerDefinition) error {
if vd.Schema != BasicVeneerBuilderSchema {
return fmt.Errorf("schema %q does not match the basic veneer builder schema %q", vd.Schema, BasicVeneerBuilderSchema)
func (bb *BasicBuilder) Build(dir string, td TemplateDefinition) error {
if td.Schema != BasicBuilderSchema {
return fmt.Errorf("schema %q does not match the basic template builder schema %q", td.Schema, BasicBuilderSchema)
}
// Parse out the basic veneer configuration
basicConfig := &BasicVeneerConfig{}
err := json.Unmarshal(vd.Config, basicConfig)
// Parse out the basic template configuration
basicConfig := &BasicConfig{}
err := yaml.UnmarshalStrict(td.Config, basicConfig)
if err != nil {
return fmt.Errorf("unmarshalling basic veneer config: %w", err)
return fmt.Errorf("unmarshalling basic template config: %w", err)
}

// validate the basic config fields
valid := true
validationErrs := []string{}
if basicConfig.Input == "" {
valid = false
validationErrs = append(validationErrs, "basic veneer config must have a non-empty input (veneerDefinition.config.input)")
validationErrs = append(validationErrs, "basic template config must have a non-empty input (templateDefinition.config.input)")
}

if basicConfig.Output == "" {
valid = false
validationErrs = append(validationErrs, "basic veneer config must have a non-empty output (veneerDefinition.config.output)")
validationErrs = append(validationErrs, "basic template config must have a non-empty output (templateDefinition.config.output)")
}

if !valid {
return fmt.Errorf("basic veneer configuration is invalid: %s", strings.Join(validationErrs, ","))
return fmt.Errorf("basic template configuration is invalid: %s", strings.Join(validationErrs, ","))
}

// build the container command
Expand All @@ -85,7 +86,7 @@ func (bb *BasicBuilder) Build(dir string, vd VeneerDefinition) error {
fmt.Sprintf("%s:%s:Z", bb.builderCfg.CurrentDirectory, bb.builderCfg.ContainerCfg.WorkingDir),
bb.builderCfg.ContainerCfg.BaseImage,
"alpha",
"render-veneer",
"render-template",
"basic",
path.Join(bb.builderCfg.ContainerCfg.WorkingDir, basicConfig.Input))

Expand All @@ -108,32 +109,32 @@ func NewSemverBuilder(builderCfg BuilderConfig) *SemverBuilder {
}
}

func (sb *SemverBuilder) Build(dir string, vd VeneerDefinition) error {
if vd.Schema != SemverVeneerBuilderSchema {
return fmt.Errorf("schema %q does not match the semver veneer builder schema %q", vd.Schema, SemverVeneerBuilderSchema)
func (sb *SemverBuilder) Build(dir string, td TemplateDefinition) error {
if td.Schema != SemverBuilderSchema {
return fmt.Errorf("schema %q does not match the semver template builder schema %q", td.Schema, SemverBuilderSchema)
}
// Parse out the semver veneer configuration
semverConfig := &SemverVeneerConfig{}
err := json.Unmarshal(vd.Config, semverConfig)
// Parse out the semver template configuration
semverConfig := &SemverConfig{}
err := yaml.UnmarshalStrict(td.Config, semverConfig)
if err != nil {
return fmt.Errorf("unmarshalling semver veneer config: %w", err)
return fmt.Errorf("unmarshalling semver template config: %w", err)
}

// validate the semver config fields
valid := true
validationErrs := []string{}
if semverConfig.Input == "" {
valid = false
validationErrs = append(validationErrs, "semver veneer config must have a non-empty input (veneerDefinition.config.input)")
validationErrs = append(validationErrs, "semver template config must have a non-empty input (templateDefinition.config.input)")
}

if semverConfig.Output == "" {
valid = false
validationErrs = append(validationErrs, "semver veneer config must have a non-empty output (veneerDefinition.config.output)")
validationErrs = append(validationErrs, "semver template config must have a non-empty output (templateDefinition.config.output)")
}

if !valid {
return fmt.Errorf("semver veneer configuration is invalid: %s", strings.Join(validationErrs, ","))
return fmt.Errorf("semver template configuration is invalid: %s", strings.Join(validationErrs, ","))
}

// build the container command
Expand All @@ -144,7 +145,7 @@ func (sb *SemverBuilder) Build(dir string, vd VeneerDefinition) error {
fmt.Sprintf("%s:%s:Z", sb.builderCfg.CurrentDirectory, sb.builderCfg.ContainerCfg.WorkingDir),
sb.builderCfg.ContainerCfg.BaseImage,
"alpha",
"render-veneer",
"render-template",
"semver",
path.Join(sb.builderCfg.ContainerCfg.WorkingDir, semverConfig.Input))

Expand All @@ -167,32 +168,32 @@ func NewRawBuilder(builderCfg BuilderConfig) *RawBuilder {
}
}

func (rb *RawBuilder) Build(dir string, vd VeneerDefinition) error {
if vd.Schema != RawVeneerBuilderSchema {
return fmt.Errorf("schema %q does not match the raw veneer builder schema %q", vd.Schema, RawVeneerBuilderSchema)
func (rb *RawBuilder) Build(dir string, td TemplateDefinition) error {
if td.Schema != RawBuilderSchema {
return fmt.Errorf("schema %q does not match the raw template builder schema %q", td.Schema, RawBuilderSchema)
}
// Parse out the raw veneer configuration
rawConfig := &RawVeneerConfig{}
err := json.Unmarshal(vd.Config, rawConfig)
// Parse out the raw template configuration
rawConfig := &RawConfig{}
err := yaml.UnmarshalStrict(td.Config, rawConfig)
if err != nil {
return fmt.Errorf("unmarshalling raw veneer config: %w", err)
return fmt.Errorf("unmarshalling raw template config: %w", err)
}

// validate the raw config fields
valid := true
validationErrs := []string{}
if rawConfig.Input == "" {
valid = false
validationErrs = append(validationErrs, "raw veneer config must have a non-empty input (veneerDefinition.config.input)")
validationErrs = append(validationErrs, "raw template config must have a non-empty input (templateDefinition.config.input)")
}

if rawConfig.Output == "" {
valid = false
validationErrs = append(validationErrs, "raw veneer config must have a non-empty output (veneerDefinition.config.output)")
validationErrs = append(validationErrs, "raw template config must have a non-empty output (templateDefinition.config.output)")
}

if !valid {
return fmt.Errorf("raw veneer configuration is invalid: %s", strings.Join(validationErrs, ","))
return fmt.Errorf("raw template configuration is invalid: %s", strings.Join(validationErrs, ","))
}

// build the container command
Expand All @@ -201,7 +202,7 @@ func (rb *RawBuilder) Build(dir string, vd VeneerDefinition) error {
"--rm",
"-v",
fmt.Sprintf("%s:%s:Z", rb.builderCfg.CurrentDirectory, rb.builderCfg.ContainerCfg.WorkingDir),
"--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?
"--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?
rb.builderCfg.ContainerCfg.BaseImage,
path.Join(rb.builderCfg.ContainerCfg.WorkingDir, rawConfig.Input))

Expand All @@ -224,39 +225,39 @@ func NewCustomBuilder(builderCfg BuilderConfig) *CustomBuilder {
}
}

func (cb *CustomBuilder) Build(dir string, vd VeneerDefinition) error {
if vd.Schema != CustomVeneerBuilderSchema {
return fmt.Errorf("schema %q does not match the custom veneer builder schema %q", vd.Schema, CustomVeneerBuilderSchema)
func (cb *CustomBuilder) Build(dir string, td TemplateDefinition) error {
if td.Schema != CustomBuilderSchema {
return fmt.Errorf("schema %q does not match the custom template builder schema %q", td.Schema, CustomBuilderSchema)
}
// Parse out the raw veneer configuration
customConfig := &CustomVeneerConfig{}
err := json.Unmarshal(vd.Config, customConfig)
// Parse out the raw template configuration
customConfig := &CustomConfig{}
err := yaml.UnmarshalStrict(td.Config, customConfig)
if err != nil {
return fmt.Errorf("unmarshalling custom veneer config: %w", err)
return fmt.Errorf("unmarshalling custom template config: %w", err)
}

// validate the custom config fields
valid := true
validationErrs := []string{}
if customConfig.Command == "" {
valid = false
validationErrs = append(validationErrs, "custom veneer config must have a non-empty command (veneerDefinition.config.command)")
validationErrs = append(validationErrs, "custom template config must have a non-empty command (templateDefinition.config.command)")
}

if customConfig.Output == "" {
valid = false
validationErrs = append(validationErrs, "custom veneer config must have a non-empty output (veneerDefinition.config.output)")
validationErrs = append(validationErrs, "custom template config must have a non-empty output (templateDefinition.config.output)")
}

if !valid {
return fmt.Errorf("custom veneer configuration is invalid: %s", strings.Join(validationErrs, ","))
return fmt.Errorf("custom template configuration is invalid: %s", strings.Join(validationErrs, ","))
}
// build the command to execute
cmd := exec.Command(customConfig.Command, customConfig.Args...)
cmd.Dir = cb.builderCfg.CurrentDirectory

// custom veneer should output a valid FBC to STDOUT so we can
// build the FBC just like all the other veneers.
// custom template should output a valid FBC to STDOUT so we can
// build the FBC just like all the other templates.
return build(cmd, path.Join(dir, customConfig.Output), cb.builderCfg.OutputType)
}

Expand Down
Loading

0 comments on commit 57a959d

Please sign in to comment.