fluxcd/image-reflector-controller

Image policy for PiHole year-based releases `yyyy.mm.patch`

rjhenry opened this issue · 5 comments

The PiHole project have recently switched from v5.x.y to year-based releases: yyyy.mm.patch, as seen here:
https://registry.hub.docker.com/r/pihole/pihole/tags

I'd expect a SemVer ImagePolicy set like so:

apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
  name: pihole
  namespace: flux-system
spec:
  imageRepositoryRef:
    name: pihole
    namespace: pihole
  policy:
    semver:
      range: '>=1.0.0'

to return a value in the 2022.04.x range (at time of writing) but it shows that 2021.12.1 is the highest:

status:
  conditions:
  - lastTransitionTime: "2022-04-26T12:36:49Z"
    message: 'Latest image tag for ''pihole/pihole'' resolved to: 2021.12.1'
    reason: ReconciliationSucceeded
    status: "True"
    type: Ready
  latestImage: pihole/pihole:2021.12.1
  observedGeneration: 9

Now, I'm no expert, but 2022 seems to be bigger than 2021 in terms of "major version number", so wouldn't the policy be expected to return one of those?

The ImageRepository seems to find the right number of tags; it shows 45 tags found, which matches what I'd expect from a quick count of the tags, though I can't confirm that it's seeing 2022.x.y tags without finding some way to dump the found tags.

Debug logs from the image reflector controller are below:

