Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new-e2e example test for NewDDAWithOperator #31136

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions test/new-e2e/examples/kind_local_operator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package examples

import (
"context"
"github.com/DataDog/test-infra-definitions/components/datadog/agent"
"github.com/DataDog/test-infra-definitions/components/datadog/agentwithoperatorparams"
fakeintakeComp "github.com/DataDog/test-infra-definitions/components/datadog/fakeintake"
"github.com/DataDog/test-infra-definitions/components/datadog/operator"
"github.com/DataDog/test-infra-definitions/components/datadog/operatorparams"
compkube "github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/DataDog/test-infra-definitions/resources/local"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"strings"
"testing"

"github.com/stretchr/testify/assert"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
)

const namespace = "datadog"

type localKindOperatorSuite struct {
e2e.BaseSuite[environments.Kubernetes]
}

func localKindOperatorProvisioner() e2e.PulumiEnvRunFunc[environments.Kubernetes] {
return func(ctx *pulumi.Context, env *environments.Kubernetes) error {
kindEnv, err := local.NewEnvironment(ctx)
if err != nil {
return err
}

kindCluster, err := compkube.NewLocalKindCluster(&kindEnv, kindEnv.CommonNamer().ResourceName("kind-operator"), kindEnv.KubernetesVersion())
if err != nil {
return err
}

if err := kindCluster.Export(ctx, &env.KubernetesCluster.ClusterOutput); err != nil {
return err
}

// Build Kubernetes provider
kindKubeProvider, err := kubernetes.NewProvider(ctx, kindEnv.CommonNamer().ResourceName("k8s-provider"), &kubernetes.ProviderArgs{
Kubeconfig: kindCluster.KubeConfig,
EnableServerSideApply: pulumi.BoolPtr(true),
})
if err != nil {
return err
}

fakeIntake, err := fakeintakeComp.NewLocalDockerFakeintake(&kindEnv, "fakeintake")
if err != nil {
return err
}
if err := fakeIntake.Export(ctx, &env.FakeIntake.FakeintakeOutput); err != nil {
return err
}

// Setup default operator options
operatorOpts := make([]operatorparams.Option, 0)
operatorOpts = append(
operatorOpts,
operatorparams.WithNamespace(namespace),
)

// Create Operator component
_, err = operator.NewOperator(&kindEnv, kindEnv.CommonNamer().ResourceName("dd-operator-agent"), kindKubeProvider, operatorOpts...)

if err != nil {
return err
}

customDDA := agentwithoperatorparams.DDAConfig{
Name: "apm-enabled-no-ccr",
YamlConfig: `
apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
spec:
global:
kubelet:
tlsVerify: false
features:
apm:
enabled: true
`,
}

// Setup DDA options
ddaOptions := make([]agentwithoperatorparams.Option, 0)
ddaOptions = append(
ddaOptions,
agentwithoperatorparams.WithDDAConfig(customDDA),
agentwithoperatorparams.WithNamespace(namespace),
agentwithoperatorparams.WithFakeIntake(fakeIntake),
)

// Create Datadog Agent with Operator component
agentComponent, err := agent.NewDDAWithOperator(&kindEnv, kindEnv.CommonNamer().ResourceName("dd-operator-agent"), kindKubeProvider, ddaOptions...)

if err != nil {
return err
}

if err = agentComponent.Export(ctx, &env.Agent.KubernetesAgentOutput); err != nil {
return err
}

return nil
}
}

func TestOperatorKindSuite(t *testing.T) {
e2e.Run(t, &localKindOperatorSuite{}, e2e.WithPulumiProvisioner(localKindOperatorProvisioner(), nil))
}

func (k *localKindOperatorSuite) TestClusterAgentInstalled() {
res, _ := k.Env().KubernetesCluster.Client().CoreV1().Pods(namespace).List(context.TODO(), v1.ListOptions{})
containsClusterAgent := false
for _, pod := range res.Items {
if strings.Contains(pod.Name, "cluster-agent") {
containsClusterAgent = true
break
}
}
assert.True(k.T(), containsClusterAgent, "Cluster Agent not found")
}
65 changes: 65 additions & 0 deletions test/new-e2e/examples/kind_operator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package examples

import (
"context"
awskubernetes "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/kubernetes"
"github.com/DataDog/test-infra-definitions/components/datadog/agentwithoperatorparams"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
"testing"
"time"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
"github.com/stretchr/testify/assert"
)

type kindOperatorSuite struct {
e2e.BaseSuite[environments.Kubernetes]
}

func TestKindOperatorSuite(t *testing.T) {
customDDA := agentwithoperatorparams.DDAConfig{
Name: "apm-enabled",
YamlConfig: `
apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
spec:
global:
kubelet:
tlsVerify: false
features:
apm:
enabled: true
`,
}

e2e.Run(t, &kindOperatorSuite{}, e2e.WithProvisioner(awskubernetes.KindProvisioner(
awskubernetes.WithOperator(),
awskubernetes.WithOperatorDDAOptions([]agentwithoperatorparams.Option{
agentwithoperatorparams.WithDDAConfig(customDDA),
}...),
)),
e2e.WithDevMode(), e2e.WithSkipDeleteOnFailure())
}

func (v *kindOperatorSuite) TestClusterAgentInstalled() {
v.EventuallyWithT(func(c *assert.CollectT) {
res, _ := v.Env().KubernetesCluster.Client().CoreV1().Pods("datadog").List(context.TODO(), v1.ListOptions{
FieldSelector: "status.phase=Running",
})
containsClusterAgent := false
for _, pod := range res.Items {
if strings.Contains(pod.Name, "cluster-agent") {
containsClusterAgent = true
break
}
}
assert.True(v.T(), containsClusterAgent, "Cluster Agent not found")
}, 30*time.Second, 15*time.Second)
}
14 changes: 7 additions & 7 deletions test/new-e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ replace (
github.com/DataDog/datadog-agent/pkg/util/winutil => ../../pkg/util/winutil
github.com/DataDog/datadog-agent/pkg/version => ../../pkg/version
github.com/DataDog/datadog-agent/test/fakeintake => ../fakeintake
github.com/DataDog/test-infra-definitions => ../../../test-infra-definitions
)

