Skip to content

Commit ab6da64

Browse files
fix: Do not validate the current image tag against SemVer (#1473)
Signed-off-by: Christian Schlichtherle <christian@schlichtherle.de>
1 parent b7a0823 commit ab6da64

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ handling on your side.
2929

3030
* refactor: make argocd-image-updater-config volume mapping optional (#145)
3131
* enhancement: sort Helm parameters alphabetically in .argocd-source-<appName>.yaml for deterministic output
32+
* enhancement: the current image tag no longer needs to be a valid semver version when using the semver update strategy
3233

3334
## 2020-12-06 - Release v0.8.0
3435

docs/basics/update-strategies.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ The above example would update to any new tag pushed to the registry matching
9393
this constraint, e.g. `1.2.5`, `1.2.12` etc., but not to a new minor version
9494
(e.g. `1.3`).
9595

96-
!!!warning "A note on the current image tag"
97-
For semver strategy to work, the current application tag must already follow
98-
semver. Otherwise, no comparison can happen by the updater. See discussion at [#270](https://github.com/argoproj-labs/argocd-image-updater/issues/270) for more details.
96+
!!!note "A note on the current image tag"
97+
The current application tag does not need to follow semver. The updater will
98+
find the newest tag from the registry that matches the version constraint,
99+
regardless of the format of the currently running tag. For example, an
100+
application running the `latest` tag can be updated to a semver-compatible
101+
version using a constraint like `1.x`.
99102

100103
Likewise, to allow updates to any minor release within the major version `1`,
101104
use

registry-scanner/pkg/image/version.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,11 @@ func (img *ContainerImage) GetNewestVersionFromTags(ctx context.Context, vc *Ver
106106
// The given constraint MUST match a semver constraint
107107
var semverConstraint *semver.Constraints
108108
var err error
109-
if vc.Strategy == StrategySemVer {
110-
// TODO: Shall we really ensure a valid semver on the current tag?
111-
// This prevents updating from a non-semver tag currently.
112-
if img.ImageTag != nil && img.ImageTag.TagName != "" {
113-
_, err := semver.NewVersion(img.ImageTag.TagName)
114-
if err != nil {
115-
return nil, err
116-
}
117-
}
118-
119-
if vc.Constraint != "" {
120-
if vc.Strategy == StrategySemVer {
121-
semverConstraint, err = semver.NewConstraint(vc.Constraint)
122-
if err != nil {
123-
logCtx.Errorf("invalid constraint '%s' given: '%v'", vc, err)
124-
return nil, err
125-
}
126-
}
109+
if vc.Strategy == StrategySemVer && vc.Constraint != "" {
110+
semverConstraint, err = semver.NewConstraint(vc.Constraint)
111+
if err != nil {
112+
logCtx.Errorf("invalid constraint '%s' given: '%v'", vc, err)
113+
return nil, err
127114
}
128115
}
129116

registry-scanner/pkg/image/version_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ func Test_LatestVersion(t *testing.T) {
5959
assert.Equal(t, "1.0.1", newTag.TagName)
6060
})
6161

62+
t.Run("Find the latest version with a non-semver current tag and semver constraint", func(t *testing.T) {
63+
tagList := newImageTagList([]string{"0.1", "0.5.1", "0.9", "1.0", "1.0.1", "1.1.2", "2.0.3"})
64+
img := NewFromIdentifier("christianschlichtherle/test:latest")
65+
vc := VersionConstraint{Constraint: "^1.0"}
66+
newTag, err := img.GetNewestVersionFromTags(context.Background(), &vc, tagList)
67+
require.NoError(t, err)
68+
require.NotNil(t, newTag)
69+
assert.Equal(t, "1.1.2", newTag.TagName)
70+
})
71+
72+
t.Run("Find the latest version with a non-semver current tag without any constraint", func(t *testing.T) {
73+
tagList := newImageTagList([]string{"0.1", "0.5.1", "0.9", "1.0", "1.0.1", "1.1.2", "2.0.3"})
74+
img := NewFromIdentifier("christianschlichtherle/test:latest")
75+
vc := VersionConstraint{}
76+
newTag, err := img.GetNewestVersionFromTags(context.Background(), &vc, tagList)
77+
require.NoError(t, err)
78+
require.NotNil(t, newTag)
79+
assert.Equal(t, "2.0.3", newTag.TagName)
80+
})
81+
6282
t.Run("Find the latest version with a semver constraint that has no match", func(t *testing.T) {
6383
tagList := newImageTagList([]string{"0.1", "0.5.1", "0.9", "2.0.3"})
6484
img := NewFromIdentifier("jannfis/test:1.0")

0 commit comments

Comments
 (0)