From 53b4729c634eabc2e8eb662e6edecdaa75f3b6fb Mon Sep 17 00:00:00 2001 From: Victor Martinelli Date: Thu, 6 Jan 2022 10:47:25 -0300 Subject: [PATCH 1/4] fix: improve test startup logic --- controllers/k6_start.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/controllers/k6_start.go b/controllers/k6_start.go index 4024cb26..05af4303 100644 --- a/controllers/k6_start.go +++ b/controllers/k6_start.go @@ -3,6 +3,8 @@ package controllers import ( "context" "fmt" + "net/http" + "strconv" "time" "github.com/go-logr/logr" @@ -15,6 +17,22 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) +func isPodReady(pod *v1.Pod) bool { + resp, err := http.Get(fmt.Sprintf("%v/v1/status", pod.Status.HostIP)) + + if err != nil { + return false + } + + status, err := strconv.Atoi(resp.Status) + + if err != nil { + return false + } + + return status < 400 +} + // StartJobs in the Ready phase using a curl container func StartJobs(ctx context.Context, log logr.Logger, k6 *v1alpha1.K6, r *K6Reconciler) (ctrl.Result, error) { log.Info("Waiting for pods to get ready") @@ -35,7 +53,7 @@ func StartJobs(ctx context.Context, log logr.Logger, k6 *v1alpha1.K6, r *K6Recon var count int for _, pod := range pl.Items { - if pod.Status.Phase != "Running" { + if pod.Status.Phase != "Running" && !isPodReady(&pod) { continue } count++ From 6ddc29601db22470884fb972c2e0d179e5a028ee Mon Sep 17 00:00:00 2001 From: Victor Martinelli Date: Fri, 7 Jan 2022 09:11:41 -0300 Subject: [PATCH 2/4] fix: change usage to statusCode --- controllers/k6_start.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/controllers/k6_start.go b/controllers/k6_start.go index 05af4303..1f75d1a4 100644 --- a/controllers/k6_start.go +++ b/controllers/k6_start.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strconv" "time" "github.com/go-logr/logr" @@ -24,13 +23,7 @@ func isPodReady(pod *v1.Pod) bool { return false } - status, err := strconv.Atoi(resp.Status) - - if err != nil { - return false - } - - return status < 400 + return resp.StatusCode < 400 } // StartJobs in the Ready phase using a curl container From 99b2be6b497fae77976350f230c0086df6f1126e Mon Sep 17 00:00:00 2001 From: Victor Martinelli Date: Tue, 11 Jan 2022 05:39:06 -0300 Subject: [PATCH 3/4] fix: avoid requesting when hostip is empty Co-authored-by: yorugac --- controllers/k6_start.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/k6_start.go b/controllers/k6_start.go index 1f75d1a4..d64bbe57 100644 --- a/controllers/k6_start.go +++ b/controllers/k6_start.go @@ -17,6 +17,9 @@ import ( ) func isPodReady(pod *v1.Pod) bool { + if len(pod.Status.HostIP) < 1 { + return false + } resp, err := http.Get(fmt.Sprintf("%v/v1/status", pod.Status.HostIP)) if err != nil { From 442e1cf198b148b9ddeae0655ae92d748c580c0e Mon Sep 17 00:00:00 2001 From: Victor Martinelli Date: Mon, 17 Jan 2022 09:33:21 -0300 Subject: [PATCH 4/4] feat: change to service instead of pods --- controllers/k6_start.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/controllers/k6_start.go b/controllers/k6_start.go index d64bbe57..358c7ee3 100644 --- a/controllers/k6_start.go +++ b/controllers/k6_start.go @@ -16,13 +16,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func isPodReady(pod *v1.Pod) bool { - if len(pod.Status.HostIP) < 1 { - return false - } - resp, err := http.Get(fmt.Sprintf("%v/v1/status", pod.Status.HostIP)) +func isServiceReady(log logr.Logger, service *v1.Service) bool { + resp, err := http.Get(fmt.Sprintf("http://%v.%v.svc.cluster.local:6565/v1/status", service.ObjectMeta.Name, service.ObjectMeta.Namespace)) if err != nil { + log.Error(err, fmt.Sprintf("failed to get status from %v", service.ObjectMeta.Name)) return false } @@ -49,7 +47,7 @@ func StartJobs(ctx context.Context, log logr.Logger, k6 *v1alpha1.K6, r *K6Recon var count int for _, pod := range pl.Items { - if pod.Status.Phase != "Running" && !isPodReady(&pod) { + if pod.Status.Phase != "Running" { continue } count++ @@ -72,6 +70,11 @@ func StartJobs(ctx context.Context, log logr.Logger, k6 *v1alpha1.K6, r *K6Recon for _, service := range sl.Items { hostnames = append(hostnames, service.ObjectMeta.Name) + + if !isServiceReady(log, &service) { + log.Info(fmt.Sprintf("%v service is not ready, aborting", service.ObjectMeta.Name)) + return false, nil + } } starter := jobs.NewStarterJob(k6, hostnames)