Skip to content

Commit 09a43ac

Browse files
joelanfordanik120
authored andcommitted
alpha/declcfg: re-encode olm.bundle.object data to JSON when loading (#874)
Maintainers of file-based catalogs often have YAML manifests for their bundle objects. However the GRPC API expects the CSV and bundle objects to be presented with a JSON encoding. This commit updates the FBC loading code such that data for all olm.bundle.object properties are converted to JSON. Signed-off-by: Joe Lanford <[email protected]> Upstream-repository: operator-registry Upstream-commit: aa2afc95f3063fad355a426252b7d62a47cb191a
1 parent dc5f6de commit 09a43ac

File tree

3 files changed

+36
-8
lines changed
  • staging/operator-registry/alpha/declcfg
  • vendor/github.com/operator-framework/operator-registry/alpha/declcfg

3 files changed

+36
-8
lines changed

staging/operator-registry/alpha/declcfg/load.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,23 @@ func readBundleObjects(bundles []Bundle, root fs.FS, path string) error {
8787
for bi, b := range bundles {
8888
props, err := property.Parse(b.Properties)
8989
if err != nil {
90-
return fmt.Errorf("parse properties for bundle %q: %v", b.Name, err)
90+
return fmt.Errorf("package %q, bundle %q: parse properties: %v", b.Package, b.Name, err)
9191
}
9292
for oi, obj := range props.BundleObjects {
93+
objID := fmt.Sprintf(" %q", obj.GetRef())
94+
if !obj.IsRef() {
95+
objID = fmt.Sprintf("[%d]", oi)
96+
}
97+
9398
d, err := obj.GetData(root, filepath.Dir(path))
9499
if err != nil {
95-
return fmt.Errorf("get data for bundle object[%d]: %v", oi, err)
100+
return fmt.Errorf("package %q, bundle %q: get data for bundle object%s: %v", b.Package, b.Name, objID, err)
101+
}
102+
objJson, err := yaml.ToJSON(d)
103+
if err != nil {
104+
return fmt.Errorf("package %q, bundle %q: convert object%s to JSON: %v", b.Package, b.Name, objID, err)
96105
}
97-
bundles[bi].Objects = append(bundles[bi].Objects, string(d))
106+
bundles[bi].Objects = append(bundles[bi].Objects, string(objJson))
98107
}
99108
bundles[bi].CsvJSON = extractCSV(bundles[bi].Objects)
100109
}

staging/operator-registry/alpha/declcfg/load_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
12+
"k8s.io/apimachinery/pkg/util/yaml"
1213

1314
"github.com/operator-framework/operator-registry/alpha/property"
1415
)
@@ -188,8 +189,8 @@ func TestLoadFS(t *testing.T) {
188189
{Type: "olm.bundle.object", Value: json.RawMessage(`{"ref":"etcdoperator.v0.6.1.clusterserviceversion.yaml"}`)},
189190
},
190191
RelatedImages: []RelatedImage{{Name: "etcdv0.6.1", Image: "quay.io/coreos/etcd-operator@sha256:bd944a211eaf8f31da5e6d69e8541e7cada8f16a9f7a5a570b22478997819943"}},
191-
Objects: []string{string(etcdCSV.Data)},
192-
CsvJSON: string(etcdCSV.Data),
192+
Objects: []string{toJSON(t, etcdCSV.Data)},
193+
CsvJSON: toJSON(t, etcdCSV.Data),
193194
},
194195
{
195196
Schema: "olm.bundle",
@@ -280,6 +281,15 @@ func TestLoadFS(t *testing.T) {
280281
}
281282
}
282283

284+
func toJSON(t *testing.T, in []byte) string {
285+
t.Helper()
286+
out, err := yaml.ToJSON(in)
287+
if err != nil {
288+
t.Fatalf("failed converting testdata to JSON: %v", err)
289+
}
290+
return string(out)
291+
}
292+
283293
var (
284294
invalidBundle = &fstest.MapFile{
285295
Data: []byte(`{"schema": "olm.bundle","relatedImages": {}}`),

vendor/github.com/operator-framework/operator-registry/alpha/declcfg/load.go

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)