Skip to content

Commit ddde355

Browse files
Skip failing k8s capabilities test (#5293)
* Skip failing k8s capabilities test * Skipped the wrong test :/ * Skipping another sub-test * fix: make k8s integrations test run in sequence * fix: increase waiting for agent to report healthy to 120 seconds --------- Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
1 parent 44528c4 commit ddde355

File tree

2 files changed

+57
-51
lines changed

2 files changed

+57
-51
lines changed

pkg/testing/runner/runner.go

+45-49
Original file line numberDiff line numberDiff line change
@@ -306,63 +306,59 @@ func (r *Runner) Clean() error {
306306
}
307307

308308
func (r *Runner) runK8sInstances(ctx context.Context, instances []StateInstance) (map[string]OSRunnerResult, error) {
309-
g, ctx := errgroup.WithContext(ctx)
310309
results := make(map[string]OSRunnerResult)
311310
var resultsMx sync.Mutex
311+
var err error
312312
for _, instance := range instances {
313-
func(instance StateInstance) {
314-
g.Go(func() error {
315-
batch, ok := findBatchByID(instance.ID, r.batches)
316-
if !ok {
317-
return fmt.Errorf("unable to find batch with ID: %s", instance.ID)
318-
}
313+
batch, ok := findBatchByID(instance.ID, r.batches)
314+
if !ok {
315+
err = fmt.Errorf("unable to find batch with ID: %s", instance.ID)
316+
continue
317+
}
319318

320-
logger := &batchLogger{wrapped: r.logger, prefix: instance.ID}
321-
// start with the ExtraEnv first preventing the other environment flags below
322-
// from being overwritten
323-
env := map[string]string{}
324-
for k, v := range r.cfg.ExtraEnv {
325-
env[k] = v
326-
}
327-
// ensure that we have all the requirements for the stack if required
328-
if batch.Batch.Stack != nil {
329-
// wait for the stack to be ready before continuing
330-
logger.Logf("Waiting for stack to be ready...")
331-
stack, err := r.getStackForBatchID(batch.ID)
332-
if err != nil {
333-
return err
334-
}
335-
env["ELASTICSEARCH_HOST"] = stack.Elasticsearch
336-
env["ELASTICSEARCH_USERNAME"] = stack.Username
337-
env["ELASTICSEARCH_PASSWORD"] = stack.Password
338-
env["KIBANA_HOST"] = stack.Kibana
339-
env["KIBANA_USERNAME"] = stack.Username
340-
env["KIBANA_PASSWORD"] = stack.Password
341-
logger.Logf("Using Stack with Kibana host %s, credentials available under .integration-cache", stack.Kibana)
342-
}
319+
logger := &batchLogger{wrapped: r.logger, prefix: instance.ID}
320+
// start with the ExtraEnv first preventing the other environment flags below
321+
// from being overwritten
322+
env := map[string]string{}
323+
for k, v := range r.cfg.ExtraEnv {
324+
env[k] = v
325+
}
326+
// ensure that we have all the requirements for the stack if required
327+
if batch.Batch.Stack != nil {
328+
// wait for the stack to be ready before continuing
329+
logger.Logf("Waiting for stack to be ready...")
330+
stack, stackErr := r.getStackForBatchID(batch.ID)
331+
if stackErr != nil {
332+
err = stackErr
333+
continue
334+
}
335+
env["ELASTICSEARCH_HOST"] = stack.Elasticsearch
336+
env["ELASTICSEARCH_USERNAME"] = stack.Username
337+
env["ELASTICSEARCH_PASSWORD"] = stack.Password
338+
env["KIBANA_HOST"] = stack.Kibana
339+
env["KIBANA_USERNAME"] = stack.Username
340+
env["KIBANA_PASSWORD"] = stack.Password
341+
logger.Logf("Using Stack with Kibana host %s, credentials available under .integration-cache", stack.Kibana)
342+
}
343343

344-
// set the go test flags
345-
env["GOTEST_FLAGS"] = r.cfg.TestFlags
346-
env["KUBECONFIG"] = instance.Instance.Internal["config"].(string)
347-
env["TEST_BINARY_NAME"] = r.cfg.BinaryName
348-
env["AGENT_IMAGE"] = instance.Instance.Internal["agent_image"].(string)
344+
// set the go test flags
345+
env["GOTEST_FLAGS"] = r.cfg.TestFlags
346+
env["KUBECONFIG"] = instance.Instance.Internal["config"].(string)
347+
env["TEST_BINARY_NAME"] = r.cfg.BinaryName
348+
env["AGENT_IMAGE"] = instance.Instance.Internal["agent_image"].(string)
349349

350-
prefix := fmt.Sprintf("%s-%s", instance.Instance.Internal["version"].(string), batch.ID)
350+
prefix := fmt.Sprintf("%s-%s", instance.Instance.Internal["version"].(string), batch.ID)
351351

352-
// run the actual tests on the host
353-
result, err := batch.OS.Runner.Run(ctx, r.cfg.VerboseMode, nil, logger, r.cfg.AgentVersion, prefix, batch.Batch, env)
354-
if err != nil {
355-
logger.Logf("Failed to execute tests on instance: %s", err)
356-
return fmt.Errorf("failed to execute tests on instance %s: %w", instance.Name, err)
357-
}
358-
resultsMx.Lock()
359-
results[batch.ID] = result
360-
resultsMx.Unlock()
361-
return nil
362-
})
363-
}(instance)
352+
// run the actual tests on the host
353+
result, runErr := batch.OS.Runner.Run(ctx, r.cfg.VerboseMode, nil, logger, r.cfg.AgentVersion, prefix, batch.Batch, env)
354+
if runErr != nil {
355+
logger.Logf("Failed to execute tests on instance: %s", err)
356+
err = fmt.Errorf("failed to execute tests on instance %s: %w", instance.Name, err)
357+
}
358+
resultsMx.Lock()
359+
results[batch.ID] = result
360+
resultsMx.Unlock()
364361
}
365-
err := g.Wait()
366362
if err != nil {
367363
return nil, err
368364
}

testing/integration/kubernetes_agent_standalone_test.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func TestKubernetesAgentStandalone(t *testing.T) {
8888
capabilitiesDrop []corev1.Capability
8989
capabilitiesAdd []corev1.Capability
9090
runK8SInnerTests bool
91+
skipReason string
9192
}{
9293
{
9394
"default deployment - rootful agent",
@@ -96,6 +97,7 @@ func TestKubernetesAgentStandalone(t *testing.T) {
9697
nil,
9798
nil,
9899
false,
100+
"",
99101
},
100102
{
101103
"drop ALL capabilities - rootful agent",
@@ -104,6 +106,7 @@ func TestKubernetesAgentStandalone(t *testing.T) {
104106
[]corev1.Capability{"ALL"},
105107
[]corev1.Capability{},
106108
false,
109+
"",
107110
},
108111
{
109112
"drop ALL add CHOWN, SETPCAP capabilities - rootful agent",
@@ -112,6 +115,7 @@ func TestKubernetesAgentStandalone(t *testing.T) {
112115
[]corev1.Capability{"ALL"},
113116
[]corev1.Capability{"CHOWN", "SETPCAP"},
114117
true,
118+
"",
115119
},
116120
{
117121
"drop ALL add CHOWN, SETPCAP capabilities - rootless agent",
@@ -120,6 +124,7 @@ func TestKubernetesAgentStandalone(t *testing.T) {
120124
[]corev1.Capability{"ALL"},
121125
[]corev1.Capability{"CHOWN", "SETPCAP"},
122126
true,
127+
"https://github.com/elastic/elastic-agent/issues/5275",
123128
},
124129
{
125130
"drop ALL add CHOWN, SETPCAP capabilities - rootless agent random uid:gid",
@@ -128,12 +133,17 @@ func TestKubernetesAgentStandalone(t *testing.T) {
128133
[]corev1.Capability{"ALL"},
129134
[]corev1.Capability{"CHOWN", "SETPCAP", "DAC_READ_SEARCH"},
130135
true,
136+
"https://github.com/elastic/elastic-agent/issues/5275",
131137
},
132138
}
133139

134140
for _, tc := range testCases {
135141
tc := tc
136142
t.Run(tc.name, func(t *testing.T) {
143+
if tc.skipReason != "" {
144+
t.Skip(tc.skipReason)
145+
}
146+
137147
hasher := sha256.New()
138148
hasher.Write([]byte(tc.name))
139149
testNamespace := strings.ToLower(base64.URLEncoding.EncodeToString(hasher.Sum(nil)))
@@ -262,8 +272,8 @@ func deployK8SAgent(t *testing.T, ctx context.Context, client klient.Client, obj
262272
command := []string{"elastic-agent", "status"}
263273
var stdout, stderr bytes.Buffer
264274
var agentHealthyErr error
265-
// we will wait maximum 60 seconds for the agent to report healthy
266-
for i := 0; i < 60; i++ {
275+
// we will wait maximum 120 seconds for the agent to report healthy
276+
for i := 0; i < 120; i++ {
267277
stdout.Reset()
268278
stderr.Reset()
269279
agentHealthyErr = client.Resources().ExecInPod(ctx, namespace, agentPodName, "elastic-agent-standalone", command, &stdout, &stderr)

0 commit comments

Comments
 (0)