Skip to content

Commit

Permalink
Use a custom definition of equal ImageOverrides
Browse files Browse the repository at this point in the history
- meta are descriptive, not identifying, so they have no bearing on
  whether two ImageOverrides are equal.

Given that all overrides are created brand fresh during a resolve for
the kbld lock file, there's no need to dedup them (removed call to
UniqueImageOverride()).
  • Loading branch information
jtigger committed Sep 20, 2021
1 parent 1ad081d commit 9e718e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 0 additions & 2 deletions pkg/kbld/cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ func (o *ResolveOptions) emitLockOutput(conf ctlconf.Conf, resolvedImages *Proce
})
}

c.Overrides = ctlconf.UniqueImageOverrides(c.Overrides)

return c.WriteToFile(o.LockOutput)
case o.ImgpkgLockOutput != "":
iLock := lockconfig.ImagesLock{
Expand Down
13 changes: 10 additions & 3 deletions pkg/kbld/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package config
import (
"fmt"
"io/ioutil"
"reflect"

semver "github.com/hashicorp/go-version"
"github.com/k14s/imgpkg/pkg/imgpkg/lockconfig"
Expand Down Expand Up @@ -325,13 +324,21 @@ func (d Config) WriteToFile(path string) error {
return nil
}

// Equal reports whether `this` ImageOverride is equal to `that` ImageOverride.
// (`ImageMeta` is descriptive — not identifying — so not part of equality)
func (this ImageOverride) Equal(that ImageOverride) bool {
return this.ImageRef == that.ImageRef &&
this.NewImage == that.NewImage &&
this.Preresolved == that.Preresolved &&
this.TagSelection == that.TagSelection
}

func UniqueImageOverrides(overrides []ImageOverride) []ImageOverride {
var result []ImageOverride
for _, override := range overrides {
var found bool
for _, addedOverride := range result {
// using DeepEqual instead of '==' since ImageOverride contains a slice
if reflect.DeepEqual(addedOverride, override) {
if override.Equal(addedOverride) {
found = true
break
}
Expand Down

0 comments on commit 9e718e6

Please sign in to comment.