Skip to content

Commit

Permalink
[CONTINT-3783] Add tracegen app to eks and kind scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
AliDatadog authored Feb 19, 2024
2 parents c7d4161 + 10804f7 commit 47ed6c6
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 1 deletion.
164 changes: 164 additions & 0 deletions components/datadog/apps/tracegen/k8s.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package tracegen

import (
"fmt"

"github.com/DataDog/test-infra-definitions/common/config"
"github.com/DataDog/test-infra-definitions/common/utils"

"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes"
appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/apps/v1"
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1"
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/meta/v1"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type K8sComponent struct {
pulumi.ResourceState
}

func K8sAppDefinition(e config.CommonEnvironment, kubeProvider *kubernetes.Provider, namespace string, nodeSelector pulumi.StringMapInput, opts ...pulumi.ResourceOption) (*K8sComponent, error) {
opts = append(opts, pulumi.Provider(kubeProvider), pulumi.Parent(kubeProvider), pulumi.DeletedWith(kubeProvider))

k8sComponent := &K8sComponent{}
if err := e.Ctx.RegisterComponentResource("dd:apps", fmt.Sprintf("%s/tracegen", namespace), k8sComponent, opts...); err != nil {
return nil, err
}

opts = append(opts, pulumi.Parent(k8sComponent))

ns, err := corev1.NewNamespace(e.Ctx, namespace, &corev1.NamespaceArgs{
Metadata: metav1.ObjectMetaArgs{
Name: pulumi.String(namespace),
},
}, opts...)
if err != nil {
return nil, err
}

opts = append(opts, utils.PulumiDependsOn(ns))

if _, err := appsv1.NewDeployment(e.Ctx, fmt.Sprintf("%s/tracegen-uds", namespace), &appsv1.DeploymentArgs{
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("tracegen-uds"),
Namespace: pulumi.String(namespace),
Labels: pulumi.StringMap{
"app": pulumi.String("tracegen-uds"),
},
},
Spec: &appsv1.DeploymentSpecArgs{
Replicas: pulumi.Int(1),
Selector: &metav1.LabelSelectorArgs{
MatchLabels: pulumi.StringMap{
"app": pulumi.String("tracegen-uds"),
},
},
Template: &corev1.PodTemplateSpecArgs{
Metadata: &metav1.ObjectMetaArgs{
Labels: pulumi.StringMap{
"app": pulumi.String("tracegen-uds"),
},
},
Spec: &corev1.PodSpecArgs{
NodeSelector: nodeSelector,
Containers: corev1.ContainerArray{
&corev1.ContainerArgs{
Name: pulumi.String("tracegen-uds"),
Image: pulumi.String("ghcr.io/datadog/apps-tracegen:main"),
Env: &corev1.EnvVarArray{
&corev1.EnvVarArgs{
Name: pulumi.String("DD_TRACE_AGENT_URL"),
Value: pulumi.String("/var/run/datadog/apm.socket"),
},
},
Resources: &corev1.ResourceRequirementsArgs{
Limits: pulumi.StringMap{
"cpu": pulumi.String("10m"),
"memory": pulumi.String("32Mi"),
},
Requests: pulumi.StringMap{
"cpu": pulumi.String("2m"),
"memory": pulumi.String("32Mi"),
},
},
VolumeMounts: &corev1.VolumeMountArray{
&corev1.VolumeMountArgs{
Name: pulumi.String("apmsocketpath"),
MountPath: pulumi.String("/var/run/datadog"),
},
},
},
},
Volumes: corev1.VolumeArray{
&corev1.VolumeArgs{
Name: pulumi.String("apmsocketpath"),
HostPath: &corev1.HostPathVolumeSourceArgs{
Path: pulumi.String("/var/run/datadog"),
},
},
},
},
},
},
}, opts...); err != nil {
return nil, err
}

if _, err := appsv1.NewDeployment(e.Ctx, fmt.Sprintf("%s/tracegen-tcp", namespace), &appsv1.DeploymentArgs{
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("tracegen-tcp"),
Namespace: pulumi.String(namespace),
Labels: pulumi.StringMap{
"app": pulumi.String("tracegen-tcp"),
},
},
Spec: &appsv1.DeploymentSpecArgs{
Replicas: pulumi.Int(1),
Selector: &metav1.LabelSelectorArgs{
MatchLabels: pulumi.StringMap{
"app": pulumi.String("tracegen-tcp"),
},
},
Template: &corev1.PodTemplateSpecArgs{
Metadata: &metav1.ObjectMetaArgs{
Labels: pulumi.StringMap{
"app": pulumi.String("tracegen-tcp"),
},
},
Spec: &corev1.PodSpecArgs{
NodeSelector: nodeSelector,
Containers: corev1.ContainerArray{
&corev1.ContainerArgs{
Name: pulumi.String("tracegen-tcp"),
Image: pulumi.String("ghcr.io/datadog/apps-tracegen:main"),
Env: &corev1.EnvVarArray{
&corev1.EnvVarArgs{
Name: pulumi.String("DD_AGENT_HOST"),
ValueFrom: &corev1.EnvVarSourceArgs{
FieldRef: &corev1.ObjectFieldSelectorArgs{
FieldPath: pulumi.String("status.hostIP"),
},
},
},
},
Resources: &corev1.ResourceRequirementsArgs{
Limits: pulumi.StringMap{
"cpu": pulumi.String("10m"),
"memory": pulumi.String("32Mi"),
},
Requests: pulumi.StringMap{
"cpu": pulumi.String("2m"),
"memory": pulumi.String("32Mi"),
},
},
},
},
},
},
},
}, opts...); err != nil {
return nil, err
}

