Skip to content

Commit

Permalink
eks*: spinner in job waits
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed Jul 11, 2020
1 parent 1531dc1 commit 5ab80c4
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions eks/cluster-loader/remote/cluster-loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (ts *tester) Create() (err error) {
_, pods, err = k8s_client.WaitForJobCompletes(
ctx,
ts.cfg.Logger,
ts.cfg.LogWriter,
ts.cfg.Stopc,
ts.cfg.K8SClient,
2*time.Minute,
Expand Down
1 change: 1 addition & 0 deletions eks/configmaps/remote/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (ts *tester) Create() (err error) {
_, pods, err = k8s_client.WaitForJobCompletes(
ctx,
ts.cfg.Logger,
ts.cfg.LogWriter,
ts.cfg.Stopc,
ts.cfg.K8SClient,
3*time.Minute,
Expand Down
1 change: 1 addition & 0 deletions eks/cron-jobs/cron-jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (ts *tester) Create() (err error) {
_, pods, err = k8s_client.WaitForCronJobCompletes(
ctx,
ts.cfg.Logger,
ts.cfg.LogWriter,
ts.cfg.Stopc,
ts.cfg.K8SClient,
3*time.Minute,
Expand Down
1 change: 1 addition & 0 deletions eks/csrs/remote/csrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (ts *tester) Create() (err error) {
_, pods, err = k8s_client.WaitForJobCompletes(
ctx,
ts.cfg.Logger,
ts.cfg.LogWriter,
ts.cfg.Stopc,
ts.cfg.K8SClient,
3*time.Minute,
Expand Down
1 change: 1 addition & 0 deletions eks/jobs-echo/jobs-echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (ts *tester) Create() (err error) {
_, pods, err = k8s_client.WaitForJobCompletes(
ctx,
ts.cfg.Logger,
ts.cfg.LogWriter,
ts.cfg.Stopc,
ts.cfg.K8SClient,
2*time.Minute,
Expand Down
1 change: 1 addition & 0 deletions eks/jobs-pi/jobs-pi.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (ts *tester) Create() (err error) {
_, pods, err = k8s_client.WaitForJobCompletes(
ctx,
ts.cfg.Logger,
ts.cfg.LogWriter,
ts.cfg.Stopc,
ts.cfg.K8SClient,
2*time.Minute,
Expand Down
1 change: 1 addition & 0 deletions eks/secrets/remote/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (ts *tester) Create() (err error) {
_, pods, err = k8s_client.WaitForJobCompletes(
ctx,
ts.cfg.Logger,
ts.cfg.LogWriter,
ts.cfg.Stopc,
ts.cfg.K8SClient,
3*time.Minute,
Expand Down
1 change: 1 addition & 0 deletions eks/stresser/remote/stresser.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (ts *tester) Create() (err error) {
_, pods, err = k8s_client.WaitForJobCompletes(
ctx,
ts.cfg.Logger,
ts.cfg.LogWriter,
ts.cfg.Stopc,
ts.cfg.K8SClient,
time.Minute+ts.cfg.EKSConfig.AddOnStresserRemote.Duration/2,
Expand Down
13 changes: 11 additions & 2 deletions pkg/k8s-client/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import (
"context"
"errors"
"fmt"
"io"
"net"
"strings"
"time"

"github.com/aws/aws-k8s-tester/pkg/ctxutil"
"github.com/aws/aws-k8s-tester/pkg/spinner"
"go.uber.org/zap"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
Expand Down Expand Up @@ -510,6 +512,7 @@ func CreateObject(dynamicClient dynamic.Interface, namespace string, name string
func WaitForJobCompletes(
ctx context.Context,
lg *zap.Logger,
logWriter io.Writer,
stopc chan struct{},
k8sClient EKS,
initialWait time.Duration,
Expand All @@ -518,7 +521,7 @@ func WaitForJobCompletes(
jobName string,
target int,
opts ...OpOption) (job *batchv1.Job, pods []apiv1.Pod, err error) {
job, _, pods, err = waitForJobCompletes(false, ctx, lg, stopc, k8sClient, initialWait, pollInterval, namespace, jobName, target, opts...)
job, _, pods, err = waitForJobCompletes(false, ctx, lg, logWriter, stopc, k8sClient, initialWait, pollInterval, namespace, jobName, target, opts...)
return job, pods, err
}

Expand All @@ -527,6 +530,7 @@ func WaitForJobCompletes(
func WaitForCronJobCompletes(
ctx context.Context,
lg *zap.Logger,
logWriter io.Writer,
stopc chan struct{},
k8sClient EKS,
initialWait time.Duration,
Expand All @@ -535,7 +539,7 @@ func WaitForCronJobCompletes(
jobName string,
target int,
opts ...OpOption) (cronJob *batchv1beta1.CronJob, pods []apiv1.Pod, err error) {
_, cronJob, pods, err = waitForJobCompletes(true, ctx, lg, stopc, k8sClient, initialWait, pollInterval, namespace, jobName, target, opts...)
_, cronJob, pods, err = waitForJobCompletes(true, ctx, lg, logWriter, stopc, k8sClient, initialWait, pollInterval, namespace, jobName, target, opts...)
return cronJob, pods, err
}

Expand All @@ -559,6 +563,7 @@ func waitForJobCompletes(
isCronJob bool,
ctx context.Context,
lg *zap.Logger,
logWriter io.Writer,
stopc chan struct{},
k8sClient EKS,
initialWait time.Duration,
Expand All @@ -575,6 +580,7 @@ func waitForJobCompletes(
pollInterval = DefaultNamespaceDeletionInterval
}

sp := spinner.New(logWriter, "Waiting for Job completes "+jobName)
lg.Info("waiting Job completes",
zap.String("namespace", namespace),
zap.String("job-name", jobName),
Expand All @@ -585,10 +591,13 @@ func waitForJobCompletes(
zap.String("ctx-time-left", ctxutil.TimeLeftTillDeadline(ctx)),
zap.Int("target", target),
)
sp.Restart()
select {
case <-stopc:
sp.Stop()
return nil, nil, nil, errors.New("initial wait aborted")
case <-time.After(initialWait):
sp.Stop()
}

retryWaitFunc := func() (done bool, err error) {
Expand Down

0 comments on commit 5ab80c4

Please sign in to comment.