Apply failed with 1 conflict #2304
-
Hello, I'm experiencing an error since a few days and I can't find the root cause of it neither any satisfying explanations about it. Here is the error message:
I don't understand where this "manager" comes from and what does it means by conflict? I mean, I got this error at the creation of a CR, how can it conflicts with nothing? And why the status is conflicting while I don't even set it? Here is a sample of my code (It seems that the errors come from the func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
var pod corev1.Pod
if err := r.Get(ctx, req.NamespacedName, &pod); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
cachedImages, err := r.desiredCachedImages(pod)
if err != nil {
return ctrl.Result{}, err
}
applyOpts := []client.PatchOption{
client.FieldOwner("pod-controller"),
}
for _, cachedImage := range cachedImages {
_ = cachedImage
err = r.Patch(ctx, &cachedImage, client.Apply, applyOpts...)
if err != nil {
return ctrl.Result{}, err
}
}
return ctrl.Result{}, nil
}
func (r *PodReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&corev1.Pod{}).
Complete(r)
}
func (r *PodReconciler) desiredCachedImages(pod corev1.Pod) ([]dcrenixiov1alpha1.CachedImage, error) {
containers := append(pod.Spec.Containers, pod.Spec.InitContainers...)
cachedImages := []dcrenixiov1alpha1.CachedImage{}
for i, container := range containers {
sourceImage, ok := pod.Annotations[fmt.Sprintf("tugger-original-image-%d", i)]
if !ok {
continue
}
re := regexp.MustCompile(`localhost:[0-9]+/`)
image := string(re.ReplaceAll([]byte(container.Image), []byte("")))
sanitizedName := cache.SanitizeImageName(image)
cachedImage := dcrenixiov1alpha1.CachedImage{
TypeMeta: metav1.TypeMeta{APIVersion: dcrenixiov1alpha1.GroupVersion.String(), Kind: "CachedImage"},
ObjectMeta: metav1.ObjectMeta{
Name: sanitizedName,
},
Spec: dcrenixiov1alpha1.CachedImageSpec{
Image: image,
SourceImage: sourceImage,
},
}
cachedImages = append(cachedImages, cachedImage)
}
return cachedImages, nil
} EDIT: I surprisingly "fixed" my issue by just adding |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Your error indicates that there's a conflict during a server-side apply operation, specifically related to the .status field of a resource managed by another controller named "manager". This conflict arises due to overlapping ownership of fields when using server-side apply in Kubernetes. Let's dissect this:
However, server-side is not support yet in controller-tools or controller-runtime so consequently it is not support in kubebuilder too, You can check the progress of this work here: Marking it as answered and closing this one. |
Beta Was this translation helpful? Give feedback.
Your error indicates that there's a conflict during a server-side apply operation, specifically related to the .status field of a resource managed by another controller named "manager". This conflict arises due to overlapping ownership of fields when using server-side apply in Kubernetes.
Let's dissect this:
Server-side Apply and Field Management: Server-side apply uses a mechanism called field management. Every field in a resource is owned by a manager (a controller, user, etc.) that has set its value using the server-side apply. The manager's name is typically derived from the User-Agent HTTP header, but with controller-runtime, it's often the controller's name. In your error, there s…