Skip to content

Commit 1510c73

Browse files
committed
Address feedbacks (second round)
Signed-off-by: Vu Dinh <[email protected]>
1 parent 85c26c9 commit 1510c73

File tree

11 files changed

+173
-210
lines changed

11 files changed

+173
-210
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dependencies:
22
- type: olm.package
3-
packageName: test-operator
4-
version: ">0.2.0"
3+
packageName: testoperator
4+
version: "> 0.2.0"

pkg/api/registry.pb.go

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

pkg/api/registry.proto

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ service Registry {
1212
rpc GetChannelEntriesThatProvide(GetAllProvidersRequest) returns (stream ChannelEntry) {}
1313
rpc GetLatestChannelEntriesThatProvide(GetLatestProvidersRequest) returns (stream ChannelEntry) {}
1414
rpc GetDefaultBundleThatProvides(GetDefaultProviderRequest) returns (Bundle) {}
15-
rpc ListBundles(ListBundlesRequest) returns (stream Bundle) {}
15+
rpc ListBundles(ListBundlesRequest) returns (stream Bundle) {}
1616
}
1717

1818

@@ -40,10 +40,7 @@ message GroupVersionKind{
4040

4141
message Dependency{
4242
string type = 1;
43-
string name = 2;
44-
string group = 3;
45-
string version = 4;
46-
string kind = 5;
43+
string value = 2;
4744
}
4845

4946
message Bundle{
@@ -57,7 +54,7 @@ message Bundle{
5754
repeated GroupVersionKind requiredApis = 8;
5855
string version = 9;
5956
string skipRange = 10;
60-
repeated Dependency dependencies = 11;
57+
repeated Dependency dependencies = 11;
6158
}
6259

6360
message ChannelEntry{

pkg/registry/bundle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Bundle struct {
3535
BundleImage string
3636
csv *ClusterServiceVersion
3737
crds []*v1beta1.CustomResourceDefinition
38-
Dependencies []Dependency
38+
Dependencies []*Dependency
3939
cacheStale bool
4040
}
4141

pkg/registry/populator.go

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package registry
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"fmt"
78
"io/ioutil"
@@ -16,9 +17,9 @@ import (
1617
"github.com/operator-framework/operator-registry/pkg/image"
1718
)
1819

19-
const (
20-
DependenciesFileName = "dependencies.yaml"
21-
)
20+
type Dependencies struct {
21+
RawMessage []map[string]string `json:"dependencies" yaml:"dependencies"`
22+
}
2223

2324
// DirectoryPopulator loads an unpacked operator bundle from a directory into the database.
2425
type DirectoryPopulator struct {
@@ -62,13 +63,12 @@ func (i *DirectoryPopulator) Populate(mode Mode) error {
6263
log.Info("found annotations file searching for csv")
6364
continue
6465
}
65-
if f.Name() == DependenciesFileName {
66-
err = decodeFile(filepath.Join(metadata, f.Name()), dependenciesFile)
67-
if err != nil {
68-
log.Info("unable to parse dependencies.yaml file")
69-
} else {
70-
log.Info("found dependencies file searching for csv")
71-
}
66+
67+
err = parseDependenciesFile(filepath.Join(metadata, f.Name()), dependenciesFile)
68+
if err != nil || len(dependenciesFile.Dependencies) < 1 {
69+
continue
70+
} else {
71+
log.Info("found dependencies file searching for csv")
7272
}
7373
}
7474

@@ -112,7 +112,7 @@ func (i *DirectoryPopulator) loadManifests(manifests string, annotationsFile *An
112112
// set the bundleimage on the bundle
113113
bundle.BundleImage = i.to.String()
114114
// set the dependencies on the bundle
115-
bundle.Dependencies = dependenciesFile.Dependencies
115+
bundle.Dependencies = dependenciesFile.GetDependencies()
116116

117117
bundle.Name = csvName
118118
bundle.Package = annotationsFile.Annotations.PackageName
@@ -340,3 +340,36 @@ func decodeFile(path string, into interface{}) error {
340340

341341
return decoder.Decode(into)
342342
}
343+
344+
func parseDependenciesFile(path string, depFile *DependenciesFile) error {
345+
deps := Dependencies{}
346+
err := decodeFile(path, &deps)
347+
if err != nil || len(deps.RawMessage) == 0 {
348+
return fmt.Errorf("Unable to decode the dependencies file %s", path)
349+
}
350+
depList := []Dependency{}
351+
for _, v := range deps.RawMessage {
352+
// convert map to json
353+
jsonStr, _ := json.Marshal(v)
354+
fmt.Println(string(jsonStr))
355+
356+
// Check dependency type
357+
dep := Dependency{}
358+
err := json.Unmarshal(jsonStr, &dep)
359+
if err != nil {
360+
return err
361+
}
362+
363+
switch dep.GetType() {
364+
case "olm.gvk", "olm.package":
365+
dep.Value = string(jsonStr)
366+
default:
367+
return fmt.Errorf("Unsupported dependency type %s", dep.GetType())
368+
}
369+
depList = append(depList, dep)
370+
}
371+
372+
depFile.Dependencies = depList
373+
374+
return nil
375+
}

pkg/registry/populator_test.go

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ func TestQuerierForImage(t *testing.T) {
118118
SkipRange: "",
119119
Dependencies: []*api.Dependency{
120120
{
121-
Type: "olm.gvk",
122-
Group: "testapi.coreos.com",
123-
Kind: "testapi",
124-
Version: "v1",
121+
Type: "olm.gvk",
122+
Value: `{"group":"testapi.coreos.com","kind":"testapi","type":"olm.gvk","version":"v1"}`,
125123
},
126124
},
127125
ProvidedApis: []*api.GroupVersionKind{
@@ -351,15 +349,12 @@ func TestQuerierForDependencies(t *testing.T) {
351349

352350
expectedDependencies := []*api.Dependency{
353351
{
354-
Type: "olm.package",
355-
Name: "test-operator",
356-
Version: ">0.2.0",
352+
Type: "olm.package",
353+
Value: `{"packageName":"testoperator","type":"olm.package","version":"\u003e 0.2.0"}`,
357354
},
358355
{
359-
Type: "olm.gvk",
360-
Group: "testapi.coreos.com",
361-
Kind: "testapi",
362-
Version: "v1",
356+
Type: "olm.gvk",
357+
Value: `{"group":"testapi.coreos.com","kind":"testapi","type":"olm.gvk","version":"v1"}`,
363358
},
364359
}
365360

@@ -401,15 +396,12 @@ func TestListBundles(t *testing.T) {
401396

402397
expectedDependencies := []*api.Dependency{
403398
{
404-
Type: "olm.package",
405-
Name: "test-operator",
406-
Version: ">0.2.0",
399+
Type: "olm.package",
400+
Value: `{"packageName":"testoperator","type":"olm.package","version":"\u003e 0.2.0"}`,
407401
},
408402
{
409-
Type: "olm.gvk",
410-
Group: "testapi.coreos.com",
411-
Kind: "testapi",
412-
Version: "v1",
403+
Type: "olm.gvk",
404+
Value: `{"group":"testapi.coreos.com","kind":"testapi","type":"olm.gvk","version":"v1"}`,
413405
},
414406
}
415407

@@ -418,7 +410,6 @@ func TestListBundles(t *testing.T) {
418410
require.NoError(t, err)
419411
for _, b := range bundles {
420412
dep := b.Dependencies
421-
fmt.Printf("Dep: %v\n", dep)
422413
dependencies = append(dependencies, dep...)
423414
}
424415
require.ElementsMatch(t, expectedDependencies, dependencies)

0 commit comments

Comments
 (0)