flux2
flux2 copied to clipboard
why is imagePolicy triggering error
My Issue: I have a job that is used to on-demand pull down a one shot pod which moves some content into my environment. since it is not reoccurring this is the perfect type for it.
apiVersion: batch/v1
kind: Job
when I have the job just as a deployment, aka no image-repository checking or updating, it seems to work just fine.
When I attempt to add an updater it throws this error:
ImagePolicy/flux-system/frontend-deployer-latest dry-run failed, error: failed to create typed patch object: .spec.template: field not declared in schema
My suspicion is that image.toolkit just really dose not like kube jobs.
looking for opinions
.
├── base
│ ├
│ └── frontend-deployer
│ ├── job.yaml
│ ├── kustomization.yaml
│ └── updater.yaml
└── dev
├── frontend-deployer-latest.yaml
└── kustomization.yaml
updater.yaml
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
metadata:
name: frontend-deployer
namespace: flux-system
spec:
image: ghcr.io/vodori/frontend-deployer
interval: 1m0s
secretRef:
name: regcred
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
name: frontend-deployer-${version}
namespace: flux-system
spec:
imageRepositoryRef:
name: frontend-deployer
filterTags:
pattern: "^${tracking_branch}-[a-f0-9]+-(?P<ts>[0-9]+)"
extract: '$ts'
policy:
numerical:
order: asc
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageUpdateAutomation
metadata:
name: frontend-deployer-${version}
namespace: flux-system
spec:
interval: 1m0s
sourceRef:
kind: GitRepository
name: flux-system
git:
checkout:
ref:
branch: ${branch}
commit:
author:
email: [email protected]
name: fluxcdbot
messageTemplate: '{{range .Updated.Images}}{{println .}}{{end}}'
push:
branch: ${branch}
update:
path: ./apps/${update_dir}
strategy: Setters
job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: frontend-deployer-${version}
namespace: ${target_namespace}
spec:
template:
spec:
imagePullSecrets:
- name: regcred
containers:
- name: frontend-deployer
image: ghcr.io/vodori/frontend-deployer:latest-main
imagePullPolicy: Always
env:
- name: PREFIX
value: /etc/nginx/html
- name: AWS_ENV_NAME
valueFrom:
configMapKeyRef:
name: aws-env-info
key: name
- name: DOCKER_HOST
value: tcp://localhost:2375
volumeMounts:
- name: regcred
mountPath: "/root/.docker-secret/"
readOnly: true
- name: semaphore
mountPath: /signal
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -c
- touch /signal/healthy; /root/.docker/config.json
preStop:
exec:
command:
- /bin/sh
- -c
- rm -rf /signal/healthy
- name: dind-daemon
image: docker:1.12.6-dind
resources:
#### Snipped some unimportant stuff
serviceAccountName: vodori-flow-frontend
restartPolicy: Never
frontend-deployer-latest.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: frontend-deployer-latest
namespace: flux-system
spec:
interval: 1m0s
path: ./apps/base/frontend-deployer
prune: true
sourceRef:
kind: GitRepository
name: flux-system
images:
- name: ghcr.io/vodori/frontend-deployer
newTag: latest-main # {"$imagepolicy": "flux-system:frontend-deployer-latest:tag"}
postBuild:
substitute:
update_dir: dev
version: latest
tracking_branch: main
target_namespace: cloud-dev
develop: develop-8d146f6b-1655137519 # {"$imagepolicy": "flux-system:flow-frontend-latest:tag"}
r18: release-R18-fc4485f5-1655230817 # {"$imagepolicy": "flux-system:flow-frontend-r18:tag"}
r17: release-R17-8d146f6b-1655139849 # {"$imagepolicy": "flux-system:flow-frontend-r17:tag"}
substituteFrom:
- kind: ConfigMap
name: cluster-vars
wait: true
force: true
patches:
- patch: |-
apiVersion: batch/v1
kind: Job
metadata:
name: frontend-deployer
namespace: ${target_namespace}
spec:
template:
spec:
containers:
- name: frontend-deployer
env:
- name: ARTIFACT_LATEST
value: ghcr.io/vodori/flow-frontend:${develop}
- name: ARTIFACT_R18
value: ghcr.io/vodori/flow-frontend:${r18}
- name: ARTIFACT_R17
value: ghcr.io/vodori/flow-frontend:${r17}
kustomization.yaml (in base)
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- job.yaml
- updater.yaml
commonLabels:
app: frontend-deployer
version: ${version}
Originally posted by @jvr-vodori in https://github.com/fluxcd/flux2/discussions/2846
This error seems to be from the kustomize-controller. It is unable to apply the Image policy
ImagePolicy/flux-system/frontend-deployer-latest dry-run failed, error: failed to create typed patch object: .spec.template: field not declared in schema
Can you cross-check your ImagePolicy/flux-system/frontend-deployer-latest to be sure it is valid?
This error seems to be from the kustomize-controller. It is unable to apply the Image policy
Can you cross-check your
ImagePolicy/flux-system/frontend-deployer-latestto be sure it is valid?
So here is the interesting part, If I comment out updater.yaml in the kustomization.yaml it does not throw that error and works just fine.. (with the exception of never triggering a deploy when flux-system:frontend-deployer-latest is triggered)
Hmm. Tried out your example on my end and it works okay.
Not sure where it's seeing a spec.template field. Can you try putting the ImagePolicy in a different yaml.
Closing this as we can't replicate the error, please comment here if you still have this issue.