@@ -12,6 +12,7 @@ import (
1212 "bytes"
1313 "context"
1414 "encoding/json"
15+ "errors"
1516 "fmt"
1617 "io"
1718 "os"
@@ -1275,10 +1276,45 @@ func k8sStepLogstashCheckStatus(logstashPodLabelSelector string, logstashExpecte
12751276 opt .LabelSelector = logstashPodLabelSelector
12761277 })
12771278 require .NoError (t , err , "failed to list logstash pods with selector " , logstashPodLabelSelector )
1278- require .NotEmpty (t , logstashPodList .Items , "no agent pods found with selector " , logstashPodLabelSelector )
1279+ require .NotEmpty (t , logstashPodList .Items , "no logstash pods found with selector " , logstashPodLabelSelector )
12791280 for _ , pod := range logstashPodList .Items {
12801281 if (pod .Status .Phase != corev1 .PodRunning ) && logstashExpected {
12811282 t .Errorf ("logstash pod %s is not running" , pod .Name )
1283+ ctx , cancel := context .WithTimeout (ctx , 2 * time .Minute )
1284+ defer cancel ()
1285+ checkStatus := func () error {
1286+ var err error
1287+ var stdout , stderr bytes.Buffer
1288+ stdout .Reset ()
1289+ stderr .Reset ()
1290+ var result map [string ]interface {}
1291+ if err := kCtx .client .Resource ().ExecInPod (ctx , namespace , pod .Name , "logstash" ,
1292+ []string {"curl" , "localhost:9600/_pretty" }, stdout , stderr ); err != nil {
1293+ return err
1294+ }
1295+ if err := json .Unmarshal (stdout .Bytes (), & result ); err != nil {
1296+ return err
1297+ }
1298+ if status , found := result ["status" ]; found {
1299+ if status != "green" {
1300+ return fmt .Errorf ("logstash internal status is not green: %s" , status )
1301+ }
1302+ } else {
1303+ return fmt .Errorf ("status not found in logstash API response" )
1304+ }
1305+ return err
1306+ }
1307+ for {
1308+ err := checkStatus ()
1309+ if err == nil {
1310+ return nil
1311+ }
1312+ if ctx .Err () != nil {
1313+ // timeout waiting for agent to become healthy
1314+ return errors .Join (err , errors .New ("timeout waiting for agent to become healthy" ))
1315+ }
1316+ time .Sleep (100 * time .Millisecond )
1317+ }
12821318 }
12831319 if (pod .Status .Phase == corev1 .PodRunning ) && ! logstashExpected {
12841320 t .Errorf ("logstash pod %s is running but it should not" , pod .Name )
0 commit comments