Skip to content

Commit a0cf1e3

Browse files
authored
feat: Rename confusing update strategies (#456)
* rename strategies * update docs
1 parent f12a5ab commit a0cf1e3

File tree

11 files changed

+116
-36
lines changed

11 files changed

+116
-36
lines changed

argocd-image-updater

72.2 MB
Binary file not shown.

docs/basics/update-strategies.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ The following update strategies are currently supported:
1515

1616
* [semver](#strategy-semver) - Update to the latest version of an image
1717
considering semantic versioning constraints
18-
* [latest](#strategy-latest) - Update to the most recently built image found in a registry
18+
* [latest/newest-build](#strategy-latest) - Update to the most recently built image found in a registry
1919
* [digest](#strategy-digest) - Update to the latest version of a given version (tag), using the tag's SHA digest
20-
* [name](#strategy-name) - Sorts tags alphabetically and update to the one with the highest cardinality
20+
* [name/alphabetical](#strategy-name) - Sorts tags alphabetically and update to the one with the highest cardinality
21+
22+
!!!warning "Renamed image update strategies
23+
The `latest` strategy has been renamed to `newest-build`, and `name` strategy has been renamed to `alphabetical`.
24+
Please switch to the new convention as support for the old naming convention will be removed in future releases.
2125

2226
Some of the strategies will require additional configuration, or can be tweaked
2327
with additional parameters. Please have a look at the
@@ -97,30 +101,42 @@ Image Updater will pick the highest version number found in the registry.
97101
Argo CD Image Updater will omit any tags from your registry that do not match
98102
a semantic version when using the `semver` update strategy.
99103

100-
### <a name="strategy-latest"></a>latest - Update to the most recently built image
104+
### <a name="strategy-latest"></a>latest/newest-build - Update to the most recently built image
105+
106+
107+
!!!warning "Renamed image update strategies"
108+
The `latest` strategy has been renamed to `newest-build`.
109+
Please switch to the new convention as support for the old naming convention will be removed in future releases.
110+
Detected usage of `latest` will result in a warning message within the image-updater controller logs.
101111

102112
!!!warning
103113
As of November 2020, Docker Hub has introduced pull limits for accounts on
104-
the free plan and unauthenticated requests. The `latest` update strategy
114+
the free plan and unauthenticated requests. The `latest` or `newest-build` update strategy
105115
will perform manifest pulls for determining the most recently pushed tags,
106116
and these will count into your pull limits. So unless you are not affected
107-
by these pull limits, it is **not recommended** to use the `latest` update
117+
by these pull limits, it is **not recommended** to use the `latest` or `newest-build` update
108118
strategy with images hosted on Docker Hub.
109119

110120
!!!note
111121
If you are using *reproducible builds* for your container images (e.g. if
112122
your build pipeline always sets the creation date of the image to the same
113-
value), the `latest` strategy will not be able to determine which tag to
123+
value), the `latest` or `newest-build` strategy will not be able to determine which tag to
114124
update to.
115125

116-
Strategy name: `latest`
126+
Strategy name: `latest` or `newest-build`
117127

118128
Basic configuration:
119129

120130
```yaml
121131
argocd-image-updater.argoproj.io/image-list: <alias>=some/image
122132
argocd-image-updater.argoproj.io/<alias>.update-strategy: latest
123133
```
134+
or
135+
136+
```yaml
137+
argocd-image-updater.argoproj.io/image-list: <alias>=some/image
138+
argocd-image-updater.argoproj.io/<alias>.update-strategy: newest-build
139+
```
124140
125141
Argo CD Image Updater can update to the image that has the most recent build
126142
date, and is tagged with an arbitrary name (e.g. a Git commit SHA, or even a
@@ -147,6 +163,14 @@ argocd-image-updater.argoproj.io/myimage.update-strategy: latest
147163
argocd-image-updater.argoproj.io/myimage.allow-tags: regexp:^[0-9a-f]{7}$
148164
```
149165

166+
or
167+
168+
```yaml
169+
argocd-image-updater.argoproj.io/image-list: myimage=some/image
170+
argocd-image-updater.argoproj.io/myimage.update-strategy: newest-build
171+
argocd-image-updater.argoproj.io/myimage.allow-tags: regexp:^[0-9a-f]{7}$
172+
```
173+
150174
would only consider tags that match a given regular expression for update. In
151175
this case, the regular expression matches a 7-digit hexadecimal string that
152176
could represent the short version of a Git commit SHA, so it would match tags
@@ -160,6 +184,14 @@ argocd-image-updater.argoproj.io/myimage.update-strategy: latest
160184
argocd-image-updater.argoproj.io/myimage.ignore-tags: latest, master
161185
```
162186

187+
or
188+
189+
```yaml
190+
argocd-image-updater.argoproj.io/image-list: myimage=some/image
191+
argocd-image-updater.argoproj.io/myimage.update-strategy: newest-build
192+
argocd-image-updater.argoproj.io/myimage.ignore-tags: latest, master
193+
```
194+
163195
This would allow for considering all tags found but `latest` and `master`. You
164196
can read more about filtering tags
165197
[here](../../configuration/images/#filtering-tags).
@@ -206,14 +238,26 @@ argocd-image-updater.argoproj.io/myimage.update-strategy: digest
206238

207239
### <a name="strategy-name"></a>Update according to lexical sort
208240

209-
Strategy name: `name`
241+
!!!warning "Renamed image update strategies"
242+
The `name` strategy has been renamed to `alphabetical`.
243+
Please switch to the new convention as support for the old naming convention will be removed in future releases.
244+
Detected usage of `name` will result in a warning message within the image-updater controller logs.
245+
246+
247+
Strategy name: `name` or `alphabetical`
210248

211249
Basic configuration:
212250

213251
```yaml
214252
argocd-image-updater.argoproj.io/image-list: <alias>=some/image
215253
argocd-image-updater.argoproj.io/<alias>.update-strategy: name
216254
```
255+
or
256+
257+
```yaml
258+
argocd-image-updater.argoproj.io/image-list: <alias>=some/image
259+
argocd-image-updater.argoproj.io/<alias>.update-strategy: alphabetical
260+
```
217261

218262
This update strategy sorts the tags returned by the registry in a lexical way
219263
(by name, in descending order) and picks the last tag in the list for update.
@@ -231,6 +275,14 @@ argocd-image-updater.argoproj.io/myimage.update-strategy: name
231275
argocd-image-updater.argoproj.io/myimage.allow-tags: regexp:^[0-9]{4}-[0-9]{2}[0-9]{2}$
232276
```
233277

278+
or
279+
280+
```yaml
281+
argocd-image-updater.argoproj.io/image-list: myimage=some/image
282+
argocd-image-updater.argoproj.io/myimage.update-strategy: alphabetical
283+
argocd-image-updater.argoproj.io/myimage.allow-tags: regexp:^[0-9]{4}-[0-9]{2}[0-9]{2}$
284+
```
285+
234286
would only consider tags that match a given regular expression for update. In
235287
this case, only tags matching a date specification of `YYYY-MM-DD` would be
236288
considered for update.

docs/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,18 @@ RBAC authorization on Application resources etc. are fully supported.
4242

4343
## Features
4444

45+
!!!warning "Renamed image update strategies"
46+
The `latest` strategy has been renamed to `newest-build`, and `name` strategy has been renamed to `alphabetical`.
47+
Please switch to the new convention as support for the old naming convention will be removed in future releases.
48+
4549
* Updates images of apps that are managed by Argo CD and are either generated
4650
from *Helm* or *Kustomize* tooling
4751
* Update app images according to different
4852
[update strategies](./basics/update-strategies.md)
4953
* `semver`: update to highest allowed version according to given image
5054
constraint,
51-
* `latest`: update to the most recently created image tag,
52-
* `name`: update to the last tag in an alphabetically sorted list
55+
* `latest/newest-build`: update to the most recently created image tag,
56+
* `name/alphabetical`: update to the last tag in an alphabetically sorted list
5357
* `digest`: update to the most recent pushed version of a mutable tag
5458
* Support for
5559
[widely used container registries](./configuration/registries.md#supported-registries)

pkg/image/options.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,15 @@ func (img *ContainerImage) ParseUpdateStrategy(val string) UpdateStrategy {
101101
case "semver":
102102
return StrategySemVer
103103
case "latest":
104-
return StrategyLatest
104+
logCtx.Warnf("\"latest\" strategy has been renamed to \"newest-build\". Please switch to the new convention as support for the old naming convention will be removed in future versions.")
105+
fallthrough
106+
case "newest-build":
107+
return StrategyNewestBuild
105108
case "name":
106-
return StrategyName
109+
logCtx.Warnf("\"name\" strategy has been renamed to \"alphabetical\". Please switch to the new convention as support for the old naming convention will be removed in future versions.")
110+
fallthrough
111+
case "alphabetical":
112+
return StrategyAlphabetical
107113
case "digest":
108114
return StrategyDigest
109115
default:

pkg/image/options_test.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,22 @@ func Test_GetSortOption(t *testing.T) {
8585
assert.Equal(t, StrategySemVer, sortMode)
8686
})
8787

88+
t.Run("Use update strategy newest-build for configured application", func(t *testing.T) {
89+
annotations := map[string]string{
90+
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "newest-build",
91+
}
92+
img := NewFromIdentifier("dummy=foo/bar:1.12")
93+
sortMode := img.GetParameterUpdateStrategy(annotations)
94+
assert.Equal(t, StrategyNewestBuild, sortMode)
95+
})
96+
8897
t.Run("Get update strategy date for configured application", func(t *testing.T) {
8998
annotations := map[string]string{
9099
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "latest",
91100
}
92101
img := NewFromIdentifier("dummy=foo/bar:1.12")
93102
sortMode := img.GetParameterUpdateStrategy(annotations)
94-
assert.Equal(t, StrategyLatest, sortMode)
103+
assert.Equal(t, StrategyNewestBuild, sortMode)
95104
})
96105

97106
t.Run("Get update strategy name for configured application", func(t *testing.T) {
@@ -100,7 +109,16 @@ func Test_GetSortOption(t *testing.T) {
100109
}
101110
img := NewFromIdentifier("dummy=foo/bar:1.12")
102111
sortMode := img.GetParameterUpdateStrategy(annotations)
103-
assert.Equal(t, StrategyName, sortMode)
112+
assert.Equal(t, StrategyAlphabetical, sortMode)
113+
})
114+
115+
t.Run("Use update strategy alphabetical for configured application", func(t *testing.T) {
116+
annotations := map[string]string{
117+
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "alphabetical",
118+
}
119+
img := NewFromIdentifier("dummy=foo/bar:1.12")
120+
sortMode := img.GetParameterUpdateStrategy(annotations)
121+
assert.Equal(t, StrategyAlphabetical, sortMode)
104122
})
105123

106124
t.Run("Get update strategy option configured application because of invalid option", func(t *testing.T) {
@@ -121,21 +139,21 @@ func Test_GetSortOption(t *testing.T) {
121139

122140
t.Run("Prefer update strategy option from image-specific annotation", func(t *testing.T) {
123141
annotations := map[string]string{
124-
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
125-
common.ApplicationWideUpdateStrategyAnnotation: "latest",
142+
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "alphabetical",
143+
common.ApplicationWideUpdateStrategyAnnotation: "newest-build",
126144
}
127145
img := NewFromIdentifier("dummy=foo/bar:1.12")
128146
sortMode := img.GetParameterUpdateStrategy(annotations)
129-
assert.Equal(t, StrategyName, sortMode)
147+
assert.Equal(t, StrategyAlphabetical, sortMode)
130148
})
131149

132150
t.Run("Get update strategy option from application-wide annotation", func(t *testing.T) {
133151
annotations := map[string]string{
134-
common.ApplicationWideUpdateStrategyAnnotation: "latest",
152+
common.ApplicationWideUpdateStrategyAnnotation: "newest-build",
135153
}
136154
img := NewFromIdentifier("dummy=foo/bar:1.12")
137155
sortMode := img.GetParameterUpdateStrategy(annotations)
138-
assert.Equal(t, StrategyLatest, sortMode)
156+
assert.Equal(t, StrategyNewestBuild, sortMode)
139157
})
140158
}
141159

pkg/image/version.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const (
1717
// VersionSortSemVer sorts tags using semver sorting (the default)
1818
StrategySemVer UpdateStrategy = 0
1919
// VersionSortLatest sorts tags after their creation date
20-
StrategyLatest UpdateStrategy = 1
20+
StrategyNewestBuild UpdateStrategy = 1
2121
// VersionSortName sorts tags alphabetically by name
22-
StrategyName UpdateStrategy = 2
22+
StrategyAlphabetical UpdateStrategy = 2
2323
// VersionSortDigest uses latest digest of an image
2424
StrategyDigest UpdateStrategy = 3
2525
)
@@ -28,10 +28,10 @@ func (us UpdateStrategy) String() string {
2828
switch us {
2929
case StrategySemVer:
3030
return "semver"
31-
case StrategyLatest:
32-
return "latest"
33-
case StrategyName:
34-
return "name"
31+
case StrategyNewestBuild:
32+
return "newest-build"
33+
case StrategyAlphabetical:
34+
return "alphabetical"
3535
case StrategyDigest:
3636
return "digest"
3737
}
@@ -87,12 +87,12 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
8787
switch vc.Strategy {
8888
case StrategySemVer:
8989
availableTags = tagList.SortBySemVer()
90-
case StrategyName:
91-
availableTags = tagList.SortByName()
92-
case StrategyLatest:
90+
case StrategyAlphabetical:
91+
availableTags = tagList.SortAlphabetically()
92+
case StrategyNewestBuild:
9393
availableTags = tagList.SortByDate()
9494
case StrategyDigest:
95-
availableTags = tagList.SortByName()
95+
availableTags = tagList.SortAlphabetically()
9696
}
9797

9898
considerTags := tag.SortableImageTagList{}
@@ -192,7 +192,7 @@ func (s UpdateStrategy) IsCacheable() bool {
192192
// NeedsMetadata returns true if strategy s requires image metadata to work correctly
193193
func (s UpdateStrategy) NeedsMetadata() bool {
194194
switch s {
195-
case StrategyLatest:
195+
case StrategyNewestBuild:
196196
return true
197197
default:
198198
return false

pkg/image/version_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func Test_LatestVersion(t *testing.T) {
8888
t.Run("Find the latest version using latest sortmode", func(t *testing.T) {
8989
tagList := newImageTagListWithDate([]string{"zz", "bb", "yy", "cc", "yy", "aa", "ll"})
9090
img := NewFromIdentifier("jannfis/test:bb")
91-
vc := VersionConstraint{Strategy: StrategyLatest}
91+
vc := VersionConstraint{Strategy: StrategyNewestBuild}
9292
newTag, err := img.GetNewestVersionFromTags(&vc, tagList)
9393
require.NoError(t, err)
9494
require.NotNil(t, newTag)

pkg/registry/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (endpoint *RegistryEndpoint) GetTags(img *image.ContainerImage, regClient R
8080
//
8181
// We just create a dummy time stamp according to the registry's sort mode, if
8282
// set.
83-
if (vc.Strategy != image.StrategyLatest && vc.Strategy != image.StrategyDigest) || endpoint.TagListSort.IsTimeSorted() {
83+
if (vc.Strategy != image.StrategyNewestBuild && vc.Strategy != image.StrategyDigest) || endpoint.TagListSort.IsTimeSorted() {
8484
for i, tagStr := range tags {
8585
var ts int
8686
if endpoint.TagListSort == TagListSortLatestFirst {

pkg/registry/registry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func Test_GetTags(t *testing.T) {
7070

7171
img := image.NewFromIdentifier("foo/bar:1.2.0")
7272

73-
tl, err := ep.GetTags(img, &regClient, &image.VersionConstraint{Strategy: image.StrategyName, Options: options.NewManifestOptions()})
73+
tl, err := ep.GetTags(img, &regClient, &image.VersionConstraint{Strategy: image.StrategyAlphabetical, Options: options.NewManifestOptions()})
7474
require.NoError(t, err)
7575
assert.NotEmpty(t, tl)
7676

@@ -102,7 +102,7 @@ func Test_GetTags(t *testing.T) {
102102
ep.Cache.ClearCache()
103103

104104
img := image.NewFromIdentifier("foo/bar:1.2.0")
105-
tl, err := ep.GetTags(img, &regClient, &image.VersionConstraint{Strategy: image.StrategyLatest, Options: options.NewManifestOptions()})
105+
tl, err := ep.GetTags(img, &regClient, &image.VersionConstraint{Strategy: image.StrategyNewestBuild, Options: options.NewManifestOptions()})
106106
require.NoError(t, err)
107107
assert.NotEmpty(t, tl)
108108

pkg/tag/tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (il ImageTagList) Add(tag *ImageTag) {
123123
}
124124

125125
// SortByName returns an array of ImageTag objects, sorted by the tag's name
126-
func (il ImageTagList) SortByName() SortableImageTagList {
126+
func (il ImageTagList) SortAlphabetically() SortableImageTagList {
127127
sil := SortableImageTagList{}
128128
for _, v := range il.items {
129129
sil = append(sil, v)

0 commit comments

Comments
 (0)