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

Bug 1781366: feat(resolver): fallback to csv parsing if grcp api does not contain info #1194

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 29 additions & 7 deletions pkg/controller/registry/resolver/operators.go
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought -- but if JSONPath can let us query the provided and required APIs w/o unmarshaling the entire CSV, should we use it to more accurately verify the content of the bundle fields?

(this question shouldn't block the PR)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that if the grpc has any provide/required apis, we just trust that (gives us more freedom on the side of the registry going forward).

// 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
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