Skip to content

Commit

Permalink
Revert "Move containers integration tests to e2e provisioners" (DataD…
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinFairise2 authored Dec 5, 2024
1 parent 973511f commit 835a848
Show file tree
Hide file tree
Showing 9 changed files with 681 additions and 131 deletions.
15 changes: 3 additions & 12 deletions test/new-e2e/pkg/environments/aws/kubernetes/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi
// Deploy the agent
if params.agentOptions != nil {
params.agentOptions = append(params.agentOptions, kubernetesagentparams.WithPulumiResourceOptions(utils.PulumiDependsOn(cluster)), kubernetesagentparams.WithFakeintake(fakeIntake), kubernetesagentparams.WithTags([]string{"stackid:" + ctx.Stack()}))

eksParams, err := eks.NewParams(params.eksOptions...)
if err != nil {
return err
}
if eksParams.WindowsNodeGroup {
params.agentOptions = append(params.agentOptions, kubernetesagentparams.WithDeployWindows())
}

kubernetesAgent, err := helm.NewKubernetesAgent(&awsEnv, "eks", cluster.KubeProvider, params.agentOptions...)
if err != nil {
return err
Expand All @@ -135,7 +126,7 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi
}
// Deploy standalone dogstatsd
if params.deployDogstatsd {
if _, err := dogstatsdstandalone.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "dogstatsd-standalone", fakeIntake, true, "", utils.PulumiDependsOn(cluster)); err != nil {
if _, err := dogstatsdstandalone.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "dogstatsd-standalone", fakeIntake, true, ""); err != nil {
return err
}
}
Expand All @@ -147,7 +138,7 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi
}

// dogstatsd clients that report to the Agent
if _, err := dogstatsd.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-dogstatsd", 8125, "/var/run/datadog/dsd.socket", utils.PulumiDependsOn(workloadWithCRDDeps...)); err != nil {
if _, err := dogstatsd.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-dogstatsd", 8125, "/var/run/datadog/dsd.socket", utils.PulumiDependsOn(cluster)); err != nil {
return err
}

Expand All @@ -166,7 +157,7 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi
return err
}

if _, err := mutatedbyadmissioncontroller.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-mutated", "workload-mutated-lib-injection", utils.PulumiDependsOn(workloadWithCRDDeps...)); err != nil {
if _, err := mutatedbyadmissioncontroller.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-mutated", "workload-mutated-lib-injection", utils.PulumiDependsOn(cluster)); err != nil {
return err
}

Expand Down
12 changes: 7 additions & 5 deletions test/new-e2e/pkg/environments/aws/kubernetes/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,19 @@ func KindRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Prov

var dependsOnCrd []pulumi.Resource
if params.agentOptions != nil {
helmValues := `
kindClusterName := ctx.Stack()
helmValues := fmt.Sprintf(`
datadog:
kubelet:
tlsVerify: false
clusterName: "%s"
agents:
useHostNetwork: true
`
`, kindClusterName)

newOpts := []kubernetesagentparams.Option{kubernetesagentparams.WithHelmValues(helmValues), kubernetesagentparams.WithClusterName(kindCluster.ClusterName), kubernetesagentparams.WithTags([]string{"stackid:" + ctx.Stack()})}
newOpts := []kubernetesagentparams.Option{kubernetesagentparams.WithHelmValues(helmValues), kubernetesagentparams.WithTags([]string{"stackid:" + ctx.Stack()})}
params.agentOptions = append(newOpts, params.agentOptions...)
agent, err := helm.NewKubernetesAgent(&awsEnv, "kind", kubeProvider, params.agentOptions...)
agent, err := helm.NewKubernetesAgent(&awsEnv, kindClusterName, kubeProvider, params.agentOptions...)
if err != nil {
return err
}
Expand Down Expand Up @@ -180,7 +182,7 @@ agents:
return err
}