return k8sComponent, nil
}
19 changes: 19 additions & 0 deletions scenarios/aws/eks/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DataDog/test-infra-definitions/components/datadog/apps/nginx"
"github.com/DataDog/test-infra-definitions/components/datadog/apps/prometheus"
"github.com/DataDog/test-infra-definitions/components/datadog/apps/redis"
"github.com/DataDog/test-infra-definitions/components/datadog/apps/tracegen"
dogstatsdstandalone "github.com/DataDog/test-infra-definitions/components/datadog/dogstatsd-standalone"
fakeintakeComp "github.com/DataDog/test-infra-definitions/components/datadog/fakeintake"
kubeComp "github.com/DataDog/test-infra-definitions/components/kubernetes"
Expand All @@ -28,6 +29,9 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

// eksNodeSelector is the label used to select the node group for tracegen
const eksNodeSelector = "eks.amazonaws.com/nodegroup"

func Run(ctx *pulumi.Context) error {
awsEnv, err := resourcesAws.NewEnvironment(ctx)
if err != nil {
Expand Down Expand Up @@ -132,13 +136,17 @@ func Run(ctx *pulumi.Context) error {
comp.KubeConfig = cluster.KubeconfigJson

nodeGroups := make([]pulumi.Resource, 0)
var cgroupV1Ng pulumi.StringOutput
var cgroupV2Ng pulumi.StringOutput
// Create managed node groups
if awsEnv.EKSLinuxNodeGroup() {
ng, err := localEks.NewLinuxNodeGroup(awsEnv, cluster, linuxNodeRole)
if err != nil {
return err
}
nodeGroups = append(nodeGroups, ng)
// The default AMI used for Amazon Linux 2 is using cgroupv1
cgroupV1Ng = ng.NodeGroup.NodeGroupName()
}

if awsEnv.EKSLinuxARMNodeGroup() {
Expand All @@ -147,6 +155,7 @@ func Run(ctx *pulumi.Context) error {
return err
}
nodeGroups = append(nodeGroups, ng)
cgroupV1Ng = ng.NodeGroup.NodeGroupName()
}

if awsEnv.EKSBottlerocketNodeGroup() {
Expand All @@ -155,6 +164,8 @@ func Run(ctx *pulumi.Context) error {
return err
}
nodeGroups = append(nodeGroups, ng)
// Bottlerocket uses cgroupv2
cgroupV2Ng = ng.NodeGroup.NodeGroupName()
}

// Create unmanaged node groups
Expand Down Expand Up @@ -266,6 +277,14 @@ func Run(ctx *pulumi.Context) error {
return err
}

if _, err := tracegen.K8sAppDefinition(*awsEnv.CommonEnvironment, eksKubeProvider, "workload-tracegen-cgroupv1", pulumi.StringMap{eksNodeSelector: cgroupV1Ng}); err != nil {
return err
}

if _, err := tracegen.K8sAppDefinition(*awsEnv.CommonEnvironment, eksKubeProvider, "workload-tracegen-cgroupv2", pulumi.StringMap{eksNodeSelector: cgroupV2Ng}); err != nil {
return err
}

if _, err := prometheus.K8sAppDefinition(*awsEnv.CommonEnvironment, eksKubeProvider, "workload-prometheus"); err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions scenarios/aws/kindvm/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DataDog/test-infra-definitions/components/datadog/apps/nginx"
"github.com/DataDog/test-infra-definitions/components/datadog/apps/prometheus"
"github.com/DataDog/test-infra-definitions/components/datadog/apps/redis"
"github.com/DataDog/test-infra-definitions/components/datadog/apps/tracegen"
dogstatsdstandalone "github.com/DataDog/test-infra-definitions/components/datadog/dogstatsd-standalone"
fakeintakeComp "github.com/DataDog/test-infra-definitions/components/datadog/fakeintake"
localKubernetes "github.com/DataDog/test-infra-definitions/components/kubernetes"
Expand Down Expand Up @@ -135,6 +136,11 @@ agents:
return err
}

// for tracegen we can't find the cgroup version as it depends on the underlying version of the kernel
if _, err := tracegen.K8sAppDefinition(*awsEnv.CommonEnvironment, kindKubeProvider, "workload-tracegen", nil); err != nil {
return err
}

if _, err := prometheus.K8sAppDefinition(*awsEnv.CommonEnvironment, kindKubeProvider, "workload-prometheus"); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/eks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create_eks(
agent_version: Optional[str] = None,
linux_node_group: bool = True,
linux_arm_node_group: bool = False,
bottlerocket_node_group: bool = False,
bottlerocket_node_group: bool = True,
windows_node_group: bool = False,
instance_type: Optional[str] = None,
):
Expand Down

0 comments on commit 47ed6c6

Please sign in to comment.