Skip to content

Commit

Permalink
fix: Fetch metadata for multi-arch images with latest strategy (#342)
Browse files Browse the repository at this point in the history
* fix: Fetch metadata for multi-arch images with latest strategy

Signed-off-by: jannfis <[email protected]>

* Simplify

Signed-off-by: jannfis <[email protected]>
  • Loading branch information
jannfis authored Jan 12, 2022
1 parent e1f6501 commit 752f305
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
4 changes: 3 additions & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions pkg/image/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
12 changes: 3 additions & 9 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions pkg/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 752f305

Please sign in to comment.