Skip to content

Commit a6ba3dd

Browse files
author
Prince Rachit Sinha
committed
[ws-manager] Add missing check to fix OOM error
1 parent aa52b3e commit a6ba3dd

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

components/ws-manager/pkg/manager/manager.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,37 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
235235
retryErr = err
236236

237237
var tempPod corev1.Pod
238-
getErr := m.Clientset.Get(ctx, types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}, &tempPod)
239-
if getErr != nil {
240-
clog.WithError(getErr).WithField("pod.Namespace", pod.Namespace).WithField("pod.Name", pod.Name).Error("was unable to get pod")
241-
// pod doesn't exist, so we are safe to proceed with retry
242-
return false, nil
238+
finalizerRemoved := false
239+
// We do below in loop as sometimes the pod might be already deleted or modified when we attempt to remove the finalizer
240+
// so we first get the pod and then attempt to remove the finalizer
241+
// in case the pod is not found in the first place, we return success
242+
for i := 0; i < 3 && !finalizerRemoved; i++ {
243+
getErr := m.Clientset.Get(ctx, types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}, &tempPod)
244+
if getErr != nil {
245+
if !k8serr.IsNotFound(getErr) {
246+
// pod doesn't exist, so we are safe to proceed with retry
247+
return true, nil
248+
}
249+
clog.WithError(getErr).WithField("pod.Namespace", pod.Namespace).WithField("pod.Name", pod.Name).Error("was unable to get pod")
250+
// pod get call failed so we error out
251+
return false, retryErr
252+
}
253+
// we successfully got the pod, now we attempt to remove finalizer
254+
tempPod.Finalizers = []string{}
255+
updateErr := m.Clientset.Update(ctx, &tempPod)
256+
if updateErr != nil {
257+
clog.WithError(updateErr).WithField("pod.Namespace", pod.Namespace).WithField("pod.Name", pod.Name).Error("was unable to remove finalizer")
258+
continue
259+
}
260+
finalizerRemoved = true
243261
}
244-
tempPod.Finalizers = []string{}
245-
updateErr := m.Clientset.Update(ctx, &tempPod)
246-
if updateErr != nil {
247-
clog.WithError(updateErr).WithField("pod.Namespace", pod.Namespace).WithField("pod.Name", pod.Name).Error("was unable to remove finalizer")
248-
// failed to remove finalizer, we not going to be able to create a new pod, so bail out with retry error
262+
// if even after retries we could not remove finalizers, then error out
263+
if !finalizerRemoved {
249264
return false, retryErr
250265
}
251266

252267
deleteErr := m.Clientset.Delete(ctx, &tempPod)
253-
if deleteErr != nil {
268+
if deleteErr != nil && !k8serr.IsNotFound(deleteErr) {
254269
clog.WithError(deleteErr).WithField("pod.Namespace", pod.Namespace).WithField("pod.Name", pod.Name).Error("was unable to delete pod")
255270
// failed to delete pod, so not going to be able to create a new pod, so bail out
256271
return false, retryErr

0 commit comments

Comments
 (0)