Skip to content

Commit 0cac5d7

Browse files
committed
Update pod label and add check status for logstash
1 parent 8990492 commit 0cac5d7

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

testing/integration/k8s/kubernetes_agent_standalone_test.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)

testing/integration/k8s/testdata/logstash.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spec:
1515
metadata:
1616
labels:
1717
app: logstash-agent
18+
app.kubernetes.io/name: logstash-agent # don't change this as integration tests depend on it
1819
spec:
1920
securityContext:
2021
runAsUser: 1000

0 commit comments

Comments
 (0)