|
| 1 | +package datadog |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + appsv1 "k8s.io/api/apps/v1" |
| 8 | + |
| 9 | + "github.com/DataDog/helm-charts/test/common" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + DDAgentIpcPort = "DD_AGENT_IPC_PORT" |
| 14 | + DDAgentIpcConfigRefreshInterval = "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL" |
| 15 | +) |
| 16 | + |
| 17 | +type ExpectedIpcEnv struct { |
| 18 | + ipcPort string |
| 19 | + ipcConfigRefreshInterval string |
| 20 | +} |
| 21 | + |
| 22 | +func Test_otelAgentConfigs(t *testing.T) { |
| 23 | + tests := []struct { |
| 24 | + name string |
| 25 | + command common.HelmCommand |
| 26 | + assertions func(t *testing.T, manifest string, expectedIpcEnv ExpectedIpcEnv) |
| 27 | + expectedIpcEnv ExpectedIpcEnv |
| 28 | + }{ |
| 29 | + { |
| 30 | + name: "no ipc provided", |
| 31 | + command: common.HelmCommand{ |
| 32 | + ReleaseName: "datadog", |
| 33 | + ChartPath: "../../charts/datadog", |
| 34 | + ShowOnly: []string{"templates/daemonset.yaml"}, |
| 35 | + Values: []string{"../../charts/datadog/values.yaml"}, |
| 36 | + Overrides: map[string]string{ |
| 37 | + "datadog.apiKeyExistingSecret": "datadog-secret", |
| 38 | + "datadog.appKeyExistingSecret": "datadog-secret", |
| 39 | + "datadog.otelCollector.enabled": "true", |
| 40 | + }, |
| 41 | + }, |
| 42 | + expectedIpcEnv: ExpectedIpcEnv{ |
| 43 | + ipcPort: "5009", |
| 44 | + ipcConfigRefreshInterval: "60", |
| 45 | + }, |
| 46 | + assertions: verifyOtelAgentEnvVars, |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + for _, tt := range tests { |
| 51 | + t.Run(tt.name, func(t *testing.T) { |
| 52 | + manifest, err := common.RenderChart(t, tt.command) |
| 53 | + assert.Nil(t, err, "couldn't render template") |
| 54 | + tt.assertions(t, manifest, tt.expectedIpcEnv) |
| 55 | + }) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func verifyOtelAgentEnvVars(t *testing.T, manifest string, expectedIpcEnv ExpectedIpcEnv) { |
| 60 | + var deployment appsv1.DaemonSet |
| 61 | + common.Unmarshal(t, manifest, &deployment) |
| 62 | + // otel agent |
| 63 | + otelAgentContainer, ok := getContainer(t, deployment.Spec.Template.Spec.Containers, "otel-agent") |
| 64 | + assert.True(t, ok) |
| 65 | + coreEnvs := getEnvVarMap(otelAgentContainer.Env) |
| 66 | + assert.Equal(t, expectedIpcEnv.ipcPort, coreEnvs[DDAgentIpcPort]) |
| 67 | + assert.Equal(t, expectedIpcEnv.ipcConfigRefreshInterval, coreEnvs[DDAgentIpcConfigRefreshInterval]) |
| 68 | + |
| 69 | + // core agent |
| 70 | + coreAgentContainer, ok := getContainer(t, deployment.Spec.Template.Spec.Containers, "otel-agent") |
| 71 | + assert.True(t, ok) |
| 72 | + coreEnvs = getEnvVarMap(coreAgentContainer.Env) |
| 73 | + assert.Equal(t, expectedIpcEnv.ipcPort, coreEnvs[DDAgentIpcPort]) |
| 74 | + assert.Equal(t, expectedIpcEnv.ipcConfigRefreshInterval, coreEnvs[DDAgentIpcConfigRefreshInterval]) |
| 75 | +} |
0 commit comments