image-automation-controller icon indicating copy to clipboard operation
image-automation-controller copied to clipboard

ImagePolicy with mixed policy types

Open roman-chub opened this issue 1 year ago • 2 comments

I have an issue with updating image due to the mixed naming of tag which contained both numbers and letters (I'm using CI_COMMIT_SHORT_SHA once pushing new image to repo in my gitlab pipeline). It's looking like following:

sandbox-1214bc9i
sandbox-cd14bcbc

Once I tried to use numerical policy:

apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
  name: image-policy-sandbox
spec:
  imageRepositoryRef:
    name: image-repo
  filterTags:
    pattern: '^sandbox-[0-9a-z]+'
  policy:
    numerical:
      order: asc

I got following error:

imagepolicy/image-policy-sandbox      	            	False	Cannot determine latest tag for policy: failed to parse invalid numeric value 'sandbox-ce597c69' 

If I'm using alphabetical policy:

apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
  name: image-policy-sandbox
spec:
  imageRepositoryRef:
    name: image-repo
  filterTags:
    pattern: '^sandbox-[0-9a-z]+'
  policy:
    alphabetical:
      order: asc

Image update is working but didn't use the latest image for automation and pickup much older image tag

Sorry, it may be described somewhere but I tried almost all patterns and it didn't work correctly. Could you please provide me some info how to make it workable and to teach my automation pickup latest image from sandbox-*?

roman-chub avatar Aug 11 '22 12:08 roman-chub

@roman-chub please take a look at our "sortable image tags" guide: https://fluxcd.io/docs/guides/sortable-image-tags/.

pjbgf avatar Aug 11 '22 13:08 pjbgf

@pjbgf thanks for the feedback but I already checked that and don't know what should be changed in pattern. I have no any timestamps or another staff which may be extracted and my CI_COMMIT_SHORT_SHA should covered by this [0-9a-z]+. Am I not right?

roman-chub avatar Aug 11 '22 14:08 roman-chub

@pjbgf I little bit changed pipeline - $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA-$CI_PIPELINE_IID and added new pattern ^sandbox-[a-zA-Z0-9]+-(?P<sha>[0-9]+) - it works.

roman-chub avatar Aug 16 '22 14:08 roman-chub