Skip to content

Commit 37efcf0

Browse files
authored
fix(backend): add check for casting (kubeflow#1040)
Add check for type cast. make sure the watcher receives Pod event. Signed-off-by: Yihong Wang <[email protected]> Signed-off-by: Yihong Wang <[email protected]>
1 parent 51e7623 commit 37efcf0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

backend/src/cache/server/watcher.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"log"
87
"reflect"
98
"strconv"
109
"time"
@@ -47,12 +46,16 @@ func WatchPods(ctx context.Context, namespaceToWatch string, clientManager Clien
4746
}
4847

4948
for event := range watcher.ResultChan() {
50-
pod := reflect.ValueOf(event.Object).Interface().(*corev1.Pod)
49+
pod, ok := reflect.ValueOf(event.Object).Interface().(*corev1.Pod)
50+
if !ok {
51+
logger.Warnf("Not processing WatchPods as event Object is not a Pod, event type: %s", event.Type)
52+
continue
53+
}
54+
5155
if event.Type == watch.Error {
5256
logger.Errorf("Watcher error in loop: %v", event.Type)
5357
continue
5458
}
55-
log.Printf((*pod).GetName())
5659

5760
if !isPodCompletedAndSucceeded(pod) {
5861
logger.Warnf("Pod %s is not completed or not in successful status, skip the loop.", pod.ObjectMeta.Name)

0 commit comments

Comments
 (0)