Skip to content

Commit 939d5f6

Browse files
committed
opm validate: skips stranding is commutative
Signed-off-by: Joe Lanford <[email protected]>
1 parent ad389c4 commit 939d5f6

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

alpha/model/model.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,12 @@ func (c *Channel) Validate() error {
264264
// validateReplacesChain checks the replaces chain of a channel.
265265
// Specifically the following rules must be followed:
266266
// 1. There must be exactly 1 channel head.
267-
// 2. Beginning at the head, the replaces chain must reach all non-skipped entries.
268-
// Non-skipped entries are defined as entries that are not skipped by any other entry in the channel.
269-
// 3. There must be no cycles in the replaces chain.
270-
// 4. The tail entry in the replaces chain is permitted to replace a non-existent entry.
267+
// 2. Beginning at the head, the replaces chain traversal must reach all entries.
268+
// Unreached entries are considered "stranded" and cause a channel to be invalid.
269+
// 3. Skipped entries are always leaf nodes. We never follow replaces or skips edges
270+
// of skipped entries during replaces chain traversal.
271+
// 4. There must be no cycles in the replaces chain.
272+
// 5. The tail entry in the replaces chain is permitted to replace a non-existent entry.
271273
func (c *Channel) validateReplacesChain() error {
272274
head, err := c.Head()
273275
if err != nil {
@@ -289,12 +291,12 @@ func (c *Channel) validateReplacesChain() error {
289291
if _, ok := chainFrom[cur.Name]; !ok {
290292
chainFrom[cur.Name] = []string{cur.Name}
291293
}
292-
if skippedBundles.Has(cur.Replaces) {
294+
295+
skippedInChain = skippedInChain.Insert(cur.Skips...)
296+
if skippedInChain.Has(cur.Replaces) {
293297
break
294298
}
295-
for _, skip := range cur.Skips {
296-
skippedInChain = skippedInChain.Insert(skip)
297-
}
299+
298300
for k := range chainFrom {
299301
chainFrom[k] = append(chainFrom[k], cur.Replaces)
300302
}

alpha/model/model_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestValidReplacesChain(t *testing.T) {
132132
ch: Channel{Bundles: map[string]*Bundle{
133133
"anakin.v0.0.1": {Name: "anakin.v0.0.1"},
134134
"anakin.v0.0.2": {Name: "anakin.v0.0.2", Skips: []string{"anakin.v0.0.1"}},
135-
"anakin.v0.0.3": {Name: "anakin.v0.0.3", Skips: []string{"anakin.v0.0.2"}},
135+
"anakin.v0.0.3": {Name: "anakin.v0.0.3", Replaces: "anakin.v0.0.2"},
136136
"anakin.v0.0.4": {Name: "anakin.v0.0.4", Replaces: "anakin.v0.0.3"},
137137
}},
138138
assertion: require.NoError,
@@ -181,8 +181,8 @@ func TestValidReplacesChain(t *testing.T) {
181181
name: "Error/StrandedSkipsAfterReplaces",
182182
ch: Channel{Bundles: map[string]*Bundle{
183183
"anakin.v0.0.1": {Name: "anakin.v0.0.1"},
184-
"anakin.v0.0.2": {Name: "anakin.v0.0.2", Replaces: "anakin.v0.0.1"},
185-
"anakin.v0.0.3": {Name: "anakin.v0.0.3", Replaces: "anakin.v0.0.2", Skips: []string{"anakin.v0.0.3"}},
184+
"anakin.v0.0.2": {Name: "anakin.v0.0.2", Replaces: "anakin.v0.0.1", Skips: []string{"anakin.v0.0.3"}},
185+
"anakin.v0.0.3": {Name: "anakin.v0.0.3", Replaces: "anakin.v0.0.2"},
186186
"anakin.v0.0.4": {Name: "anakin.v0.0.4", Replaces: "anakin.v0.0.3"},
187187
"anakin.v0.0.5": {Name: "anakin.v0.0.5", Replaces: "anakin.v0.0.4"},
188188
}},

0 commit comments

Comments
 (0)