Skip to content

Commit

Permalink
Revert "Revert "Move containers integration tests to e2e provisioners… (
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinFairise2 authored Dec 23, 2024
1 parent 6c2e98e commit e6c945e
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 690 deletions.
32 changes: 24 additions & 8 deletions test/new-e2e/pkg/provisioners/aws/kubernetes/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
dogstatsdstandalone "github.com/DataDog/test-infra-definitions/components/datadog/dogstatsd-standalone"
fakeintakeComp "github.com/DataDog/test-infra-definitions/components/datadog/fakeintake"
"github.com/DataDog/test-infra-definitions/components/datadog/kubernetesagentparams"
"github.com/DataDog/test-infra-definitions/components/kubernetes/vpa"
"github.com/DataDog/test-infra-definitions/resources/aws"
"github.com/DataDog/test-infra-definitions/scenarios/aws/eks"
"github.com/DataDog/test-infra-definitions/scenarios/aws/fakeintake"
Expand Down Expand Up @@ -88,6 +89,12 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi
return nil
}

vpaCrd, err := vpa.DeployCRD(&awsEnv, cluster.KubeProvider)
if err != nil {
return err
}
dependsOnVPA := utils.PulumiDependsOn(vpaCrd)

var fakeIntake *fakeintakeComp.Fakeintake
if params.fakeintakeOptions != nil {
fakeIntakeOptions := []fakeintake.Option{
Expand All @@ -108,10 +115,19 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi
env.FakeIntake = nil
}

workloadWithCRDDeps := []pulumi.Resource{cluster}
var dependsOnDDAgent pulumi.ResourceOption
// 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 @@ -120,7 +136,7 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi
if err != nil {
return err
}
workloadWithCRDDeps = append(workloadWithCRDDeps, kubernetesAgent)
dependsOnDDAgent = utils.PulumiDependsOn(kubernetesAgent)
} else {
env.Agent = nil
}
Expand All @@ -133,18 +149,18 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi

if params.deployTestWorkload {

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

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

if params.deployDogstatsd {
// dogstatsd clients that report to the dogstatsd standalone deployment
if _, err := dogstatsd.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-dogstatsd-standalone", dogstatsdstandalone.HostPort, dogstatsdstandalone.Socket, utils.PulumiDependsOn(cluster)); err != nil {
if _, err := dogstatsd.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-dogstatsd-standalone", dogstatsdstandalone.HostPort, dogstatsdstandalone.Socket, dependsOnDDAgent /* for admission */); err != nil {
return err
}
}
Expand All @@ -157,17 +173,17 @@ 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(cluster)); err != nil {
if _, err := mutatedbyadmissioncontroller.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-mutated", "workload-mutated-lib-injection", dependsOnDDAgent /* for admission */); err != nil {
return err
}

// These resources cannot be deployed if the Agent is not installed, it requires some CRDs provided by the Helm chart
if params.agentOptions != nil {
if _, err := nginx.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-nginx", "", true, utils.PulumiDependsOn(workloadWithCRDDeps...)); err != nil {
if _, err := nginx.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-nginx", "", true, dependsOnDDAgent /* for DDM */, dependsOnVPA); err != nil {
return err
}

if _, err := redis.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-redis", true, utils.PulumiDependsOn(workloadWithCRDDeps...)); err != nil {
if _, err := redis.K8sAppDefinition(&awsEnv, cluster.KubeProvider, "workload-redis", true, dependsOnDDAgent /* for DDM */, dependsOnVPA); err != nil {
return err
}
}
Expand Down
33 changes: 19 additions & 14 deletions test/new-e2e/pkg/provisioners/aws/kubernetes/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
fakeintakeComp "github.com/DataDog/test-infra-definitions/components/datadog/fakeintake"
"github.com/DataDog/test-infra-definitions/components/datadog/kubernetesagentparams"
kubeComp "github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/DataDog/test-infra-definitions/components/kubernetes/vpa"
"github.com/DataDog/test-infra-definitions/resources/aws"
"github.com/DataDog/test-infra-definitions/scenarios/aws/ec2"
"github.com/DataDog/test-infra-definitions/scenarios/aws/fakeintake"
Expand Down Expand Up @@ -106,6 +107,12 @@ func KindRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Prov
return err
}

vpaCrd, err := vpa.DeployCRD(&awsEnv, kubeProvider)
if err != nil {
return err
}
dependsOnVPA := utils.PulumiDependsOn(vpaCrd)

var fakeIntake *fakeintakeComp.Fakeintake
if params.fakeintakeOptions != nil {
fakeintakeOpts := []fakeintake.Option{fakeintake.WithLoadBalancer()}
Expand All @@ -127,29 +134,27 @@ func KindRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Prov
env.FakeIntake = nil
}

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

