Skip to content

Commit e562bd9

Browse files
author
Ankita Thomas
committed
Retry conflicting update after fetching latest pod spec
1 parent ff94842 commit e562bd9

File tree

1 file changed

+18
-3
lines changed
  • pkg/controller/registry/reconciler

1 file changed

+18
-3
lines changed

pkg/controller/registry/reconciler/grpc.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package reconciler
33
import (
44
"context"
55
"fmt"
6+
"k8s.io/apiserver/pkg/registry/generic/registry"
67

78
"github.com/operator-framework/api/pkg/operators/v1alpha1"
89
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
910
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
1011
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
1112
"github.com/pkg/errors"
13+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1214
"github.com/sirupsen/logrus"
1315
corev1 "k8s.io/api/core/v1"
1416
v1 "k8s.io/api/core/v1"
@@ -199,11 +201,24 @@ func (c *GrpcRegistryReconciler) ensureUpdatePod(source grpcCatalogSourceDecorat
199201

200202
// Update the update pod to promote it to serving pod
201203
_, err := c.OpClient.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).Update(context.TODO(), updatePod, metav1.UpdateOptions{})
202-
if err != nil {
203-
return errors.Wrapf(err, "error creating new pod: %s", source.Pod().GetName())
204+
if err == nil {
205+
break
204206
}
207+
if !(apierrors.IsConflict(err) && err.Error() == registry.OptimisticLockErrorMsg) {
208+
return errors.Wrapf(err, "error updating catalog source pod labels: %s", source.Pod().GetName())
209+
}
210+
211+
// stale pod, fetch and try again
212+
updatePod, err = c.Lister.CoreV1().PodLister().Pods(source.GetNamespace()).Get(updatePod.Name)
213+
updatePod.Labels[CatalogSourceLabelKey] = source.GetName()
214+
updatePod.Labels[CatalogSourceUpdateKey] = ""
205215

206-
break
216+
// Update the update pod to promote it to serving pod
217+
_, err = c.OpClient.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).Update(context.TODO(), updatePod, metav1.UpdateOptions{})
218+
if err == nil {
219+
break
220+
}
221+
return errors.Wrapf(err, "error updating catalog source pod labels: %s", source.Pod().GetName())
207222
}
208223
}
209224

0 commit comments

Comments
 (0)