Skip to content

Commit 69881b6

Browse files
committed
validate fail for dupe skips+replaces channel entries
Signed-off-by: grokspawn <[email protected]>
1 parent b5c503a commit 69881b6

File tree

6 files changed

+29
-4
lines changed

6 files changed

+29
-4
lines changed

alpha/declcfg/declcfg_to_model.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package declcfg
22

33
import (
44
"fmt"
5+
"slices"
56

67
"github.com/blang/semver/v4"
78
"k8s.io/apimachinery/pkg/util/sets"
@@ -66,6 +67,14 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
6667
// This API is in alpha stage and it is subject to change.
6768
Properties: c.Properties,
6869
}
70+
for _, entry := range c.Entries {
71+
// invalid if there is a skips edge which matches a replacement edge
72+
if entry.Replaces != "" && len(entry.Skips) > 0 {
73+
if slices.Contains(entry.Skips, entry.Replaces) {
74+
return nil, fmt.Errorf("invalid package %q, channel %q: entry %q has identical replaces and skips: %q", c.Package, c.Name, entry.Name, entry.Replaces)
75+
}
76+
}
77+
}
6978

7079
cde := sets.Set[string]{}
7180
for _, entry := range c.Entries {

alpha/declcfg/declcfg_to_model_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,22 @@ func TestConvertToModel(t *testing.T) {
442442
},
443443
},
444444
},
445+
{
446+
name: "Error/DuplicateSkipsReplaces",
447+
assertion: hasError(`invalid package "foo", channel "alpha": entry "foo.v0.1.0" has identical replaces and skips: "foo.v0.0.1"`),
448+
cfg: DeclarativeConfig{
449+
Packages: []Package{
450+
addPackageProperties(
451+
newTestPackage("foo", "alpha", svgSmallCircle),
452+
[]property.Property{
453+
{Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")},
454+
},
455+
),
456+
},
457+
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0", Replaces: "foo.v0.0.1", Skips: []string{"foo.v0.0.1"}})},
458+
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
459+
},
460+
},
445461
}
446462

447463
for _, s := range specs {

pkg/cache/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ var validFS = fstest.MapFS{
402402
"name": "clusterwide-alpha",
403403
"entries": [
404404
{"name": "etcdoperator.v0.9.0"},
405-
{"name": "etcdoperator.v0.9.2-clusterwide", "replaces": "etcdoperator.v0.9.0", "skips": ["etcdoperator.v0.6.1","etcdoperator.v0.9.0"], "skipRange": ">=0.9.0 <=0.9.1"},
405+
{"name": "etcdoperator.v0.9.2-clusterwide", "replaces": "etcdoperator.v0.9.0", "skips": ["etcdoperator.v0.6.1"], "skipRange": ">=0.9.0 <=0.9.1"},
406406
{"name": "etcdoperator.v0.9.4-clusterwide", "replaces": "etcdoperator.v0.9.2-clusterwide"}
407407
]
408408
}

pkg/cache/json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestJSON_StableDigest(t *testing.T) {
2828
//
2929
// If validFS needs to change DO NOT CHANGE the json cache implementation
3030
// in the same pull request.
31-
require.Equal(t, "9adad9ff6cf54e4f", actualDigest)
31+
require.Equal(t, "563a1febb83cdbd6", actualDigest)
3232
}
3333

3434
func TestJSON_CheckIntegrity(t *testing.T) {

pkg/cache/pogrebv1_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestPogrebV1_StableDigest(t *testing.T) {
2828
//
2929
// If validFS needs to change DO NOT CHANGE the json cache implementation
3030
// in the same pull request.
31-
require.Equal(t, "485a767449dd66d4", actualDigest)
31+
require.Equal(t, "badb5551e9b35e68", actualDigest)
3232
}
3333

3434
func TestPogrebV1_CheckIntegrity(t *testing.T) {

pkg/cache/tar_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func Test_fsToTar(t *testing.T) {
4343
require.NoError(t, err)
4444
hasher := fnv.New64a()
4545
hasher.Write(i)
46-
require.Equal(t, "6f9eec5b366c557f", fmt.Sprintf("%x", hasher.Sum(nil)))
46+
require.Equal(t, "70c49ff8bb3476b0", fmt.Sprintf("%x", hasher.Sum(nil)))
4747
},
4848
},
4949
}

0 commit comments

Comments
 (0)