require (
Expand Down Expand Up @@ -74,8 +75,7 @@ require (
github.com/pkg/sftp v1.13.6
github.com/pulumi/pulumi-aws/sdk/v6 v6.56.1
github.com/pulumi/pulumi-awsx/sdk/v2 v2.16.1
github.com/pulumi/pulumi-eks/sdk/v2 v2.8.1 // indirect
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.17.1
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.18.3
github.com/pulumi/pulumi/sdk/v3 v3.140.0
github.com/samber/lo v1.47.0
github.com/stretchr/testify v1.10.0
Expand Down Expand Up @@ -303,13 +303,13 @@ require (
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/onsi/ginkgo/v2 v2.20.2 // indirect
github.com/onsi/gomega v1.34.1 // indirect
github.com/pulumi/pulumi-azure-native-sdk/authorization/v2 v2.67.0 // indirect
github.com/pulumi/pulumi-azure-native-sdk/compute/v2 v2.56.0 // indirect
github.com/pulumi/pulumi-azure-native-sdk/containerservice/v2 v2.67.0 // indirect
github.com/pulumi/pulumi-azure-native-sdk/authorization/v2 v2.73.1 // indirect
github.com/pulumi/pulumi-azure-native-sdk/compute/v2 v2.73.1 // indirect
github.com/pulumi/pulumi-azure-native-sdk/containerservice/v2 v2.73.1 // indirect
github.com/pulumi/pulumi-azure-native-sdk/managedidentity/v2 v2.73.1 // indirect
github.com/pulumi/pulumi-azure-native-sdk/network/v2 v2.67.0 // indirect
github.com/pulumi/pulumi-azure-native-sdk/network/v2 v2.73.1 // indirect
github.com/pulumi/pulumi-azure-native-sdk/v2 v2.73.1 // indirect
github.com/pulumi/pulumi-gcp/sdk/v6 v6.67.1 // indirect
github.com/pulumi/pulumi-eks/sdk/v3 v3.3.0 // indirect
github.com/pulumi/pulumi-gcp/sdk/v7 v7.38.0 // indirect
github.com/twinj/uuid v0.0.0-20151029044442-89173bcdda19 // indirect
github.com/x448/float16 v0.8.4 // indirect
Expand Down
28 changes: 12 additions & 16 deletions test/new-e2e/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/new-e2e/pkg/components/operator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package components

import (
"github.com/DataDog/test-infra-definitions/components/datadog/operator"
)

// Operator is a Datadog Operator running in a Kubernetes cluster
type Operator struct {
operator.OperatorOutput
}
51 changes: 47 additions & 4 deletions test/new-e2e/pkg/environments/aws/kubernetes/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ package awskubernetes
import (
"context"
"fmt"

"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/DataDog/test-infra-definitions/components/datadog/agent"
"github.com/DataDog/test-infra-definitions/components/datadog/agentwithoperatorparams"
"github.com/DataDog/test-infra-definitions/components/datadog/operator"
"github.com/DataDog/test-infra-definitions/components/datadog/operatorparams"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
Expand Down Expand Up @@ -123,12 +126,16 @@ func KindRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Prov
newOpts := []kubernetesagentparams.Option{kubernetesagentparams.WithFakeintake(fakeIntake)}
params.agentOptions = append(newOpts, params.agentOptions...)
}
if params.operatorDDAOptions != nil {
newDdaOpts := []agentwithoperatorparams.Option{agentwithoperatorparams.WithFakeIntake(fakeIntake)}
params.operatorDDAOptions = append(newDdaOpts, params.operatorDDAOptions...)
}
} else {
env.FakeIntake = nil
}

var dependsOnCrd []pulumi.Resource
if params.agentOptions != nil {
if params.agentOptions != nil && !params.deployOperator {
helmValues := `
datadog:
kubelet:
Expand All @@ -148,8 +155,23 @@ agents:
return err
}
dependsOnCrd = append(dependsOnCrd, agent)
} else {
env.Agent = nil
}

if params.deployOperator {
operatorOpts := make([]operatorparams.Option, 0)
operatorOpts = append(
operatorOpts,
params.operatorOptions...,
)

operatorComp, err := operator.NewOperator(&awsEnv, awsEnv.Namer.ResourceName("dd-operator"), kubeProvider, operatorOpts...)
if err != nil {
return err
}
err = operatorComp.Export(ctx, nil)
if err != nil {
return err
}
}

if params.deployDogstatsd {
Expand Down Expand Up @@ -206,5 +228,26 @@ agents:
}
}

if params.operatorDDAOptions != nil {
ddaOptions := make([]agentwithoperatorparams.Option, 0)
ddaOptions = append(
ddaOptions,
params.operatorDDAOptions...,
)

ddaWithOperatorComp, err := agent.NewDDAWithOperator(&awsEnv, awsEnv.CommonNamer().ResourceName("dd-operator-agent"), kubeProvider, ddaOptions...)
if err != nil {
return err
}

if err := ddaWithOperatorComp.Export(ctx, &env.Agent.KubernetesAgentOutput); err != nil {
return err
}
dependsOnCrd = append(dependsOnCrd, ddaWithOperatorComp)

} else {
env.Agent = nil
}

return nil
}
Loading
Loading