Skip to content

Commit cfc22fa

Browse files
committed
Implement support for calver as an additional update-strategy
--- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/argoproj-labs/argocd-image-updater?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 980eff5 commit cfc22fa

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

docs/basics/update-strategies.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following update strategies are currently supported:
1818
* [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
2020
* [name/alphabetical](#strategy-name) - Sorts tags alphabetically and update to the one with the highest cardinality
21+
* [calver](#strategy-calver) - Update to the latest version of an image considering calendar versioning constraints
2122

2223
!!!warning "Renamed image update strategies"
2324
The `latest` strategy has been renamed to `newest-build`, and `name` strategy has been renamed to `alphabetical`.
@@ -292,3 +293,53 @@ argocd-image-updater.argoproj.io/myimage.allow-tags: regexp:^[0-9]{4}-[0-9]{2}-[
292293
would only consider tags that match a given regular expression for update. In
293294
this case, only tags matching a date specification of `YYYY-MM-DD` would be
294295
considered for update.
296+
297+
### <a name="strategy-calver"></a>calver - Update to calendar versions
298+
299+
Strategy name: `calver`
300+
301+
Basic configuration:
302+
303+
```yaml
304+
argocd-image-updater.argoproj.io/image-list: some/image[:<version_constraint>]
305+
argocd-image-updater.argoproj.io/<image>.update-strategy: calver
306+
```
307+
308+
The `calver` strategy allows you to track & update images which use tags that
309+
follow the
310+
[calendar versioning scheme](https://calver.org). Tag names must contain calver
311+
compatible identifiers in the format `YYYY.MM.DD`, where `YYYY`, `MM`, and `DD` must be
312+
whole numbers.
313+
314+
This will allow you to update to the latest version of an image within a given
315+
year, month, or day, or just to the latest version that is tagged with a valid
316+
calendar version identifier.
317+
318+
To tell Argo CD Image Updater which versions are allowed, simply give a calver
319+
version as a constraint in the `image-list` annotation. For example, to allow
320+
updates to the latest version within the `2023.08` month, use
321+
322+
```
323+
argocd-image-updater.argoproj.io/image-list: some/image:2023.08.x
324+
```
325+
326+
The above example would update to any new tag pushed to the registry matching
327+
this constraint, e.g. `2023.08.15`, `2023.08.30` etc, but not to a new month
328+
(e.g. `2023.09`).
329+
330+
Likewise, to allow updates to any month within the year `2023`,
331+
use
332+
333+
```yaml
334+
argocd-image-updater.argoproj.io/image-list: some/image:2023.x
335+
```
336+
337+
The above example would update to any new tag pushed to the registry matching
338+
this constraint, e.g. `2023.08.15`, `2023.09.01`, `2023.12.31` etc, but not to a new year
339+
(e.g. `2024`).
340+
341+
If no version constraint is specified in the list of allowed images, Argo CD
342+
Image Updater will pick the highest version number found in the registry.
343+
344+
Argo CD Image Updater will omit any tags from your registry that do not match
345+
a calendar version when using the `calver` update strategy.

registry-scanner/pkg/image/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func (img *ContainerImage) ParseUpdateStrategy(val string) UpdateStrategy {
112112
return StrategyAlphabetical
113113
case "digest":
114114
return StrategyDigest
115+
case "calver":
116+
return StrategyCalVer
115117
default:
116118
logCtx.Warnf("Unknown sort option %s -- using semver", val)
117119
return StrategySemVer

registry-scanner/pkg/image/version.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const (
2222
StrategyAlphabetical UpdateStrategy = 2
2323
// VersionSortDigest uses latest digest of an image
2424
StrategyDigest UpdateStrategy = 3
25+
// VersionSortCalVer sorts tags using calendar versioning
26+
StrategyCalVer UpdateStrategy = 4
2527
)
2628

2729
func (us UpdateStrategy) String() string {
@@ -34,6 +36,8 @@ func (us UpdateStrategy) String() string {
3436
return "alphabetical"
3537
case StrategyDigest:
3638
return "digest"
39+
case StrategyCalVer:
40+
return "calver"
3741
}
3842

3943
return "unknown"
@@ -93,6 +97,8 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
9397
availableTags = tagList.SortByDate()
9498
case StrategyDigest:
9599
availableTags = tagList.SortAlphabetically()
100+
case StrategyCalVer:
101+
availableTags = tagList.SortByCalVer()
96102
}
97103

98104
considerTags := tag.SortableImageTagList{}

0 commit comments

Comments
 (0)