Skip to content

Commit b07d3c9

Browse files
committed
update
1 parent 7ccdf82 commit b07d3c9

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pkg/job/runtime_v2/job/util/kuberuntime/job_event_handler.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ package kuberuntime
1818

1919
import (
2020
"fmt"
21+
"reflect"
2122
"strings"
2223
"time"
2324

2425
log "github.com/sirupsen/logrus"
25-
"k8s.io/api/core/v1"
26+
v1 "k8s.io/api/core/v1"
2627
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2728
"k8s.io/apimachinery/pkg/runtime"
2829
k8sschema "k8s.io/apimachinery/pkg/runtime/schema"
@@ -89,7 +90,11 @@ func getJobStatus(statusInfo api.StatusInfo, annotations map[string]string) api.
8990
}
9091

9192
func JobAddFunc(obj interface{}, getStatusFunc api.GetStatusFunc) (*api.JobSyncInfo, error) {
92-
jobObj := obj.(*unstructured.Unstructured)
93+
jobObj, ok := obj.(*unstructured.Unstructured)
94+
if !ok {
95+
err := fmt.Errorf("interface {} is %v, not Unstructured", reflect.TypeOf(obj))
96+
return nil, err
97+
}
9398
gvk := jobObj.GroupVersionKind()
9499

95100
log.Infof("begin add %s job. jobName: %s, namespace: %s", gvk.String(), jobObj.GetName(), jobObj.GetNamespace())
@@ -180,7 +185,12 @@ func JobUpdateFunc(old, new interface{}, getStatusFunc api.GetStatusFunc) (*api.
180185
}
181186

182187
func JobDeleteFunc(obj interface{}, getStatusFunc api.GetStatusFunc) (*api.JobSyncInfo, error) {
183-
jobObj := obj.(*unstructured.Unstructured)
188+
jobObj, ok := obj.(*unstructured.Unstructured)
189+
if !ok {
190+
err := fmt.Errorf("interface {} is %v, not Unstructured", reflect.TypeOf(obj))
191+
log.Errorf("convert unstructured object failed. err: %v", err)
192+
return nil, err
193+
}
184194
// get job id and GroupVersionKind
185195
gvk := jobObj.GroupVersionKind()
186196
labels := jobObj.GetLabels()
@@ -325,7 +335,10 @@ func handlePendingPod(podStatus *v1.PodStatus, jobName, podName, namespace strin
325335
}
326336

327337
func TaskUpdateFunc(obj interface{}, action schema.ActionType, taskQueue workqueue.RateLimitingInterface) {
328-
podObj := obj.(*unstructured.Unstructured)
338+
podObj, ok := obj.(*unstructured.Unstructured)
339+
if !ok {
340+
return
341+
}
329342
uid := podObj.GetUID()
330343
name := podObj.GetName()
331344
namespace := podObj.GetNamespace()

0 commit comments

Comments
 (0)