newOpts := []kubernetesagentparams.Option{kubernetesagentparams.WithHelmValues(helmValues), kubernetesagentparams.WithTags([]string{"stackid:" + ctx.Stack()})}
newOpts := []kubernetesagentparams.Option{kubernetesagentparams.WithHelmValues(helmValues), kubernetesagentparams.WithClusterName(kindCluster.ClusterName), kubernetesagentparams.WithTags([]string{"stackid:" + ctx.Stack()})}
params.agentOptions = append(newOpts, params.agentOptions...)
agent, err := helm.NewKubernetesAgent(&awsEnv, kindClusterName, kubeProvider, params.agentOptions...)
agent, err := helm.NewKubernetesAgent(&awsEnv, "kind", kubeProvider, params.agentOptions...)
if err != nil {
return err
}
err = agent.Export(ctx, &env.Agent.KubernetesAgentOutput)
if err != nil {
return err
}
dependsOnCrd = append(dependsOnCrd, agent)
dependsOnDDAgent = utils.PulumiDependsOn(agent)
} else {
env.Agent = nil
}
Expand All @@ -163,13 +168,13 @@ agents:
// Deploy testing workload
if params.deployTestWorkload {
// dogstatsd clients that report to the Agent
if _, err := dogstatsd.K8sAppDefinition(&awsEnv, kubeProvider, "workload-dogstatsd", 8125, "/var/run/datadog/dsd.socket"); err != nil {
if _, err := dogstatsd.K8sAppDefinition(&awsEnv, kubeProvider, "workload-dogstatsd", 8125, "/var/run/datadog/dsd.socket", dependsOnDDAgent /* for admission */); err != nil {
return err
}

if params.deployDogstatsd {
// dogstatsd clients that report to the dogstatsd standalone deployment
if _, err := dogstatsd.K8sAppDefinition(&awsEnv, kubeProvider, "workload-dogstatsd-standalone", dogstatsdstandalone.HostPort, dogstatsdstandalone.Socket); err != nil {
if _, err := dogstatsd.K8sAppDefinition(&awsEnv, kubeProvider, "workload-dogstatsd-standalone", dogstatsdstandalone.HostPort, dogstatsdstandalone.Socket, dependsOnDDAgent /* for admission */); err != nil {
return err
}
}
Expand All @@ -182,21 +187,21 @@ agents:
return err
}

if _, err := mutatedbyadmissioncontroller.K8sAppDefinition(&awsEnv, kubeProvider, "workload-mutated", "workload-mutated-lib-injection"); err != nil {
if _, err := mutatedbyadmissioncontroller.K8sAppDefinition(&awsEnv, kubeProvider, "workload-mutated", "workload-mutated-lib-injection", dependsOnDDAgent /* for admission */); err != nil {
return err
}

// These workloads can be deployed only if the agent is installed, they rely on CRDs installed by Agent helm chart
if params.agentOptions != nil {
if _, err := nginx.K8sAppDefinition(&awsEnv, kubeProvider, "workload-nginx", "", true, utils.PulumiDependsOn(dependsOnCrd...)); err != nil {
if _, err := nginx.K8sAppDefinition(&awsEnv, kubeProvider, "workload-nginx", "", true, dependsOnDDAgent /* for DDM */, dependsOnVPA); err != nil {
return err
}

if _, err := redis.K8sAppDefinition(&awsEnv, kubeProvider, "workload-redis", true, utils.PulumiDependsOn(dependsOnCrd...)); err != nil {
if _, err := redis.K8sAppDefinition(&awsEnv, kubeProvider, "workload-redis", true, dependsOnDDAgent /* for DDM */, dependsOnVPA); err != nil {
return err
}

if _, err := cpustress.K8sAppDefinition(&awsEnv, kubeProvider, "workload-cpustress", utils.PulumiDependsOn(dependsOnCrd...)); err != nil {
if _, err := cpustress.K8sAppDefinition(&awsEnv, kubeProvider, "workload-cpustress"); err != nil {
return err
}
}
Expand Down
47 changes: 14 additions & 33 deletions test/new-e2e/tests/containers/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 @@ -23,39 +22,21 @@ 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/runner"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
)

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

startTime time.Time
endTime time.Time
datadogClient *datadog.Client
Fakeintake *fakeintake.Client
clusterName string
Fakeintake *fakeintake.Client
clusterName 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) {
func (suite *baseSuite[Env]) BeforeTest(suiteName, testName string) {
suite.T().Logf("START %s/%s %s", suiteName, testName, time.Now())
}

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

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

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

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

var optionalTags []*regexp.Regexp
optionalTags := []*regexp.Regexp{regexp.MustCompile("stackid:.*")} // The stackid tag is added by the framework itself to allow filtering on the stack id
if args.Optional.Tags != nil {
optionalTags = lo.Map(*args.Optional.Tags, func(tag string, _ int) *regexp.Regexp { return regexp.MustCompile(tag) })
}
Expand All @@ -120,7 +101,7 @@ func (suite *baseSuite) 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 @@ -227,7 +208,7 @@ type testLogExpectArgs struct {
Message string
}

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

suite.Run("log "+prettyLogQuery, func() {
Expand All @@ -249,7 +230,7 @@ func (suite *baseSuite) 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 @@ -356,7 +337,7 @@ type testCheckRunExpectArgs struct {
AcceptUnexpectedTags bool
}

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

suite.Run("checkRun "+prettyCheckRunQuery, func() {
Expand All @@ -378,7 +359,7 @@ func (suite *baseSuite) 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: 6 additions & 37 deletions test/new-e2e/tests/containers/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,24 @@
package containers

import (
"context"
"encoding/json"
"fmt"
"os"
"testing"

"github.com/DataDog/test-infra-definitions/scenarios/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/stretchr/testify/suite"

"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/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/provisioners/aws/docker"
)

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

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

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 e6c945e

Please sign in to comment.