if _, err := mutatedbyadmissioncontroller.K8sAppDefinition(&awsEnv, kubeProvider, "workload-mutated", "workload-mutated-lib-injection", utils.PulumiDependsOn(dependsOnCrd...)); err != nil {
if _, err := mutatedbyadmissioncontroller.K8sAppDefinition(&awsEnv, kubeProvider, "workload-mutated", "workload-mutated-lib-injection"); err != nil {
return err
}

Expand Down
47 changes: 33 additions & 14 deletions test/new-e2e/tests/containers/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"gopkg.in/yaml.v3"
"gopkg.in/zorkian/go-datadog-api.v2"

Expand All @@ -22,21 +23,39 @@ import (
"github.com/DataDog/datadog-agent/pkg/util/pointer"
"github.com/DataDog/datadog-agent/test/fakeintake/aggregator"
fakeintake "github.com/DataDog/datadog-agent/test/fakeintake/client"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
)

type baseSuite[Env any] struct {
e2e.BaseSuite[Env]
type baseSuite struct {
suite.Suite

Fakeintake *fakeintake.Client
clusterName string
startTime time.Time
endTime time.Time
datadogClient *datadog.Client
Fakeintake *fakeintake.Client
clusterName string
}

func (suite *baseSuite[Env]) BeforeTest(suiteName, testName string) {
func (suite *baseSuite) SetupSuite() {
apiKey, err := runner.GetProfile().SecretStore().Get(parameters.APIKey)
suite.Require().NoError(err)
appKey, err := runner.GetProfile().SecretStore().Get(parameters.APPKey)
suite.Require().NoError(err)
suite.datadogClient = datadog.NewClient(apiKey, appKey)

suite.startTime = time.Now()
}

func (suite *baseSuite) TearDownSuite() {
suite.endTime = time.Now()
}

func (suite *baseSuite) BeforeTest(suiteName, testName string) {
suite.T().Logf("START %s/%s %s", suiteName, testName, time.Now())
}

func (suite *baseSuite[Env]) AfterTest(suiteName, testName string) {
func (suite *baseSuite) AfterTest(suiteName, testName string) {
suite.T().Logf("FINISH %s/%s %s", suiteName, testName, time.Now())
}

Expand Down Expand Up @@ -79,7 +98,7 @@ func (mc *myCollectT) Errorf(format string, args ...interface{}) {
mc.CollectT.Errorf(format, args...)
}

func (suite *baseSuite[Env]) testMetric(args *testMetricArgs) {
func (suite *baseSuite) testMetric(args *testMetricArgs) {
prettyMetricQuery := fmt.Sprintf("%s{%s}", args.Filter.Name, strings.Join(args.Filter.Tags, ","))

suite.Run("metric "+prettyMetricQuery, func() {
Expand All @@ -88,7 +107,7 @@ func (suite *baseSuite[Env]) testMetric(args *testMetricArgs) {
expectedTags = lo.Map(*args.Expect.Tags, func(tag string, _ int) *regexp.Regexp { return regexp.MustCompile(tag) })
}

optionalTags := []*regexp.Regexp{regexp.MustCompile("stackid:.*")} // The stackid tag is added by the framework itself to allow filtering on the stack id
var optionalTags []*regexp.Regexp
if args.Optional.Tags != nil {
optionalTags = lo.Map(*args.Optional.Tags, func(tag string, _ int) *regexp.Regexp { return regexp.MustCompile(tag) })
}
Expand All @@ -101,7 +120,7 @@ func (suite *baseSuite[Env]) testMetric(args *testMetricArgs) {
return "filter_tag_" + tag
})

if _, err := suite.DatadogClient().PostEvent(&datadog.Event{
if _, err := suite.datadogClient.PostEvent(&datadog.Event{
Title: pointer.Ptr(fmt.Sprintf("testMetric %s", prettyMetricQuery)),
Text: pointer.Ptr(fmt.Sprintf(`%%%%%%
### Result
Expand Down Expand Up @@ -208,7 +227,7 @@ type testLogExpectArgs struct {
Message string
}

func (suite *baseSuite[Env]) testLog(args *testLogArgs) {
func (suite *baseSuite) testLog(args *testLogArgs) {
prettyLogQuery := fmt.Sprintf("%s{%s}", args.Filter.Service, strings.Join(args.Filter.Tags, ","))

suite.Run("log "+prettyLogQuery, func() {
Expand All @@ -230,7 +249,7 @@ func (suite *baseSuite[Env]) testLog(args *testLogArgs) {
return "filter_tag_" + tag
})

if _, err := suite.DatadogClient().PostEvent(&datadog.Event{
if _, err := suite.datadogClient.PostEvent(&datadog.Event{
Title: pointer.Ptr(fmt.Sprintf("testLog %s", prettyLogQuery)),
Text: pointer.Ptr(fmt.Sprintf(`%%%%%%
### Result
Expand Down Expand Up @@ -337,7 +356,7 @@ type testCheckRunExpectArgs struct {
AcceptUnexpectedTags bool
}

func (suite *baseSuite[Env]) testCheckRun(args *testCheckRunArgs) {
func (suite *baseSuite) testCheckRun(args *testCheckRunArgs) {
prettyCheckRunQuery := fmt.Sprintf("%s{%s}", args.Filter.Name, strings.Join(args.Filter.Tags, ","))

suite.Run("checkRun "+prettyCheckRunQuery, func() {
Expand All @@ -359,7 +378,7 @@ func (suite *baseSuite[Env]) testCheckRun(args *testCheckRunArgs) {
return "filter_tag_" + tag
})

if _, err := suite.DatadogClient().PostEvent(&datadog.Event{
if _, err := suite.datadogClient.PostEvent(&datadog.Event{
Title: pointer.Ptr(fmt.Sprintf("testCheckRun %s", prettyCheckRunQuery)),
Text: pointer.Ptr(fmt.Sprintf(`%%%%%%
### Result
Expand Down
43 changes: 36 additions & 7 deletions test/new-e2e/tests/containers/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,53 @@
package containers

import (
"context"
"encoding/json"
"fmt"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/infra"
"github.com/DataDog/test-infra-definitions/scenarios/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/stretchr/testify/suite"
"os"
"testing"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
awsdocker "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/docker"
)

type DockerSuite struct {
baseSuite[environments.DockerHost]
baseSuite
}

func TestDockerSuite(t *testing.T) {
e2e.Run(t, &DockerSuite{}, e2e.WithProvisioner(awsdocker.Provisioner(awsdocker.WithTestingWorkload())))
suite.Run(t, &DockerSuite{})
}

func (suite *DockerSuite) SetupSuite() {
ctx := context.Background()

stackConfig := runner.ConfigMap{
"ddagent:deploy": auto.ConfigValue{Value: "true"},
"ddagent:fakeintake": auto.ConfigValue{Value: "true"},
}

_, stackOutput, err := infra.GetStackManager().GetStack(ctx, "dockerstack", stackConfig, ec2.VMRunWithDocker, false)
suite.Require().NoError(err)

var fakeintake components.FakeIntake
fiSerialized, err := json.Marshal(stackOutput.Outputs["dd-Fakeintake-aws-aws-vm"].Value)
suite.Require().NoError(err)
suite.Require().NoError(fakeintake.Import(fiSerialized, &fakeintake))
suite.Require().NoError(fakeintake.Init(suite))
suite.Fakeintake = fakeintake.Client()

var host components.RemoteHost
hostSerialized, err := json.Marshal(stackOutput.Outputs["dd-Host-aws-vm"].Value)
suite.Require().NoError(err)
suite.Require().NoError(host.Import(hostSerialized, &host))
suite.Require().NoError(host.Init(suite))
suite.clusterName = fmt.Sprintf("%s-%v", os.Getenv("USER"), host.Address)

suite.baseSuite.SetupSuite()
suite.Fakeintake = suite.Env().FakeIntake.Client()
}

func (suite *DockerSuite) TestDSDWithUDS() {
Expand Down
Loading

0 comments on commit 835a848

Please sign in to comment.