{"level":"debug","ts":"2022-04-26T12:49:18.443Z","logger":"events","msg":"Warning","object":{"kind":"ImagePolicy","namespace":"flux-system","name":"pihole","uid":"077b9c00-00d3-4863-807b-98b49af2c9f6","apiVersion":"image.toolkit.fluxcd.io/v1beta1","resourceVersion":"177377195"},"reason":"error","message":"Cannot determine latest tag for policy: version list argument cannot be empty"}
{"level":"error","ts":"2022-04-26T12:49:18.450Z","logger":"controller.imagepolicy","msg":"Reconciler error","reconciler group":"image.toolkit.fluxcd.io","reconciler kind":"ImagePolicy","name":"pihole","namespace":"flux-system","error":"Cannot determine latest tag for policy: version list argument cannot be empty","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:227"}
{"level":"error","ts":"2022-04-26T12:49:18.611Z","msg":"Cannot determine latest tag for policy: version list argument cannot be empty","name":"pihole","namespace":"flux-system","reconciler kind":"ImagePolicy","annotations":null,"error":"error","stacktrace":"github.com/fluxcd/pkg/runtime/events.(*Recorder).Eventf\n\t/go/pkg/mod/github.com/fluxcd/pkg/runtime@v0.14.1/events/recorder.go:113\ngithub.com/fluxcd/image-reflector-controller/controllers.(*ImagePolicyReconciler).event\n\t/workspace/controllers/imagepolicy_controller.go:265\ngithub.com/fluxcd/image-reflector-controller/controllers.(*ImagePolicyReconciler).Reconcile.func1\n\t/workspace/controllers/imagepolicy_controller.go:102\ngithub.com/fluxcd/image-reflector-controller/controllers.(*ImagePolicyReconciler).Reconcile\n\t/workspace/controllers/imagepolicy_controller.go:186\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:114\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:311\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:227"}
{"level":"debug","ts":"2022-04-26T12:49:18.612Z","logger":"events","msg":"Warning","object":{"kind":"ImagePolicy","namespace":"flux-system","name":"pihole","uid":"077b9c00-00d3-4863-807b-98b49af2c9f6","apiVersion":"image.toolkit.fluxcd.io/v1beta1","resourceVersion":"177377195"},"reason":"error","message":"Cannot determine latest tag for policy: version list argument cannot be empty"}
{"level":"error","ts":"2022-04-26T12:49:18.618Z","logger":"controller.imagepolicy","msg":"Reconciler error","reconciler group":"image.toolkit.fluxcd.io","reconciler kind":"ImagePolicy","name":"pihole","namespace":"flux-system","error":"Cannot determine latest tag for policy: version list argument cannot be empty","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:227"}
{"level":"error","ts":"2022-04-26T12:49:18.939Z","msg":"Cannot determine latest tag for policy: version list argument cannot be empty","name":"pihole","namespace":"flux-system","reconciler kind":"ImagePolicy","annotations":null,"error":"error","stacktrace":"github.com/fluxcd/pkg/runtime/events.(*Recorder).Eventf\n\t/go/pkg/mod/github.com/fluxcd/pkg/runtime@v0.14.1/events/recorder.go:113\ngithub.com/fluxcd/image-reflector-controller/controllers.(*ImagePolicyReconciler).event\n\t/workspace/controllers/imagepolicy_controller.go:265\ngithub.com/fluxcd/image-reflector-controller/controllers.(*ImagePolicyReconciler).Reconcile.func1\n\t/workspace/controllers/imagepolicy_controller.go:102\ngithub.com/fluxcd/image-reflector-controller/controllers.(*ImagePolicyReconciler).Reconcile\n\t/workspace/controllers/imagepolicy_controller.go:186\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:114\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:311\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:227"}
{"level":"debug","ts":"2022-04-26T12:49:18.939Z","logger":"events","msg":"Warning","object":{"kind":"ImagePolicy","namespace":"flux-system","name":"pihole","uid":"077b9c00-00d3-4863-807b-98b49af2c9f6","apiVersion":"image.toolkit.fluxcd.io/v1beta1","resourceVersion":"177377195"},"reason":"error","message":"Cannot determine latest tag for policy: version list argument cannot be empty"}
{"level":"error","ts":"2022-04-26T12:49:18.946Z","logger":"controller.imagepolicy","msg":"Reconciler error","reconciler group":"image.toolkit.fluxcd.io","reconciler kind":"ImagePolicy","name":"pihole","namespace":"flux-system","error":"Cannot determine latest tag for policy: version list argument cannot be empty","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.2/pkg/internal/controller/controller.go:227"}
{"level":"info","ts":"2022-04-26T12:49:19.219Z","logger":"controller.imagerepository","msg":"reconciliation finished in 1.043526689s, next run in 10m0s","reconciler group":"image.toolkit.fluxcd.io","reconciler kind":"ImageRepository","name":"pihole","namespace":"pihole"}
{"level":"info","ts":"2022-04-26T12:49:19.225Z","msg":"Latest image tag for 'pihole/pihole' resolved to: 2021.12.1","name":"pihole","namespace":"flux-system","reconciler kind":"ImagePolicy","reason":"info","annotations":null}
{"level":"debug","ts":"2022-04-26T12:49:19.225Z","logger":"events","msg":"Normal","object":{"kind":"ImagePolicy","namespace":"flux-system","name":"pihole","uid":"077b9c00-00d3-4863-807b-98b49af2c9f6","apiVersion":"image.toolkit.fluxcd.io/v1beta1","resourceVersion":"177377195"},"reason":"info","message":"Latest image tag for 'pihole/pihole' resolved to: 2021.12.1"}

If there's anything else needed, please shout - I'm happy to assist with any information I can provide! I'm sure I'm missing something small, but I can't find it for the life of me.

Semver does not accept 0 as prefix, so you can't use it. It works for 2021.12.1 because there is no 0 like in 2022.04.1.

Ah, I understand. Many thanks for your quick response!

We also support alphabetical ordering, maybe try that.

Yeah, I'm just drafting up that change now, with an accompanying comment to explain to the next person (read: me in six months) why it looks like a semver and is treated alphabetically. Many thanks!

Just as a note for future people, note that it's not quite so simple for this particular instance; in short, the older tags (4.3.2-1) beat the 2022.x.y versions as 4 > 2.

I've got things working using the following filterTags value.

filterTags:
  extract: $ds
  pattern: ^20(?P<ds>[0-9\.]+)$

You could probably optimise this further, but it seems to work for me.