<p>I occasionally get such an error "the object has been modified; please apply your changes to the latest version and try again" when I update node or deploy with client-go.My goal is that adding a taint/toleration and a label to one node/deployment.</p>

<p>some people said should use</p>

<pre><code>err = retry.RetryOnConflict(retry.DefaultBackoff, func() error {})
</code></pre>

<p>,but it seems that does not work.</p>

<pre><code>func AddFaultToleration(deploy *appsv1.Deployment, ns string, client kubernetes.Interface) (*appsv1.Deployment, error) {

    updateDeploy, err := client.AppsV1().Deployments(ns).Get(deploy.Name, metav1.GetOptions{})
    if updateDeploy == nil || err != nil {
        return deploy, fmt.Errorf("Failed to get latest version of Deployment: %v", err)
    }

    effect := apiv1.TaintEffectNoExecute
    updateDeploy.Spec.Template.Spec.Tolerations = append(updateDeploy.Spec.Template.Spec.Tolerations, apiv1.Toleration{
        Key:      ToBeFaultTaintKey,
        Value:    ToBeFaultTaintValue,
        Effect:   effect,
        Operator: apiv1.TolerationOpEqual,
    })

    updatedDeployWithTolera, err := client.AppsV1().Deployments(ns).Update(updateDeploy)
    if err != nil || updatedDeployWithTolera == nil {
        return deploy, fmt.Errorf("failed to update deploy %v after adding toleration: %v", deploy.Name, err)
    }

    log.Info("Successfully added toleration on pod:", updatedDeployWithTolera.Name)
    return updatedDeployWithTolera, nil
}

</code></pre>

Toni.W
<p>I have solved the problem. the reason is that the err of conflict is hided by</p>

<pre><code>updatedDeployWithTolera, err := client.AppsV1().Deployments(ns).Update(updateDeploy) if err != nil || updatedDeployWithTolera == nil { return deploy, fmt.Errorf("failed to update deploy %v after adding toleration: %v", deploy.Name, err)}
</code></pre>

<p>,So the function of retry.RetryOnConflict doesn't work.</p>
