Describe the bug
Argo application SyncFailed with:
applications.argoproj.io "argocd" is invalid: metadata.resourceVersion: Invalid value: 0x0: must be specified for an update
The diff is showing that argocd wants to remove metadata of generation, selfLink, etc.
To Reproduce
A list of the steps required to reproduce the issue. Best of all, give us the URL to a repository that exhibits this issue.
https://github.com/hashbang/gitops/blob/master/argocd/applications/argocd.yaml
Expected behavior
Apply succeeds
Screenshots


Version
v1.5.5+0fdef48
Hello @daurnimator ,
I suspect this might happen because someone edited application resource using kubectl edit and kubectl.kubernetes.io/last-applied-configuration no longer valid.
Mixing imperative and declarative kubectl commands might cause inconsistent diff: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/#how-to-update-objects
I suggest trying to remove kubectl.kubernetes.io/last-applied-configuration annotation from that application.
edited application resource using
kubectl editandkubectl.kubernetes.io/last-applied-configurationno longer valid.
Yes this appeared to be the issue: I manually edited the annotation to remove the extra fields and was able to get argocd to sync.
However, I don't think anyone manually applied those changes.... we did have a (Digital Ocean managed) cluster upgrade in the same time period: I wonder if they dump things out and feed them back in with kubectl apply?
We had a similar issues on a few resources; e.g. argocd wanted to delete all the local user secrets out of the argocd-secret.
Closing as I don't think we'll be able to replicate :(
It is solved by getting the existing resource version and add it to the update object before applying.
getObj, err := dr.Get(obj.GetName(), metav1.GetOptions{})
if errors.IsNotFound(err) {
// This doesnt ever happen even if it is already deleted or not found
log.Printf("%v not found", obj.GetName())
return nil, nil
}
if err != nil {
return nil, err
}
obj.SetResourceVersion(getObj.GetResourceVersion())
response, err := dr.Update(obj, metav1.UpdateOptions{})
if err != nil {
return nil, err
}
Most helpful comment
Hello @daurnimator ,
I suspect this might happen because someone edited application resource using
kubectl editandkubectl.kubernetes.io/last-applied-configurationno longer valid.Mixing imperative and declarative kubectl commands might cause inconsistent diff: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/#how-to-update-objects
I suggest trying to remove
kubectl.kubernetes.io/last-applied-configurationannotation from that application.