diff --git a/cmd/test.go b/cmd/test.go index 699137fd..a6ba4b59 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -99,7 +99,9 @@ argocd-image-updater test nginx --allow-tags '^1.19.\d+(\-.*)*$' --update-strate if err != nil { log.Fatalf("Platform %s: %v", platform, err) } - vc.Options = vc.Options.WithPlatform(os, arch, variant) + vc.Options = vc.Options. + WithPlatform(os, arch, variant). + WithMetadata(vc.SortMode.NeedsMetadata()) } if registriesConfPath != "" { diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index 0a92ff22..6fdecce9 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -197,7 +197,7 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat vc.SortMode = applicationImage.GetParameterUpdateStrategy(updateConf.UpdateApp.Application.Annotations) vc.MatchFunc, vc.MatchArgs = applicationImage.GetParameterMatch(updateConf.UpdateApp.Application.Annotations) vc.IgnoreList = applicationImage.GetParameterIgnoreTags(updateConf.UpdateApp.Application.Annotations) - vc.Options = applicationImage.GetPlatformOptions(updateConf.UpdateApp.Application.Annotations, updateConf.IgnorePlatforms) + vc.Options = applicationImage.GetPlatformOptions(updateConf.UpdateApp.Application.Annotations, updateConf.IgnorePlatforms).WithMetadata(vc.SortMode.NeedsMetadata()) // The endpoint can provide default credentials for pulling images err = rep.SetEndpointCredentials(updateConf.KubeClient) diff --git a/pkg/image/version.go b/pkg/image/version.go index 3e1b39f8..242fff3d 100644 --- a/pkg/image/version.go +++ b/pkg/image/version.go @@ -165,3 +165,13 @@ func (vsm VersionSortMode) IsCacheable() bool { return true } } + +// NeedsMetadata returns true if v requires image metadata to work correctly +func (vsm VersionSortMode) NeedsMetadata() bool { + switch vsm { + case VersionSortLatest: + return true + default: + return false + } +} diff --git a/pkg/options/options.go b/pkg/options/options.go index c1a64620..152518ea 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -70,18 +70,12 @@ func (o *ManifestOptions) Platforms() []string { } // WantsMetdata returns true if metadata should be requested -func (o *ManifestOptions) WantsMetdata() bool { +func (o *ManifestOptions) WantsMetadata() bool { return o.metadata } // WithMetadata sets metadata to be requested -func (o *ManifestOptions) WithMetadata() *ManifestOptions { - o.metadata = true - return o -} - -// WithoutMetadata sets metadata not not be requested -func (o *ManifestOptions) WithoutMetadata() *ManifestOptions { - o.metadata = false +func (o *ManifestOptions) WithMetadata(val bool) *ManifestOptions { + o.metadata = val return o } diff --git a/pkg/options/options_test.go b/pkg/options/options_test.go index d0a7fdc2..a89fc1b9 100644 --- a/pkg/options/options_test.go +++ b/pkg/options/options_test.go @@ -42,15 +42,15 @@ func Test_WantsPlatform(t *testing.T) { func Test_WantsMetadata(t *testing.T) { opts := NewManifestOptions() t.Run("Empty options", func(t *testing.T) { - assert.False(t, opts.WantsMetdata()) + assert.False(t, opts.WantsMetadata()) }) t.Run("Wants metadata", func(t *testing.T) { - opts = opts.WithMetadata() - assert.True(t, opts.WantsMetdata()) + opts = opts.WithMetadata(true) + assert.True(t, opts.WantsMetadata()) }) t.Run("Does not want metadata", func(t *testing.T) { - opts = opts.WithoutMetadata() - assert.False(t, opts.WantsMetdata()) + opts = opts.WithMetadata(false) + assert.False(t, opts.WantsMetadata()) }) } diff --git a/pkg/registry/client.go b/pkg/registry/client.go index 2f8a7c90..b3beb820 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -276,7 +276,7 @@ func (client *registryClient) TagMetadata(manifest distribution.Manifest, opts * // For some strategies, we do not need to fetch metadata for further // processing. - if !opts.WantsMetdata() { + if !opts.WantsMetadata() { return ti, nil }