Skip to content

Commit

Permalink
Merge branch 'main' into tobz/fix-global-vol-mounts-adp
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz authored Nov 20, 2024
2 parents 033eb80 + f8fc41d commit f5f630a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
46 changes: 45 additions & 1 deletion test/e2e/kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,37 @@ func (s *kindSuite) TestKindRun() {
verifyNumPodsForSelector(t, kubectlOptions, 1, clusterAgentSelector+",agent.datadoghq.com/e2e-test=datadog-agent-minimum")
})

s.T().Run("Autodiscovery works", func(t *testing.T) {
// Add nginx with annotations
var nginxConfigPath string
nginxConfigPath, err = getAbsPath(filepath.Join(manifestsPath, "autodiscovery-annotation.yaml"))
assert.NoError(t, err)
k8s.KubectlApply(t, kubectlOptions, nginxConfigPath)

verifyNumPodsForSelector(t, kubectlOptions, 1, "agent.datadoghq.com/e2e-test=datadog-agent-autodiscovery-annotated")

// check agent pods for http check
s.EventuallyWithTf(func(c *assert.CollectT) {
agentPods, err := k8s.ListPodsE(t, kubectlOptions, v1.ListOptions{
LabelSelector: nodeAgentSelector + ",agent.datadoghq.com/e2e-test=datadog-agent-minimum",
})
assert.NoError(c, err)

for _, pod := range agentPods {
k8s.WaitUntilPodAvailable(t, kubectlOptions, pod.Name, 9, 15*time.Second)

output, err := k8s.RunKubectlAndGetOutputE(t, kubectlOptions, "exec", "-it", pod.Name, "--", "agent", "status", "-j")
assert.NoError(c, err)

verifyCheck(c, output, "http_check")
}
}, 900*time.Second, 30*time.Second, "could not validate http check on agent pod")

s.EventuallyWithTf(func(c *assert.CollectT) {
verifyHTTPCheck(s, c)
}, 600*time.Second, 30*time.Second, "could not validate http.can_connect check with api client")
})

s.T().Run("Kubelet check works", func(t *testing.T) {
s.EventuallyWithTf(func(c *assert.CollectT) {
agentPods, err := k8s.ListPodsE(t, kubectlOptions, v1.ListOptions{
Expand All @@ -242,7 +273,7 @@ func (s *kindSuite) TestKindRun() {

verifyCheck(c, output, "kubelet")
}
}, 900*time.Second, 30*time.Second, fmt.Sprintf("could not validate kubelet check on agent pod"))
}, 900*time.Second, 30*time.Second, "could not validate kubelet check on agent pod")

metricQuery := fmt.Sprintf("exclude_null(avg:kubernetes.cpu.usage.total{kube_cluster_name:%s, container_id:*})", s.Env().Kind.ClusterName)
s.EventuallyWithTf(func(c *assert.CollectT) {
Expand Down Expand Up @@ -341,3 +372,16 @@ func verifyKSMCheck(s *kindSuite, c *assert.CollectT) {

assert.True(c, len(resp.Series) > 0, fmt.Sprintf("expected metric series to not be empty: %s", err))
}

func verifyHTTPCheck(s *kindSuite, c *assert.CollectT) {
metricQuery := fmt.Sprintf("exclude_null(avg:network.http.can_connect{kube_cluster_name:%s})", s.Env().Kind.ClusterName)

resp, _, err := s.datadogClient.metricsApi.QueryMetrics(s.datadogClient.ctx, time.Now().AddDate(0, 0, -1).Unix(), time.Now().Unix(), metricQuery)
assert.EqualValues(c, *resp.Status, "ok")
for _, series := range resp.Series {
for _, point := range series.Pointlist {
assert.Equal(c, int(*point[1]), 1)
}
}
assert.True(c, len(resp.Series) > 0, fmt.Sprintf("expected metric series to not be empty: %s", err))
}
33 changes: 33 additions & 0 deletions test/e2e/manifests/autodiscovery-annotation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
annotations:
ad.datadoghq.com/nginx.check_names: '["http_check"]'
ad.datadoghq.com/nginx.init_configs: '[{}]'
ad.datadoghq.com/nginx.instances: |
[
{
"name": "http_custom_identifier",
"url": "http://www.google.com"
}
]
ad.datadoghq.com/tolerate-unready: "true"
labels:
app: nginx
agent.datadoghq.com/e2e-test: datadog-agent-autodiscovery-annotated
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

0 comments on commit f5f630a

Please sign in to comment.