From dbc497e644332f6691854a473d9a950bbea2641e Mon Sep 17 00:00:00 2001 From: John Ryan Date: Mon, 20 Sep 2021 15:26:52 -0700 Subject: [PATCH] Use a custom definition of equal ImageOverrides - 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()). --- pkg/kbld/cmd/resolve.go | 2 -- pkg/kbld/config/config.go | 13 ++++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/kbld/cmd/resolve.go b/pkg/kbld/cmd/resolve.go index ee134ae7..c62f5366 100644 --- a/pkg/kbld/cmd/resolve.go +++ b/pkg/kbld/cmd/resolve.go @@ -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{ diff --git a/pkg/kbld/config/config.go b/pkg/kbld/config/config.go index 1fff03ef..e935d8ee 100644 --- a/pkg/kbld/config/config.go +++ b/pkg/kbld/config/config.go @@ -6,7 +6,6 @@ package config import ( "fmt" "io/ioutil" - "reflect" semver "github.com/hashicorp/go-version" "github.com/k14s/imgpkg/pkg/imgpkg/lockconfig" @@ -324,13 +323,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 }