Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for calver as an additional update-strategy #1017

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions docs/basics/update-strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The following update strategies are currently supported:
* [latest/newest-build](#strategy-latest) - Update to the most recently built image found in a registry
* [digest](#strategy-digest) - Update to the latest version of a given version (tag), using the tag's SHA digest
* [name/alphabetical](#strategy-name) - Sorts tags alphabetically and update to the one with the highest cardinality
* [calver](#strategy-calver) - Update to the latest version of an image considering calendar versioning constraints

!!!warning "Renamed image update strategies"
The `latest` strategy has been renamed to `newest-build`, and `name` strategy has been renamed to `alphabetical`.
Expand Down Expand Up @@ -292,3 +293,53 @@ argocd-image-updater.argoproj.io/myimage.allow-tags: regexp:^[0-9]{4}-[0-9]{2}-[
would only consider tags that match a given regular expression for update. In
this case, only tags matching a date specification of `YYYY-MM-DD` would be
considered for update.

### <a name="strategy-calver"></a>calver - Update to calendar versions

Strategy name: `calver`

Basic configuration:

```yaml
argocd-image-updater.argoproj.io/image-list: some/image[:<version_constraint>]
argocd-image-updater.argoproj.io/<image>.update-strategy: calver
```

The `calver` strategy allows you to track & update images which use tags that
follow the
[calendar versioning scheme](https://calver.org). Tag names must contain calver
compatible identifiers in the format `YYYY.MM.DD`, where `YYYY`, `MM`, and `DD` must be
whole numbers.

This will allow you to update to the latest version of an image within a given
year, month, or day, or just to the latest version that is tagged with a valid
calendar version identifier.

To tell Argo CD Image Updater which versions are allowed, simply give a calver
version as a constraint in the `image-list` annotation. For example, to allow
updates to the latest version within the `2023.08` month, use

```
argocd-image-updater.argoproj.io/image-list: some/image:2023.08.x
```

The above example would update to any new tag pushed to the registry matching
this constraint, e.g. `2023.08.15`, `2023.08.30` etc, but not to a new month
(e.g. `2023.09`).

Likewise, to allow updates to any month within the year `2023`,
use

```yaml
argocd-image-updater.argoproj.io/image-list: some/image:2023.x
```

The above example would update to any new tag pushed to the registry matching
this constraint, e.g. `2023.08.15`, `2023.09.01`, `2023.12.31` etc, but not to a new year
(e.g. `2024`).

If no version constraint is specified in the list of allowed images, Argo CD
Image Updater will pick the highest version number found in the registry.

Argo CD Image Updater will omit any tags from your registry that do not match
a calendar version when using the `calver` update strategy.
2 changes: 2 additions & 0 deletions registry-scanner/pkg/image/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (img *ContainerImage) ParseUpdateStrategy(val string) UpdateStrategy {
return StrategyAlphabetical
case "digest":
return StrategyDigest
case "calver":
return StrategyCalVer
default:
logCtx.Warnf("Unknown sort option %s -- using semver", val)
return StrategySemVer
Expand Down
6 changes: 6 additions & 0 deletions registry-scanner/pkg/image/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
StrategyAlphabetical UpdateStrategy = 2
// VersionSortDigest uses latest digest of an image
StrategyDigest UpdateStrategy = 3
// VersionSortCalVer sorts tags using calendar versioning
StrategyCalVer UpdateStrategy = 4
)

func (us UpdateStrategy) String() string {
Expand All @@ -34,6 +36,8 @@ func (us UpdateStrategy) String() string {
return "alphabetical"
case StrategyDigest:
return "digest"
case StrategyCalVer:
return "calver"
}

return "unknown"
Expand Down Expand Up @@ -93,6 +97,8 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
availableTags = tagList.SortByDate()
case StrategyDigest:
availableTags = tagList.SortAlphabetically()
case StrategyCalVer:
availableTags = tagList.SortByCalVer()
}

considerTags := tag.SortableImageTagList{}
Expand Down
Loading