Skip to content

Commit d89bc4d

Browse files
Merge pull request #1951 from dinhxuanvu/pinned-skips
Bug1906056: fix(resolver): Allow skipped versions to be installed initially
2 parents 569d8c5 + 1a171b8 commit d89bc4d

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
@@ -1357,14 +1357,14 @@ func TestSolveOperators_WithoutDeprecated(t *testing.T) {
13571357
assert.IsType(t, solver.NotSatisfiable{}, err)
13581358
}
13591359

1360-
func TestSolveOperators_WithSkips(t *testing.T) {
1360+
func TestSolveOperators_WithSkipsAndStartingCSV(t *testing.T) {
13611361
APISet := APISet{opregistry.APIKey{"g", "v", "k", "ks"}: struct{}{}}
13621362
Provides := APISet
13631363

13641364
namespace := "olm"
13651365
catalog := registry.CatalogKey{"community", namespace}
13661366

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

13701370
opToAddVersionDeps := []*api.Dependency{
@@ -1375,6 +1375,8 @@ func TestSolveOperators_WithSkips(t *testing.T) {
13751375
}
13761376

13771377
opB := genOperator("packageB.v1", "1.0.0", "", "packageB", "alpha", "community", "olm", nil, nil, opToAddVersionDeps, "", false)
1378+
opB2 := genOperator("packageB.v2", "2.0.0", "", "packageB", "alpha", "community", "olm", nil, nil, opToAddVersionDeps, "", false)
1379+
opB2.skips = []string{"packageB.v1"}
13781380
op1 := genOperator("packageA.v1", "1.0.0", "", "packageA", "alpha", "community", "olm", nil, Provides, nil, "", false)
13791381
op2 := genOperator("packageA.v2", "2.0.0", "packageA.v1", "packageA", "alpha", "community", "olm", nil, Provides, nil, "", false)
13801382
op3 := genOperator("packageA.v3", "3.0.0", "packageA.v2", "packageA", "alpha", "community", "olm", nil, Provides, nil, "", false)
@@ -1395,7 +1397,7 @@ func TestSolveOperators_WithSkips(t *testing.T) {
13951397
Name: "community",
13961398
},
13971399
operators: []*Operator{
1398-
opB, op1, op2, op3, op4, op5, op6,
1400+
opB, opB2, op1, op2, op3, op4, op5, op6,
13991401
},
14001402
},
14011403
},
@@ -1407,10 +1409,50 @@ func TestSolveOperators_WithSkips(t *testing.T) {
14071409

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

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

0 commit comments

Comments
 (0)