Skip to content

Commit 2bf2fc7

Browse files
author
Ankita Thomas
committed
Retry conflicting update after fetching latest pod spec
1 parent ffaa9bc commit 2bf2fc7

File tree

1 file changed

+22
-4
lines changed
  • pkg/controller/registry/reconciler

1 file changed

+22
-4
lines changed

pkg/controller/registry/reconciler/grpc.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package reconciler
33
import (
44
"context"
55
"fmt"
6-
76
"github.com/operator-framework/api/pkg/operators/v1alpha1"
87
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
98
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
@@ -14,7 +13,10 @@ import (
1413
v1 "k8s.io/api/core/v1"
1514
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1615
"k8s.io/apimachinery/pkg/labels"
16+
"k8s.io/apimachinery/pkg/runtime/schema"
17+
"k8s.io/apimachinery/pkg/types"
1718
"k8s.io/apimachinery/pkg/util/intstr"
19+
"sigs.k8s.io/controller-runtime/pkg/client"
1820
)
1921

2022
const CatalogSourceUpdateKey = "catalogsource.operators.coreos.com/update"
@@ -198,12 +200,28 @@ func (c *GrpcRegistryReconciler) ensureUpdatePod(source grpcCatalogSourceDecorat
198200
updatePod.Labels[CatalogSourceUpdateKey] = ""
199201

200202
// Update the update pod to promote it to serving pod
201-
_, err := c.OpClient.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).Update(context.TODO(), updatePod, metav1.UpdateOptions{})
203+
forceApply := true
204+
opts := metav1.PatchOptions{
205+
Force: &forceApply,
206+
FieldManager: "operator-lifecycle-manager-registry-reconciler",
207+
}
208+
209+
updatePodBytes, err := client.Apply.Data(updatePod)
202210
if err != nil {
203-
return errors.Wrapf(err, "error creating new pod: %s", source.Pod().GetName())
211+
return errors.Wrapf(err, "error serializing updated catalog source pod to bytes: %s", source.Pod().GetName())
204212
}
205213

206-
break
214+
if updatePod.GroupVersionKind().Empty() {
215+
updatePod.SetGroupVersionKind(schema.GroupVersionKind{
216+
Group: "",
217+
Version: "v1",
218+
Kind: "Pod",
219+
})
220+
}
221+
_, err = c.OpClient.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).Patch(context.TODO(), updatePod.Name, types.ApplyPatchType, updatePodBytes, opts)
222+
if err != nil {
223+
return errors.Wrapf(err, "error updating catalog source pod: %s", source.Pod().GetName())
224+
}
207225
}
208226
}
209227

0 commit comments

Comments
 (0)