flux2: Resource deletion/recreation fails when immutable changed and force: true
Describe the bug
I’ve tried to do a running jobs via Flux tutorial (https://fluxcd.io/flux/use-cases/running-jobs/) and there is a bug i think.
Job/default/db-migration immutable field detected, failed to delete object, error: jobs.batch "db-migration" not found...
Seems like some race condition - after repo sync force: true, item is deleted in real, but Flux try to do load / delete it second time.
Steps to reproduce
Software Installed:
Flux:
% flux -v
flux version 0.36.0
K8S (Docker Desktop for Mac):
% kubectl version --short
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.25.2
Kustomize Version: v4.5.7
Server Version: v1.25.2
Please clone my error proof repo: https://github.com/vinkiel/flux-prune-bug.git
Or better fork it, change repo address in flux/gotk-sync.yaml to your
Go to repo folder
Starting with empty flux-system and default namespaces:
kubectl apply -k flux
Results:
namespace/flux-system created
customresourcedefinition.apiextensions.k8s.io/alerts.notification.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/buckets.source.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/gitrepositories.source.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/helmcharts.source.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/helmreleases.helm.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/helmrepositories.source.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/kustomizations.kustomize.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/ocirepositories.source.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/providers.notification.toolkit.fluxcd.io created
customresourcedefinition.apiextensions.k8s.io/receivers.notification.toolkit.fluxcd.io created
serviceaccount/helm-controller created
serviceaccount/kustomize-controller created
serviceaccount/notification-controller created
serviceaccount/source-controller created
clusterrole.rbac.authorization.k8s.io/crd-controller-flux-system created
clusterrolebinding.rbac.authorization.k8s.io/cluster-reconciler-flux-system created
clusterrolebinding.rbac.authorization.k8s.io/crd-controller-flux-system created
service/notification-controller created
service/source-controller created
service/webhook-receiver created
deployment.apps/helm-controller created
deployment.apps/kustomize-controller created
deployment.apps/notification-controller created
deployment.apps/source-controller created
kustomization.kustomize.toolkit.fluxcd.io/flux-system created
networkpolicy.networking.k8s.io/allow-egress created
networkpolicy.networking.k8s.io/allow-scraping created
networkpolicy.networking.k8s.io/allow-webhooks created
gitrepository.source.toolkit.fluxcd.io/flux-system created
kubectl apply -k app-ci
kustomization.kustomize.toolkit.fluxcd.io/app-deploy created
kustomization.kustomize.toolkit.fluxcd.io/app-pre-deploy created
kubectl get gitrepository -n flux-system
NAME URL AGE READY STATUS
flux-system https://github.com/vinkiel/flux-prune-bug.git 90s True stored artifact for revision 'main/037f48ace8b2dd2381c4fa652317e237268fae6f'
kubectl get kustomization -n flux-system
NAME AGE READY STATUS
app-deploy 2m55s True Applied revision: main/037f48ace8b2dd2381c4fa652317e237268fae6f
app-pre-deploy 2m55s True Applied revision: main/037f48ace8b2dd2381c4fa652317e237268fae6f
flux-system 2m55s True Applied revision: main/037f48ace8b2dd2381c4fa652317e237268fae6f
kubectl get pod
NAME READY STATUS RESTARTS AGE
db-migration-8lmwz 0/1 Completed 0 5m22s
webserver 1/1 Running 0 4m57s
kubectl logs db-migration-8lmwz
(use pod that was listed in real)
starting db migration
Looks good till now.
Now change tag of busybox in pre-deploy/migration.job.yaml to 1.33, 1.34, 1.35 etc. , commit and push to main branch. Wait for sync (you can use kubectl get kustomization -n flux-system -w to observe)
kubectl get kustomization -n flux-system
NAME AGE READY STATUS
app-deploy 11m False dependency 'flux-system/app-pre-deploy' revision is not up to date
app-pre-deploy 11m False Job/default/db-migration immutable field detected, failed to delete object, error: jobs.batch "db-migration" not found...
flux-system 11m True Applied revision: main/c90a7a1657c2bde80a2e61081f0147c766550392
Job/default/db-migration immutable field detected, failed to delete object, error: jobs.batch "db-migration" not found... is the error that blocks deployment.
However Job was removed due force: true:
kubectl get jobs
No resources found in default namespace.
This configuration works best when the Jobs are using the same image and tag as the application being deployed. When a new version of the application is deployed, the image tags are updated. The update of the image tag will force a recreation of the Jobs.
Note: issue is not repeatable every time, so seems like a race condition. Please change version of busybox few time more if first try pass with no errors. Note: when error occured, next tag update commit will trigger Jobs creation successfully
Expected behavior
There should be no error Job/default/db-migration immutable field detected, failed to delete object, error: jobs.batch "db-migration" not found... and jobs should be recreated smooth way
BTW. Any ideas how to run pre/post deployment jobs different within Flux only?
Screenshots and recordings
No response
OS / Distro
Mac OS 12.1 (21C52)
Flux version
flux: v0.36.0
Flux check
► checking prerequisites ✔ Kubernetes 1.25.2 >=1.20.6-0 ► checking controllers ✔ helm-controller: deployment ready ► ghcr.io/fluxcd/helm-controller:v0.26.0 ✔ kustomize-controller: deployment ready ► ghcr.io/fluxcd/kustomize-controller:v0.30.0 ✔ notification-controller: deployment ready ► ghcr.io/fluxcd/notification-controller:v0.28.0 ✔ source-controller: deployment ready ► ghcr.io/fluxcd/source-controller:v0.31.0 ► checking crds ✔ alerts.notification.toolkit.fluxcd.io/v1beta1 ✔ buckets.source.toolkit.fluxcd.io/v1beta2 ✔ gitrepositories.source.toolkit.fluxcd.io/v1beta2 ✔ helmcharts.source.toolkit.fluxcd.io/v1beta2 ✔ helmreleases.helm.toolkit.fluxcd.io/v2beta1 ✔ helmrepositories.source.toolkit.fluxcd.io/v1beta2 ✔ kustomizations.kustomize.toolkit.fluxcd.io/v1beta2 ✔ ocirepositories.source.toolkit.fluxcd.io/v1beta2 ✔ providers.notification.toolkit.fluxcd.io/v1beta1 ✔ receivers.notification.toolkit.fluxcd.io/v1beta1 ✔ all checks passed
Git provider
No response
Container Registry provider
No response
Additional context
No response
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 6
- Comments: 16 (5 by maintainers)
I’m also facing this