Skip to content

Commit

Permalink
Merge pull request #1194 from ecordell/csv-fallback
Browse files Browse the repository at this point in the history
Bug 1781366: feat(resolver): fallback to csv parsing if grcp api does not contain info
  • Loading branch information
openshift-merge-robot authored Dec 12, 2019
2 parents 372a686 + a106f7c commit 6057571
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 7 deletions.
36 changes: 29 additions & 7 deletions pkg/controller/registry/resolver/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV stri
if err != nil {
v = nil
}

provided := APISet{}
for _, gvk := range bundle.ProvidedApis {
provided[registry.APIKey{Plural: gvk.Plural, Group: gvk.Group, Kind: gvk.Kind, Version: gvk.Version}] = struct{}{}
Expand All @@ -266,6 +265,34 @@ func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV stri
for _, gvk := range bundle.RequiredApis {
required[registry.APIKey{Plural: gvk.Plural, Group: gvk.Group, Kind: gvk.Kind, Version: gvk.Version}] = struct{}{}
}
sourceInfo := &OperatorSourceInfo{
Package: bundle.PackageName,
Channel: bundle.ChannelName,
StartingCSV: startingCSV,
Catalog: sourceKey,
}

// legacy support - if the grpc api doesn't contain the information we need, fallback to csv parsing
if len(required) == 0 && len(provided) == 0 {
// fallback to csv parsing
if bundle.CsvJson == "" {
return nil, fmt.Errorf("couldn't parse bundle")
}

csv := &v1alpha1.ClusterServiceVersion{}
if err := json.Unmarshal([]byte(bundle.CsvJson), csv); err != nil {
return nil, err
}

op, err := NewOperatorFromV1Alpha1CSV(csv)
if err != nil {
return nil, err
}
op.sourceInfo = sourceInfo
op.bundle = bundle
op.replaces = r
return op, nil
}

return &Operator{
name: csv.GetName(),
Expand All @@ -274,12 +301,7 @@ func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV stri
providedAPIs: provided,
requiredAPIs: required,
bundle: bundle,
sourceInfo: &OperatorSourceInfo{
Package: bundle.PackageName,
Channel: bundle.ChannelName,
StartingCSV: startingCSV,
Catalog: sourceKey,
},
sourceInfo: sourceInfo,
}, nil
}

Expand Down
55 changes: 55 additions & 0 deletions pkg/controller/registry/resolver/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,14 @@ func TestNewOperatorFromBundle(t *testing.T) {
},
}

bundleWithAPIsUnextracted := &api.Bundle{
CsvName: "testBundle",
PackageName: "testPackage",
ChannelName: "testChannel",
CsvJson: string(csvJsonWithApis),
Object: []string{string(csvJsonWithApis), string(crdJson)},
}

type args struct {
bundle *api.Bundle
sourceKey CatalogKey
Expand Down Expand Up @@ -1119,6 +1127,53 @@ func TestNewOperatorFromBundle(t *testing.T) {
},
},
},
{
name: "BundleCsvFallback",
args: args{
bundle: bundleWithAPIsUnextracted,
sourceKey: CatalogKey{Name: "source", Namespace: "testNamespace"},
replaces: "replaced",
},
want: &Operator{
name: "testCSV",
providedAPIs: APISet{
opregistry.APIKey{
Group: "crd.group.com",
Version: "v1",
Kind: "OwnedCRD",
Plural: "owneds",
}: struct{}{},
opregistry.APIKey{
Group: "apis.group.com",
Version: "v1",
Kind: "OwnedAPI",
Plural: "ownedapis",
}: struct{}{},
},
requiredAPIs: APISet{
opregistry.APIKey{
Group: "crd.group.com",
Version: "v1",
Kind: "RequiredCRD",
Plural: "requireds",
}: struct{}{},
opregistry.APIKey{
Group: "apis.group.com",
Version: "v1",
Kind: "RequiredAPI",
Plural: "requiredapis",
}: struct{}{},
},
bundle: bundleWithAPIsUnextracted,
replaces: "replaced",
version: &version.Version,
sourceInfo: &OperatorSourceInfo{
Package: "testPackage",
Channel: "testChannel",
Catalog: CatalogKey{"source", "testNamespace"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 6057571

Please sign in to comment.