ImagePolicy not able to correctly parse the image tags
bavneetsingh16 opened this issue · 2 comments
Hi All,
The image tags are of format(20190209-4) and the code block for image policy is pasted below:
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
name: app1
namespace: cluster-config
spec:
imageRepositoryRef:
name: podinfo
namespace: cluster-config
filterTags:
extract: $version
pattern: ^(?P<version>[0-9]+-[0-9]+)$
policy:
alphabetical:
order: asc
However it produces incorrect result when its comparing(20220209-04 and 20220209-22), giving the result as 20220209-04. I believe the issue is because I have used alphabetical policy. Numeric policy does not work as expected with the error 'failed to parse invalid numeric'. What would be the correct way to parse these image tags, is it even supported? Any help would be appreciated.
Hello @bavneetsingh16.
Since your versions contain two numerical components separated by a -
char, you could combine the two components into a larger number. Also, note that the capture group might not be correctly used in your example since it will capture the entire string including the -
which yields a non-numeric string that cannot be converted (hence the error).
filterTags:
extract: $ts$inc
pattern: ^(?P<ts>[0-9]+)-(?P<inc>[0-9]+)$
policy:
numerical:
order: asc
You could technically also use SemVer with your version pattern, something like this should also work since the part after the -
will be considered a SemVer pre-release tag.
filterTags:
pattern: ^[0-9]+-[0-9]+$
policy:
semver:
range: >=x-0
Thanks @relu, that works!