Skip to content

Commit e48d94f

Browse files
committed
f
1 parent 82f2397 commit e48d94f

File tree

3 files changed

+19
-39
lines changed

3 files changed

+19
-39
lines changed

pkg/dryrun/kubeutils.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ func (k *KubeUtils) IsDaemonsetReady(ctx context.Context, cli client.Client, ns,
6464
return true, nil
6565
}
6666

67-
func (k *KubeUtils) IsJobComplete(ctx context.Context, cli client.Client, ns, name string, completions int32) (bool, error) {
68-
return true, nil
69-
}
70-
7167
func (k *KubeUtils) WaitForKubernetes(ctx context.Context, cli client.Client) <-chan error {
7268
errCh := make(chan error)
7369
close(errCh)

pkg/kubeutils/interface.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type KubeUtilsInterface interface {
3333
IsDeploymentReady(ctx context.Context, cli client.Client, ns, name string) (bool, error)
3434
IsStatefulSetReady(ctx context.Context, cli client.Client, ns, name string) (bool, error)
3535
IsDaemonsetReady(ctx context.Context, cli client.Client, ns, name string) (bool, error)
36-
IsJobComplete(ctx context.Context, cli client.Client, ns, name string, completions int32) (bool, error)
3736
WaitForKubernetes(ctx context.Context, cli client.Client) <-chan error
3837
WaitForCRDToBeReady(ctx context.Context, cli client.Client, name string) error
3938
KubeClient() (client.Client, error)
@@ -106,10 +105,6 @@ func IsDaemonsetReady(ctx context.Context, cli client.Client, ns, name string) (
106105
return kb.IsDaemonsetReady(ctx, cli, ns, name)
107106
}
108107

109-
func IsJobComplete(ctx context.Context, cli client.Client, ns, name string, completions int32) (bool, error) {
110-
return kb.IsJobComplete(ctx, cli, ns, name, completions)
111-
}
112-
113108
func WaitForKubernetes(ctx context.Context, cli client.Client) <-chan error {
114109
return kb.WaitForKubernetes(ctx, cli)
115110
}

pkg/kubeutils/kubeutils.go

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,32 @@ func (k *KubeUtils) WaitForJob(ctx context.Context, cli client.Client, ns, name
118118
var lasterr error
119119
if err := wait.ExponentialBackoffWithContext(
120120
ctx, backoff, func(ctx context.Context) (bool, error) {
121-
failed, err := k.IsJobFailed(ctx, cli, ns, name)
121+
var job batchv1.Job
122+
err := cli.Get(ctx, client.ObjectKey{Namespace: ns, Name: name}, &job)
122123
if k8serrors.IsNotFound(err) {
123124
// exit
124125
lasterr = fmt.Errorf("job not found")
125126
return false, lasterr
126127
} else if err != nil {
127-
lasterr = fmt.Errorf("unable to get job status: %w", err)
128+
lasterr = fmt.Errorf("unable to get job: %w", err)
128129
return false, nil
129-
} else if failed {
130+
}
131+
132+
failed := k.isJobFailed(job)
133+
if failed {
130134
// exit
131135
lasterr = fmt.Errorf("job failed")
132136
return false, lasterr
133137
}
134-
ready, err := k.IsJobComplete(ctx, cli, ns, name, completions)
135-
if err != nil {
136-
lasterr = fmt.Errorf("unable to get job status: %w", err)
137-
return false, nil
138-
} else if ready {
138+
139+
completed := k.isJobCompleted(job, completions)
140+
if completed {
139141
return true, nil
140142
}
143+
141144
// TODO: need to handle the case where the pod get stuck in pending
142145
// This can happen if nodes are not schedulable or if a volume is not found
146+
143147
return false, nil
144148
},
145149
); err != nil {
@@ -292,35 +296,20 @@ func (k *KubeUtils) IsDaemonsetReady(ctx context.Context, cli client.Client, ns,
292296
return false, nil
293297
}
294298

295-
// IsJobComplete returns true if the job has been completed successfully.
296-
func (k *KubeUtils) IsJobComplete(ctx context.Context, cli client.Client, ns, name string, completions int32) (bool, error) {
297-
var job batchv1.Job
298-
nsn := types.NamespacedName{Namespace: ns, Name: name}
299-
if err := cli.Get(ctx, nsn, &job); err != nil {
300-
return false, err
301-
}
302-
if job.Status.Succeeded >= completions {
303-
return true, nil
304-
}
305-
return false, nil
299+
// isJobCompleted returns true if the job has been completed successfully.
300+
func (k *KubeUtils) isJobCompleted(job batchv1.Job, completions int32) bool {
301+
isSucceeded := job.Status.Succeeded >= completions
302+
return isSucceeded
306303
}
307304

308-
// IsJobFailed if the job has exceeded the backoff limit.
309-
func (k *KubeUtils) IsJobFailed(ctx context.Context, cli client.Client, ns, name string) (bool, error) {
310-
var job batchv1.Job
311-
nsn := types.NamespacedName{Namespace: ns, Name: name}
312-
if err := cli.Get(ctx, nsn, &job); err != nil {
313-
return false, err
314-
}
305+
// isJobFailed if the job has exceeded the backoff limit.
306+
func (k *KubeUtils) isJobFailed(job batchv1.Job) bool {
315307
backoffLimit := int32(6) // default
316308
if job.Spec.BackoffLimit != nil {
317309
backoffLimit = *job.Spec.BackoffLimit
318310
}
319311
exceedsBackoffLimit := job.Status.Failed > backoffLimit
320-
if exceedsBackoffLimit {
321-
return true, nil
322-
}
323-
return false, nil
312+
return exceedsBackoffLimit
324313
}
325314

326315
// IsPodComplete returns true if the pod has completed.

0 commit comments

Comments
 (0)