Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve test startup logic #89

Merged
merged 4 commits into from
Jan 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion controllers/k6_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package controllers
import (
"context"
"fmt"
"net/http"
"strconv"
"time"

"github.com/go-logr/logr"
Expand All @@ -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))
victorlcm marked this conversation as resolved.
Show resolved Hide resolved

if err != nil {
return false
}

status, err := strconv.Atoi(resp.Status)
victorlcm marked this conversation as resolved.
Show resolved Hide resolved

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")
Expand All @@ -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++
Expand Down