Skip to content

Commit 1a171b8

Browse files
committed
fix(resolver): Allow skipped versions to be installed initially
Currently, the resolver will filter all skipped versions so they cannot be installed under any conditions. This behavior is a slight change from the older resolver which allows the skipped versions to be installed if they are chosen in `startingCSV`. With this change, the resolver will allow skipped versions to be installed if specified in `startingCSV` during the initial installation. Signed-off-by: Vu Dinh <[email protected]>
1 parent 4a9d02b commit 1a171b8

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

pkg/controller/registry/resolver/resolver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func (r *SatResolver) SolveOperators(namespaces []string, csvs []*v1alpha1.Clust
9797

9898
// if no operator is installed and we have a startingCSV, filter for it
9999
if current == nil && len(sub.Spec.StartingCSV) > 0 {
100+
predicates = append(predicates, WithCSVName(sub.Spec.StartingCSV))
100101
channelFilter = append(channelFilter, WithCSVName(sub.Spec.StartingCSV))
101102
startingCSVs[sub.Spec.StartingCSV] = struct{}{}
102103
}

pkg/controller/registry/resolver/resolver_test.go

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,14 +1354,14 @@ func TestSolveOperators_WithoutDeprecated(t *testing.T) {
13541354
assert.IsType(t, solver.NotSatisfiable{}, err)
13551355
}
13561356

1357-
func TestSolveOperators_WithSkips(t *testing.T) {
1357+
func TestSolveOperators_WithSkipsAndStartingCSV(t *testing.T) {
13581358
APISet := APISet{opregistry.APIKey{"g", "v", "k", "ks"}: struct{}{}}
13591359
Provides := APISet
13601360

13611361
namespace := "olm"
13621362
catalog := registry.CatalogKey{"community", namespace}
13631363

1364-
newSub := newSub(namespace, "packageB", "alpha", catalog)
1364+
newSub := newSub(namespace, "packageB", "alpha", catalog, withStartingCSV("packageB.v1"))
13651365
subs := []*v1alpha1.Subscription{newSub}
13661366

13671367
opToAddVersionDeps := []*api.Dependency{
@@ -1372,6 +1372,8 @@ func TestSolveOperators_WithSkips(t *testing.T) {
13721372
}
13731373

13741374
opB := genOperator("packageB.v1", "1.0.0", "", "packageB", "alpha", "community", "olm", nil, nil, opToAddVersionDeps, "", false)
1375+
opB2 := genOperator("packageB.v2", "2.0.0", "", "packageB", "alpha", "community", "olm", nil, nil, opToAddVersionDeps, "", false)
1376+
opB2.skips = []string{"packageB.v1"}
13751377
op1 := genOperator("packageA.v1", "1.0.0", "", "packageA", "alpha", "community", "olm", nil, Provides, nil, "", false)
13761378
op2 := genOperator("packageA.v2", "2.0.0", "packageA.v1", "packageA", "alpha", "community", "olm", nil, Provides, nil, "", false)
13771379
op3 := genOperator("packageA.v3", "3.0.0", "packageA.v2", "packageA", "alpha", "community", "olm", nil, Provides, nil, "", false)
@@ -1392,7 +1394,7 @@ func TestSolveOperators_WithSkips(t *testing.T) {
13921394
Name: "community",
13931395
},
13941396
operators: []*Operator{
1395-
opB, op1, op2, op3, op4, op5, op6,
1397+
opB, opB2, op1, op2, op3, op4, op5, op6,
13961398
},
13971399
},
13981400
},
@@ -1404,10 +1406,50 @@ func TestSolveOperators_WithSkips(t *testing.T) {
14041406

14051407
operators, err := satResolver.SolveOperators([]string{"olm"}, nil, subs)
14061408
assert.NoError(t, err)
1409+
opB.SourceInfo().StartingCSV = "packageB.v1"
1410+
expected := OperatorSet{
1411+
"packageB.v1": opB,
1412+
"packageA.v6": op6,
1413+
}
1414+
require.EqualValues(t, expected, operators)
1415+
}
1416+
1417+
func TestSolveOperators_WithSkips(t *testing.T) {
1418+
namespace := "olm"
1419+
catalog := registry.CatalogKey{"community", namespace}
14071420

1421+
newSub := newSub(namespace, "packageB", "alpha", catalog)
1422+
subs := []*v1alpha1.Subscription{newSub}
1423+
1424+
opB := genOperator("packageB.v1", "1.0.0", "", "packageB", "alpha", "community", "olm", nil, nil, nil, "", false)
1425+
opB2 := genOperator("packageB.v2", "2.0.0", "", "packageB", "alpha", "community", "olm", nil, nil, nil, "", false)
1426+
opB2.skips = []string{"packageB.v1"}
1427+
1428+
fakeNamespacedOperatorCache := NamespacedOperatorCache{
1429+
snapshots: map[registry.CatalogKey]*CatalogSnapshot{
1430+
registry.CatalogKey{
1431+
Namespace: "olm",
1432+
Name: "community",
1433+
}: {
1434+
key: registry.CatalogKey{
1435+
Namespace: "olm",
1436+
Name: "community",
1437+
},
1438+
operators: []*Operator{
1439+
opB, opB2,
1440+
},
1441+
},
1442+
},
1443+
}
1444+
satResolver := SatResolver{
1445+
cache: getFakeOperatorCache(fakeNamespacedOperatorCache),
1446+
log: logrus.New(),
1447+
}
1448+
1449+
operators, err := satResolver.SolveOperators([]string{"olm"}, nil, subs)
1450+
assert.NoError(t, err)
14081451
expected := OperatorSet{
1409-
"packageB.v1": genOperator("packageB.v1", "1.0.0", "", "packageB", "alpha", "community", "olm", nil, nil, opToAddVersionDeps, "", false),
1410-
"packageA.v6": genOperator("packageA.v6", "6.0.0", "packageA.v5", "packageA", "alpha", "community", "olm", nil, Provides, nil, "", false),
1452+
"packageB.v2": opB2,
14111453
}
14121454
require.EqualValues(t, expected, operators)
14131455
}

0 commit comments

Comments
 (0)