@@ -8,8 +8,10 @@ import (
8
8
corev1 "k8s.io/api/core/v1"
9
9
"k8s.io/apimachinery/pkg/api/resource"
10
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
- "k8s.io/apimachinery/pkg/watch"
11
+ apiWatch "k8s.io/apimachinery/pkg/watch"
12
12
"k8s.io/client-go/kubernetes"
13
+ "k8s.io/client-go/tools/cache"
14
+ "k8s.io/client-go/tools/watch"
13
15
)
14
16
15
17
// JobController type responsible for
@@ -107,24 +109,29 @@ func (j *JobController) CreateGathererJob(ctx context.Context, dataGatherName, i
107
109
}
108
110
109
111
// WaitForJobCompletion listen the Kubernetes events to check if job finished.
110
- func (j * JobController ) WaitForJobCompletion (ctx context.Context , jobName string ) error {
111
- watcher , err := j .kubeClient .BatchV1 ().Jobs (insightsNamespace ).
112
- Watch (ctx , metav1.ListOptions {FieldSelector : fmt .Sprintf ("metadata.name=%s" , jobName )})
112
+ func (j * JobController ) WaitForJobCompletion (ctx context.Context , job * batchv1.Job ) error {
113
+ watcherFnc := func (options metav1.ListOptions ) (apiWatch.Interface , error ) {
114
+ return j .kubeClient .BatchV1 ().Jobs (insightsNamespace ).
115
+ Watch (ctx , metav1.ListOptions {FieldSelector : fmt .Sprintf ("metadata.name=%s" , job .Name )})
116
+ }
117
+
118
+ retryWatcher , err := watch .NewRetryWatcher (job .ResourceVersion , & cache.ListWatch {WatchFunc : watcherFnc })
113
119
if err != nil {
114
120
return err
115
121
}
116
- defer watcher .Stop ()
122
+
123
+ defer retryWatcher .Stop ()
117
124
118
125
for {
119
126
select {
120
127
case <- ctx .Done ():
121
128
return ctx .Err ()
122
- case event , ok := <- watcher .ResultChan ():
129
+ case event , ok := <- retryWatcher .ResultChan ():
123
130
if ! ok {
124
131
return fmt .Errorf ("watcher channel was closed unexpectedly" )
125
132
}
126
133
127
- if event .Type != watch .Modified {
134
+ if event .Type != apiWatch .Modified {
128
135
continue
129
136
}
130
137
0 commit comments