argoproj-labs / argocd-image-updater

Automatic container image update for Argo CD
https://argocd-image-updater.readthedocs.io/en/stable/
Apache License 2.0
1.25k stars 258 forks source link

Change update strategy from name to semver with git write-back will have error #270

Open zmx opened 3 years ago

zmx commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce

  1. Enable git write-back
  2. update-strategy: name, let it write-back to .argocd-source-*.yaml
  3. change update strategy to semver
  4. Unable to find newest version from available tags: Invalid Semantic Version in logs

Expected behavior Former strategy result should not cause error with new strategy. When we change to new strategy, should always override old tag.

Additional context Workaround:

  1. Stop Argo CD Auto Sync
  2. Scale down argocd-image-updater to zero instance
  3. manually upate tag in .argocd-source-*.yaml
  4. manually Argo CD Sync
  5. Wait App -> SUMMARY -> IMAGe have correct result. (It will have both old strategy tag and new tag co-exists a while)
  6. Scale up argocd-image-updater to one instance

Version Argo CD: v2.1.3 argocd-image-updater: v0.10.3

Logs Unable to find newest version from available tags: Invalid Semantic Version" alias=eucleia application=hub-main image_name=eucleia image_tag=20211001T060636 registry="repo.mycompany.com"

zmx commented 3 years ago

Found this in source code https://github.com/argoproj-labs/argocd-image-updater/blob/master/pkg/image/version.go#L83

    if vc.SortMode == VersionSortSemVer {
        // TODO: Shall we really ensure a valid semver on the current tag?
        // This prevents updating from a non-semver tag currently.
jannfis commented 3 years ago

The problem is, that we need to compare the version that's running with the version(s) found in the registry in order to be able to update. If there's no semantic version on the currently running image, we don't have anything to compare against.

I think we could leverage the force-update option here. If it is set, and the currently running image doesn't have a valid semver tag, we can log a warning, set the version to 0.0.0 and proceed. Any semver tag found in the registry should be higher compared to that.

johnytiago commented 2 years ago

We're facing a similar problem where image-updater won't update the initial stable image because it is not semver. If one specifically defines a semver constraint, I can't see the reason why it shouldn't update to the most recent version that matches the constraint. I'm not totally sure about leveraging the force-update option, since it seems like this goes beyond the intent of that flag.

@jannfis would you be happy to take a PR to address this?

Something like:

t.Run("Find the latest version with a semver constraint when base is a named tag", func(t *testing.T) {
  tagList := newImageTagList([]string{"0.1", "0.5.1", "0.9", "1.0", "1.0.1", "1.1.2", "2.0.3"})
  img := NewFromIdentifier("jannfis/test:stable")
  vc := VersionConstraint{Constraint: "1.x.x"}
  newTag, err := img.GetNewestVersionFromTags(&vc, tagList)
  require.NoError(t, err)
  require.NotNil(t, newTag)
  assert.Equal(t, "1.1.2", newTag.TagName)
})
NickLarsenNZ commented 2 years ago

I'm having trouble trying to change from the latest to semver strategy without having to take down all of the running pods. I've even set the initial tag to be semver in the kustomization.yml to no avail.

In the end I had to schedule some downtime, disable auto-sync, and delete all Deployment, Job, CronJob, etc... resources that references the image. Seems to have come up, but I think there should be a better solution for switching strategies.

umi0410 commented 2 years ago

I've suffered from this issue. I also tried to change my update strategy from latest to semver but when my current tag name wasn't qualified with semver, it returned errors.

I think this is a bug and I hope the bug fixed. If no one is handling this issue, can I fix this?

Please refer to https://github.com/argoproj-labs/argocd-image-updater/blob/f12a5ab6d3c69299ccd02473bdebdebc24131cb4/pkg/image/version.go#L109

alvarogonzalez-packlink commented 2 years ago

I think it'd be great to have an annotation were you could specify one or several tags that, when found, image-updater automatically upgrades to the latest semver image found in the registry.

e.g., If you find [latest,master,stage] in the running application, just override the image with the semver latest found in the registry

lukonjun commented 1 year ago

Running into the same issue trying to update from latest to semver

aaaaahaaaaa commented 1 year ago

I experience the same issue here trying to switch from latest to semver with a kustomization setup.

Logs:

time="2022-11-08T17:49:01Z" level=debug msg="Considering this image for update" alias=gcs application=<REDACTED> image_name=<REDACTED>/docker/<REDACTED> image_tag=latest registry=europe-docker.pkg.dev
time="2022-11-08T17:49:01Z" level=debug msg="Using version constraint 'v1.x.x' when looking for a new tag" alias=gcs application=<REDACTED> image_name=<REDACTED>/docker/<REDACTED> image_tag=latest registry=europe-docker.pkg.dev
time="2022-11-08T17:49:01Z" level=debug msg="could not parse input tag latest as semver: Invalid Semantic Version"

What I'm struggling to understand is why the updater is considering image_tag=latest (which, if I understand correctly is the source of the problem here) since the kustomization being targeted is already overriding newTag with a valid semver tag which is not latest.

melkishengue commented 1 year ago

This also seems to happen while using images with no semver tags with the latest strategy

davidmendezph commented 10 months ago

I know this is an old thread, but for anyone having this issue, I was able to fix it by setting an override for the app. I ran argocd app set appli -p image.tag=v1.5.0 and after that argocd-image-updater could update to v1.5.1.

Using constraint vx.x.x, update-strategy: semver, helm.image-name: image.repository.