|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed |
| 2 | +// under the Apache License Version 2.0. |
| 3 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 4 | +// Copyright 2016-present Datadog, Inc. |
| 5 | +package ssi |
| 6 | + |
| 7 | +import ( |
| 8 | + "os" |
| 9 | + "testing" |
| 10 | + "time" |
| 11 | + |
| 12 | + "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes" |
| 13 | + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" |
| 14 | + "github.com/stretchr/testify/require" |
| 15 | + |
| 16 | + "github.com/DataDog/datadog-agent/pkg/ssi/testutils" |
| 17 | + "github.com/DataDog/datadog-agent/test/e2e-framework/common/config" |
| 18 | + "github.com/DataDog/datadog-agent/test/e2e-framework/components/datadog/apps/singlestep" |
| 19 | + "github.com/DataDog/datadog-agent/test/e2e-framework/components/datadog/kubernetesagentparams" |
| 20 | + compkube "github.com/DataDog/datadog-agent/test/e2e-framework/components/kubernetes" |
| 21 | + "github.com/DataDog/datadog-agent/test/e2e-framework/scenarios/aws/kindvm" |
| 22 | + "github.com/DataDog/datadog-agent/test/e2e-framework/testing/e2e" |
| 23 | + "github.com/DataDog/datadog-agent/test/e2e-framework/testing/environments" |
| 24 | + provkindvm "github.com/DataDog/datadog-agent/test/e2e-framework/testing/provisioners/aws/kubernetes/kindvm" |
| 25 | +) |
| 26 | + |
| 27 | +type localSDKInjectionSuite struct { |
| 28 | + e2e.BaseSuite[environments.Kubernetes] |
| 29 | +} |
| 30 | + |
| 31 | +func TestLocalSDKInjectionSuite(t *testing.T) { |
| 32 | + helmValues, err := os.ReadFile("testdata/local_sdk_injection.yaml") |
| 33 | + require.NoError(t, err, "Could not open helm values file for test") |
| 34 | + e2e.Run(t, &localSDKInjectionSuite{}, e2e.WithProvisioner(provkindvm.Provisioner( |
| 35 | + provkindvm.WithRunOptions( |
| 36 | + kindvm.WithAgentDependentWorkloadApp(func(e config.Env, kubeProvider *kubernetes.Provider, dependsOnAgent pulumi.ResourceOption) (*compkube.Workload, error) { |
| 37 | + return singlestep.Scenario(e, kubeProvider, "workload-selection", []singlestep.Namespace{ |
| 38 | + { |
| 39 | + Name: "application", |
| 40 | + Apps: []singlestep.App{ |
| 41 | + { |
| 42 | + Name: DefaultAppName, |
| 43 | + Image: "registry.ddbuild.io/ci/injector-dev/python", |
| 44 | + Version: "2cd78ded", |
| 45 | + Port: 8080, |
| 46 | + PodLabels: map[string]string{ |
| 47 | + "admission.datadoghq.com/enabled": "true", |
| 48 | + }, |
| 49 | + PodAnnotations: map[string]string{ |
| 50 | + "dmission.datadoghq.com/python-lib.version": "v3.18.1", |
| 51 | + }, |
| 52 | + }, |
| 53 | + { |
| 54 | + Name: "expect-no-injection", |
| 55 | + Image: "registry.ddbuild.io/ci/injector-dev/python", |
| 56 | + Version: "2cd78ded", |
| 57 | + Port: 8080, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | + }, dependsOnAgent) |
| 62 | + }), |
| 63 | + kindvm.WithAgentOptions(kubernetesagentparams.WithHelmValues(string(helmValues))), |
| 64 | + ), |
| 65 | + ))) |
| 66 | +} |
| 67 | + |
| 68 | +func (v *localSDKInjectionSuite) TestClusterAgentInstalled() { |
| 69 | + FindPodInNamespace(v.T(), v.Env().KubernetesCluster.Client(), "datadog", "cluster-agent") |
| 70 | +} |
| 71 | + |
| 72 | +func (v *localSDKInjectionSuite) TestExpectInjection() { |
| 73 | + // Get clients. |
| 74 | + intake := v.Env().FakeIntake.Client() |
| 75 | + k8s := v.Env().KubernetesCluster.Client() |
| 76 | + |
| 77 | + // Ensure the pod was injected. |
| 78 | + pod := FindPodInNamespace(v.T(), k8s, "application", DefaultAppName) |
| 79 | + podValidator := testutils.NewPodValidator(pod) |
| 80 | + podValidator.RequireInjection(v.T(), DefaultExpectedContainers) |
| 81 | + podValidator.RequireLibraryVersions(v.T(), map[string]string{ |
| 82 | + "python": "v3.18.1", |
| 83 | + }) |
| 84 | + podValidator.RequireInjectorVersion(v.T(), "0.52.0") |
| 85 | + |
| 86 | + // Ensure the service has traces. |
| 87 | + require.Eventually(v.T(), func() bool { |
| 88 | + traces := FindTracesForService(v.T(), intake, DefaultAppName) |
| 89 | + return len(traces) != 0 |
| 90 | + }, 1*time.Minute, 10*time.Second, "did not find any traces at intake for DD_SERVICE %s", DefaultAppName) |
| 91 | +} |
| 92 | + |
| 93 | +func (v *localSDKInjectionSuite) TestExpectNoInjection() { |
| 94 | + pod := FindPodInNamespace(v.T(), v.Env().KubernetesCluster.Client(), "application", "expect-no-injection") |
| 95 | + podValidator := testutils.NewPodValidator(pod) |
| 96 | + podValidator.RequireNoInjection(v.T()) |
| 97 | +} |
0 commit comments