Skip to content

Commit 96797a3

Browse files
authored
Wait for default FelixConfiguration before patching it in calico e2e setup (DataDog#23674)
The default FelixConfiguration is created asynchronously by calico-node after pods report Ready, so the immediate calicoctl patch sometimes ran before the resource existed. The patch failed silently (run_command defaults to check=False), Prometheus metrics were never enabled, and the downstream metrics endpoint check timed out 200s later with a generic connection-refused error. Wait for the resource to exist before patching, and use check=True on the patch so any future regression fails fast and visibly.
1 parent ab29361 commit 96797a3

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

calico/tests/conftest.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from datadog_checks.dev.conditions import CheckEndpoints
8+
from datadog_checks.dev.conditions import CheckEndpoints, WaitFor
99
from datadog_checks.dev.kind import kind_run
1010
from datadog_checks.dev.kube_port_forward import port_forward
1111
from datadog_checks.dev.subprocess import run_command
@@ -16,6 +16,11 @@
1616
HERE = path.dirname(path.abspath(__file__))
1717

1818

19+
def _felix_config_default_exists():
20+
result = run_command(["kubectl", "get", "felixconfiguration", "default"], capture='both')
21+
return result.code == 0
22+
23+
1924
def setup_calico():
2025
# Deploy calico
2126
run_command(["kubectl", "apply", "-f", path.join(HERE, 'kind', 'calico.yaml')])
@@ -32,10 +37,27 @@ def setup_calico():
3237
# Wait for pods
3338
run_command(["kubectl", "wait", "--for=condition=Ready", "pods", "--all", "--all-namespaces", "--timeout=300s"])
3439

35-
# Activate Felix
40+
# calico-node creates the default FelixConfiguration asynchronously after pods report Ready.
41+
WaitFor(_felix_config_default_exists, attempts=60, wait=2)()
42+
43+
# check=True so a missed patch fails loudly here instead of as a connection-refused timeout later.
3644
run_command(
37-
"""kubectl exec -i -n kube-system calicoctl -- /calicoctl patch felixConfiguration
38-
default --patch '{"spec":{"prometheusMetricsEnabled": true}}'"""
45+
[
46+
"kubectl",
47+
"exec",
48+
"-i",
49+
"-n",
50+
"kube-system",
51+
"calicoctl",
52+
"--",
53+
"/calicoctl",
54+
"patch",
55+
"felixConfiguration",
56+
"default",
57+
"--patch",
58+
'{"spec":{"prometheusMetricsEnabled": true}}',
59+
],
60+
check=True,
3961
)
4062

4163

0 commit comments

Comments
 (0)