Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export parsed composite specs #1139

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 19 additions & 30 deletions alpha/template/composite/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"path/filepath"
Expand All @@ -14,23 +13,6 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
)

type BuilderMap map[string]Builder

type CatalogBuilderMap map[string]BuilderMap

type builderFunc func(BuilderConfig) Builder

type Template struct {
catalogFile io.Reader
contributionFile io.Reader
validate bool
outputType string
registry image.Registry
registeredBuilders map[string]builderFunc
}

type TemplateOption func(t *Template)

func WithCatalogFile(catalogFile io.Reader) TemplateOption {
return func(t *Template) {
t.catalogFile = catalogFile
Expand Down Expand Up @@ -79,10 +61,6 @@ func NewTemplate(opts ...TemplateOption) *Template {
return temp
}

type HttpGetter interface {
Get(url string) (*http.Response, error)
}

// FetchCatalogConfig will fetch the catalog configuration file from the given path.
// The path can be a local file path OR a URL that returns the raw contents of the catalog
// configuration file.
Expand All @@ -100,7 +78,7 @@ func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, erro
}
} else {
// Evalute remote catalog config
// If URi is valid, execute fetch
// If URI is valid, execute fetch
tempResp, err := httpGetter.Get(catalogURI.String())
if err != nil {
return nil, fmt.Errorf("fetching remote catalog config file %q: %v", path, err)
Expand All @@ -111,26 +89,37 @@ func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, erro
return tempCatalog, nil
}

// TODO(everettraven): do we need the context here? If so, how should it be used?
func (t *Template) Render(ctx context.Context, validate bool) error {
func (t *Template) Parse() (*Specs, error) {
var s Specs

catalogFile, err := t.parseCatalogsSpec()
catalogSpec, err := t.parseCatalogsSpec()
if err != nil {
return err
return nil, err
}
s.CatalogSpec = catalogSpec

contributionSpec, err := t.parseContributionSpec()
if err != nil {
return nil, err
}
s.ContributionSpec = contributionSpec

return &s, nil
}

contributionFile, err := t.parseContributionSpec()
func (t *Template) Render(ctx context.Context, validate bool) error {
specs, err := t.Parse()
if err != nil {
return err
}

catalogBuilderMap, err := t.newCatalogBuilderMap(catalogFile.Catalogs, t.outputType)
catalogBuilderMap, err := t.newCatalogBuilderMap(specs.CatalogSpec.Catalogs, t.outputType)
if err != nil {
return err
}

// TODO(everettraven): should we return aggregated errors?
for _, component := range contributionFile.Components {
for _, component := range specs.ContributionSpec.Components {
if builderMap, ok := (*catalogBuilderMap)[component.Name]; ok {
if builder, ok := builderMap[component.Strategy.Template.Schema]; ok {
// run the builder corresponding to the schema
Expand Down
34 changes: 33 additions & 1 deletion alpha/template/composite/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package composite

import "encoding/json"
import (
"encoding/json"
"io"
"net/http"

"github.com/operator-framework/operator-registry/pkg/image"
)

type TemplateDefinition struct {
Schema string
Expand All @@ -27,3 +33,29 @@ type CustomConfig struct {
Args []string
Output string
}

type BuilderMap map[string]Builder

type CatalogBuilderMap map[string]BuilderMap

type builderFunc func(BuilderConfig) Builder

type Template struct {
catalogFile io.Reader
contributionFile io.Reader
validate bool
outputType string
registry image.Registry
registeredBuilders map[string]builderFunc
}

type TemplateOption func(t *Template)

type Specs struct {
CatalogSpec *CatalogConfig
ContributionSpec *CompositeConfig
}

type HttpGetter interface {
Get(url string) (*http.Response, error)
}