diff --git a/k8s-tester/fluent-bit/tester.go b/k8s-tester/fluent-bit/tester.go index 8f5424c56..396bf91a6 100644 --- a/k8s-tester/fluent-bit/tester.go +++ b/k8s-tester/fluent-bit/tester.go @@ -59,6 +59,7 @@ func (ts *tester) Apply() error { if ok := ts.runPrompt("apply"); !ok { return errors.New("cancelled") } + if err := client.CreateNamespace(ts.cfg.Logger, ts.cli, ts.cfg.Namespace); err != nil { return err } @@ -89,6 +90,7 @@ func (ts *tester) Apply() error { if err := ts.testLogsWithinNamespace(); err != nil { return err } + return nil } @@ -194,6 +196,7 @@ func (ts *tester) Delete() error { if len(errs) > 0 { return errors.New(strings.Join(errs, ", ")) } + return nil } diff --git a/k8s-tester/jobs-echo/tester.go b/k8s-tester/jobs-echo/tester.go index bcf730fb9..1a1b9683f 100644 --- a/k8s-tester/jobs-echo/tester.go +++ b/k8s-tester/jobs-echo/tester.go @@ -106,26 +106,9 @@ func (ts *tester) Apply() (err error) { return errors.New("cancelled") } - // check ECR permission - // ref. https://github.com/aws/aws-k8s-tester/blob/v1.5.9/eks/jobs-echo/jobs-echo.go#L75-L90 - bsyImg := jobBusyboxImageName - if ts.cfg.RepositoryBusyboxAccountID != "" && - ts.cfg.RepositoryBusyboxRegion != "" && - ts.cfg.RepositoryBusyboxName != "" && - ts.cfg.RepositoryBusyboxImageTag != "" && - ts.cfg.ECRAPI != nil { - bsyImg, _, err = aws_v1_ecr.Check( - ts.cfg.Logger, - ts.cfg.ECRAPI, - ts.cfg.RepositoryBusyboxPartition, - ts.cfg.RepositoryBusyboxAccountID, - ts.cfg.RepositoryBusyboxRegion, - ts.cfg.RepositoryBusyboxName, - ts.cfg.RepositoryBusyboxImageTag, - ) - if err != nil { - return err - } + bsyImg, err := ts.checkECRImage() + if err != nil { + return err } if err := client.CreateNamespace(ts.cfg.Logger, ts.cli, ts.cfg.Namespace); err != nil { @@ -136,33 +119,9 @@ func (ts *tester) Apply() (err error) { return err } - timeout := 5*time.Minute + 5*time.Minute*time.Duration(ts.cfg.Completes) - if timeout > 3*time.Hour { - timeout = 3 * time.Hour - } - ctx, cancel := context.WithTimeout(context.Background(), timeout) - var pods []core_v1.Pod - _, pods, err = client.WaitForJobCompletes( - ctx, - ts.cfg.Logger, - ts.cfg.LogWriter, - ts.cfg.Stopc, - ts.cli, - time.Minute, - 5*time.Second, - ts.cfg.Namespace, - jobName, - int(ts.cfg.Completes), - ) - cancel() - if err != nil { + if err := ts.checkJob(); err != nil { return err } - fmt.Fprintf(ts.cfg.LogWriter, "\n") - for _, item := range pods { - fmt.Fprintf(ts.cfg.LogWriter, "Job Pod %q: %q\n", item.Name, item.Status.Phase) - } - fmt.Fprintf(ts.cfg.LogWriter, "\n") return nil } @@ -241,6 +200,31 @@ const ( jobBusyboxImageName = "busybox" ) +func (ts *tester) checkECRImage() (busyboxImg string, err error) { + // check ECR permission + // ref. https://github.com/aws/aws-k8s-tester/blob/v1.5.9/eks/jobs-echo/jobs-echo.go#L75-L90 + busyboxImg = jobBusyboxImageName + if ts.cfg.RepositoryBusyboxAccountID != "" && + ts.cfg.RepositoryBusyboxRegion != "" && + ts.cfg.RepositoryBusyboxName != "" && + ts.cfg.RepositoryBusyboxImageTag != "" && + ts.cfg.ECRAPI != nil { + busyboxImg, _, err = aws_v1_ecr.Check( + ts.cfg.Logger, + ts.cfg.ECRAPI, + ts.cfg.RepositoryBusyboxPartition, + ts.cfg.RepositoryBusyboxAccountID, + ts.cfg.RepositoryBusyboxRegion, + ts.cfg.RepositoryBusyboxName, + ts.cfg.RepositoryBusyboxImageTag, + ) + if err != nil { + return "", err + } + } + return busyboxImg, nil +} + func (ts *tester) createObject(busyboxImg string) (batch_v1.Job, string, error) { podSpec := core_v1.PodTemplateSpec{ Spec: core_v1.PodSpec{ @@ -313,3 +297,35 @@ func (ts *tester) createJob(busyboxImg string) (err error) { ts.cfg.Logger.Info("created a Job object") return nil } + +func (ts *tester) checkJob() error { + timeout := 5*time.Minute + 5*time.Minute*time.Duration(ts.cfg.Completes) + if timeout > 3*time.Hour { + timeout = 3 * time.Hour + } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + var pods []core_v1.Pod + _, pods, err := client.WaitForJobCompletes( + ctx, + ts.cfg.Logger, + ts.cfg.LogWriter, + ts.cfg.Stopc, + ts.cli, + time.Minute, + 5*time.Second, + ts.cfg.Namespace, + jobName, + int(ts.cfg.Completes), + ) + cancel() + if err != nil { + return err + } + + fmt.Fprintf(ts.cfg.LogWriter, "\n") + for _, item := range pods { + fmt.Fprintf(ts.cfg.LogWriter, "Job Pod %q: %q\n", item.Name, item.Status.Phase) + } + fmt.Fprintf(ts.cfg.LogWriter, "\n") + return nil +} diff --git a/k8s-tester/jobs-pi/tester.go b/k8s-tester/jobs-pi/tester.go index 5207e64a9..6252f2f0a 100644 --- a/k8s-tester/jobs-pi/tester.go +++ b/k8s-tester/jobs-pi/tester.go @@ -86,33 +86,9 @@ func (ts *tester) Apply() error { return err } - timeout := 5*time.Minute + 5*time.Minute*time.Duration(ts.cfg.Completes) - if timeout > 3*time.Hour { - timeout = 3 * time.Hour - } - ctx, cancel := context.WithTimeout(context.Background(), timeout) - var pods []core_v1.Pod - _, pods, err := client.WaitForJobCompletes( - ctx, - ts.cfg.Logger, - ts.cfg.LogWriter, - ts.cfg.Stopc, - ts.cli, - time.Minute, - 5*time.Second, - ts.cfg.Namespace, - jobName, - int(ts.cfg.Completes), - ) - cancel() - if err != nil { + if err := ts.checkJob(); err != nil { return err } - fmt.Fprintf(ts.cfg.LogWriter, "\n") - for _, item := range pods { - fmt.Fprintf(ts.cfg.LogWriter, "Job Pod %q: %q\n", item.Name, item.Status.Phase) - } - fmt.Fprintf(ts.cfg.LogWriter, "\n") return nil } @@ -257,3 +233,35 @@ func (ts *tester) createJob() (err error) { ts.cfg.Logger.Info("created a Job object") return nil } + +func (ts *tester) checkJob() error { + timeout := 5*time.Minute + 5*time.Minute*time.Duration(ts.cfg.Completes) + if timeout > 3*time.Hour { + timeout = 3 * time.Hour + } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + var pods []core_v1.Pod + _, pods, err := client.WaitForJobCompletes( + ctx, + ts.cfg.Logger, + ts.cfg.LogWriter, + ts.cfg.Stopc, + ts.cli, + time.Minute, + 5*time.Second, + ts.cfg.Namespace, + jobName, + int(ts.cfg.Completes), + ) + cancel() + if err != nil { + return err + } + + fmt.Fprintf(ts.cfg.LogWriter, "\n") + for _, item := range pods { + fmt.Fprintf(ts.cfg.LogWriter, "Job Pod %q: %q\n", item.Name, item.Status.Phase) + } + fmt.Fprintf(ts.cfg.LogWriter, "\n") + return nil +} diff --git a/k8s-tester/nlb-hello-world/tester.go b/k8s-tester/nlb-hello-world/tester.go index 36a13edc5..0c5e29b1e 100644 --- a/k8s-tester/nlb-hello-world/tester.go +++ b/k8s-tester/nlb-hello-world/tester.go @@ -90,6 +90,7 @@ func (ts *tester) Apply() error { if err := ts.createDeployment(); err != nil { return err } + if err := ts.checkDeployment(); err != nil { return err } @@ -97,6 +98,7 @@ func (ts *tester) Apply() error { if err := ts.createService(); err != nil { return err } + waitDur := 3 * time.Minute ts.cfg.Logger.Info("waiting for NLB hello-world Service", zap.Duration("wait", waitDur)) select { @@ -104,6 +106,7 @@ func (ts *tester) Apply() error { return errors.New("NLB hello-world Service apply aborted") case <-time.After(waitDur): } + if err := ts.checkService(); err != nil { return err }