Skip to content

Commit d02b0b6

Browse files
authored
export parsed composite specs (#1139)
Signed-off-by: Jordan Keister <[email protected]>
1 parent 56771f7 commit d02b0b6

File tree

2 files changed

+52
-31
lines changed

2 files changed

+52
-31
lines changed

Diff for: alpha/template/composite/composite.go

+19-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"net/http"
98
"net/url"
109
"os"
1110
"path/filepath"
@@ -14,23 +13,6 @@ import (
1413
"k8s.io/apimachinery/pkg/util/yaml"
1514
)
1615

17-
type BuilderMap map[string]Builder
18-
19-
type CatalogBuilderMap map[string]BuilderMap
20-
21-
type builderFunc func(BuilderConfig) Builder
22-
23-
type Template struct {
24-
catalogFile io.Reader
25-
contributionFile io.Reader
26-
validate bool
27-
outputType string
28-
registry image.Registry
29-
registeredBuilders map[string]builderFunc
30-
}
31-
32-
type TemplateOption func(t *Template)
33-
3416
func WithCatalogFile(catalogFile io.Reader) TemplateOption {
3517
return func(t *Template) {
3618
t.catalogFile = catalogFile
@@ -79,10 +61,6 @@ func NewTemplate(opts ...TemplateOption) *Template {
7961
return temp
8062
}
8163

82-
type HttpGetter interface {
83-
Get(url string) (*http.Response, error)
84-
}
85-
8664
// FetchCatalogConfig will fetch the catalog configuration file from the given path.
8765
// The path can be a local file path OR a URL that returns the raw contents of the catalog
8866
// configuration file.
@@ -100,7 +78,7 @@ func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, erro
10078
}
10179
} else {
10280
// Evalute remote catalog config
103-
// If URi is valid, execute fetch
81+
// If URI is valid, execute fetch
10482
tempResp, err := httpGetter.Get(catalogURI.String())
10583
if err != nil {
10684
return nil, fmt.Errorf("fetching remote catalog config file %q: %v", path, err)
@@ -111,26 +89,37 @@ func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, erro
11189
return tempCatalog, nil
11290
}
11391

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

117-
catalogFile, err := t.parseCatalogsSpec()
95+
catalogSpec, err := t.parseCatalogsSpec()
11896
if err != nil {
119-
return err
97+
return nil, err
98+
}
99+
s.CatalogSpec = catalogSpec
100+
101+
contributionSpec, err := t.parseContributionSpec()
102+
if err != nil {
103+
return nil, err
120104
}
105+
s.ContributionSpec = contributionSpec
106+
107+
return &s, nil
108+
}
121109

122-
contributionFile, err := t.parseContributionSpec()
110+
func (t *Template) Render(ctx context.Context, validate bool) error {
111+
specs, err := t.Parse()
123112
if err != nil {
124113
return err
125114
}
126115

127-
catalogBuilderMap, err := t.newCatalogBuilderMap(catalogFile.Catalogs, t.outputType)
116+
catalogBuilderMap, err := t.newCatalogBuilderMap(specs.CatalogSpec.Catalogs, t.outputType)
128117
if err != nil {
129118
return err
130119
}
131120

132121
// TODO(everettraven): should we return aggregated errors?
133-
for _, component := range contributionFile.Components {
122+
for _, component := range specs.ContributionSpec.Components {
134123
if builderMap, ok := (*catalogBuilderMap)[component.Name]; ok {
135124
if builder, ok := builderMap[component.Strategy.Template.Schema]; ok {
136125
// run the builder corresponding to the schema

Diff for: alpha/template/composite/types.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package composite
22

3-
import "encoding/json"
3+
import (
4+
"encoding/json"
5+
"io"
6+
"net/http"
7+
8+
"github.com/operator-framework/operator-registry/pkg/image"
9+
)
410

511
type TemplateDefinition struct {
612
Schema string
@@ -27,3 +33,29 @@ type CustomConfig struct {
2733
Args []string
2834
Output string
2935
}
36+
37+
type BuilderMap map[string]Builder
38+
39+
type CatalogBuilderMap map[string]BuilderMap
40+
41+
type builderFunc func(BuilderConfig) Builder
42+
43+
type Template struct {
44+
catalogFile io.Reader
45+
contributionFile io.Reader
46+
validate bool
47+
outputType string
48+
registry image.Registry
49+
registeredBuilders map[string]builderFunc
50+
}
51+
52+
type TemplateOption func(t *Template)
53+
54+
type Specs struct {
55+
CatalogSpec *CatalogConfig
56+
ContributionSpec *CompositeConfig
57+
}
58+
59+
type HttpGetter interface {
60+
Get(url string) (*http.Response, error)
61+
}

0 commit comments

Comments
 (0)