Skip to content

Commit 6057571

Browse files
Merge pull request #1194 from ecordell/csv-fallback
Bug 1781366: feat(resolver): fallback to csv parsing if grcp api does not contain info
2 parents 372a686 + a106f7c commit 6057571

File tree

2 files changed

+84
-7
lines changed

2 files changed

+84
-7
lines changed

pkg/controller/registry/resolver/operators.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV stri
257257
if err != nil {
258258
v = nil
259259
}
260-
261260
provided := APISet{}
262261
for _, gvk := range bundle.ProvidedApis {
263262
provided[registry.APIKey{Plural: gvk.Plural, Group: gvk.Group, Kind: gvk.Kind, Version: gvk.Version}] = struct{}{}
@@ -266,6 +265,34 @@ func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV stri
266265
for _, gvk := range bundle.RequiredApis {
267266
required[registry.APIKey{Plural: gvk.Plural, Group: gvk.Group, Kind: gvk.Kind, Version: gvk.Version}] = struct{}{}
268267
}
268+
sourceInfo := &OperatorSourceInfo{
269+
Package: bundle.PackageName,
270+
Channel: bundle.ChannelName,
271+
StartingCSV: startingCSV,
272+
Catalog: sourceKey,
273+
}
274+
275+
// legacy support - if the grpc api doesn't contain the information we need, fallback to csv parsing
276+
if len(required) == 0 && len(provided) == 0 {
277+
// fallback to csv parsing
278+
if bundle.CsvJson == "" {
279+
return nil, fmt.Errorf("couldn't parse bundle")
280+
}
281+
282+
csv := &v1alpha1.ClusterServiceVersion{}
283+
if err := json.Unmarshal([]byte(bundle.CsvJson), csv); err != nil {
284+
return nil, err
285+
}
286+
287+
op, err := NewOperatorFromV1Alpha1CSV(csv)
288+
if err != nil {
289+
return nil, err
290+
}
291+
op.sourceInfo = sourceInfo
292+
op.bundle = bundle
293+
op.replaces = r
294+
return op, nil
295+
}
269296

270297
return &Operator{
271298
name: csv.GetName(),
@@ -274,12 +301,7 @@ func NewOperatorFromBundle(bundle *api.Bundle, replaces string, startingCSV stri
274301
providedAPIs: provided,
275302
requiredAPIs: required,
276303
bundle: bundle,
277-
sourceInfo: &OperatorSourceInfo{
278-
Package: bundle.PackageName,
279-
Channel: bundle.ChannelName,
280-
StartingCSV: startingCSV,
281-
Catalog: sourceKey,
282-
},
304+
sourceInfo: sourceInfo,
283305
}, nil
284306
}
285307

pkg/controller/registry/resolver/operators_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,14 @@ func TestNewOperatorFromBundle(t *testing.T) {
10191019
},
10201020
}
10211021

1022+
bundleWithAPIsUnextracted := &api.Bundle{
1023+
CsvName: "testBundle",
1024+
PackageName: "testPackage",
1025+
ChannelName: "testChannel",
1026+
CsvJson: string(csvJsonWithApis),
1027+
Object: []string{string(csvJsonWithApis), string(crdJson)},
1028+
}
1029+
10221030
type args struct {
10231031
bundle *api.Bundle
10241032
sourceKey CatalogKey
@@ -1119,6 +1127,53 @@ func TestNewOperatorFromBundle(t *testing.T) {
11191127
},
11201128
},
11211129
},
1130+
{
1131+
name: "BundleCsvFallback",
1132+
args: args{
1133+
bundle: bundleWithAPIsUnextracted,
1134+
sourceKey: CatalogKey{Name: "source", Namespace: "testNamespace"},
1135+
replaces: "replaced",
1136+
},
1137+
want: &Operator{
1138+
name: "testCSV",
1139+
providedAPIs: APISet{
1140+
opregistry.APIKey{
1141+
Group: "crd.group.com",
1142+
Version: "v1",
1143+
Kind: "OwnedCRD",
1144+
Plural: "owneds",
1145+
}: struct{}{},
1146+
opregistry.APIKey{
1147+
Group: "apis.group.com",
1148+
Version: "v1",
1149+
Kind: "OwnedAPI",
1150+
Plural: "ownedapis",
1151+
}: struct{}{},
1152+
},
1153+
requiredAPIs: APISet{
1154+
opregistry.APIKey{
1155+
Group: "crd.group.com",
1156+
Version: "v1",
1157+
Kind: "RequiredCRD",
1158+
Plural: "requireds",
1159+
}: struct{}{},
1160+
opregistry.APIKey{
1161+
Group: "apis.group.com",
1162+
Version: "v1",
1163+
Kind: "RequiredAPI",
1164+
Plural: "requiredapis",
1165+
}: struct{}{},
1166+
},
1167+
bundle: bundleWithAPIsUnextracted,
1168+
replaces: "replaced",
1169+
version: &version.Version,
1170+
sourceInfo: &OperatorSourceInfo{
1171+
Package: "testPackage",
1172+
Channel: "testChannel",
1173+
Catalog: CatalogKey{"source", "testNamespace"},
1174+
},
1175+
},
1176+
},
11221177
}
11231178
for _, tt := range tests {
11241179
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)