Search code examples
githubkubernetesfluxcd

Flux V2 not pushing new image version to git repo


I've upgrade from Flux V1 to V2. It all went fairly smooth but I can't seem to get the ImageUpdateAutomation to work. Flux knows I have images to update but it doesn't change the container image in the deployment.yaml manifest and commit the changes to Github. I have no errors in my logs so I'm at a bit of a loss as to what to do next.

I have an file structure that looks something like this:

├── README.md
├── staging
│   ├── api
│   │   ├── deployment.yaml
│   │   ├── automation.yaml
│   │   └── service.yaml
│   ├── app
│   │   ├── deployment.yaml
│   │   ├── automation.yaml
│   │   └── service.yaml
│   ├── flux-system
│   │   ├── gotk-components.yaml
│   │   ├── gotk-sync.yaml
│   │   └── kustomization.yaml
│   ├── image_update_automation.yaml

My staging/api/automation.yaml is pretty strait-forward:

---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
metadata:
  name: api
  namespace: flux-system
spec:
  image: xxx/api
  interval: 1m0s
  secretRef:
    name: dockerhub

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

My staging/image_update_automation.yaml looks something like this:

---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageUpdateAutomation
metadata:
  name: flux-system
  namespace: flux-system
spec:
  git:
    checkout:
      ref:
        branch: master
    commit:
      author:
        email: fluxcdbot@users.noreply.github.com
        name: fluxcdbot
      messageTemplate: '{{range .Updated.Images}}{{println .}}{{end}}'
    push:
      branch: master
  interval: 1m0s
  sourceRef:
    kind: GitRepository
    name: flux-system
  update:
    path: ./staging
    strategy: Setters

Everything seems to be ok here:

❯ flux get image repository
NAME    READY   MESSAGE                         LAST SCAN                   SUSPENDED
api True    successful scan, found 23 tags  2021-07-28T17:11:02-06:00   False
app True    successful scan, found 18 tags  2021-07-28T17:11:02-06:00   False

❯ flux get image policy
NAME    READY   MESSAGE                                                             LATEST IMAGE
api True    Latest image tag for 'xxx/api' resolved to: 1.0.1   xxx/api:1.0.1
app True    Latest image tag for 'xxx/app' resolved to: 3.2.1   xxx/app:3.2.1

As you can see from the policy output the LATEST IMAGE api is 1.0.1, however when I view the current version of my app and api they have not been updated.

kubectl get deployment api -n xxx -o json | jq '.spec.template.spec.containers[0].image'
"xxx/api:0.1.5"

Any advice on this would be much appreciated.


Solution

  • My issue was that I didn't add the comment after my image declaration in my deployment yaml. More details. Honestly, I'm surprised this is not Annotation instead of a comment.

        spec:
          containers:
            - image: docker.io/xxx/api:0.1.5 # {"$imagepolicy": "flux-system:api"}