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

DDA w/operator component cleanups and improvements #1251

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
13 changes: 7 additions & 6 deletions components/datadog/agent/helm/kubernetes_agent.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helm

import (
componentskube "github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"

Expand Down Expand Up @@ -43,23 +44,23 @@ func NewKubernetesAgent(e config.Env, resourceName string, kubeProvider *kuberne

baseName := "dda-" + platform

comp.LinuxNodeAgent, err = agent.NewKubernetesObjRef(e, baseName+"-nodeAgent", params.Namespace, "Pod", appVersion, version, map[string]string{
comp.LinuxNodeAgent, err = componentskube.NewKubernetesObjRef(e, baseName+"-nodeAgent", params.Namespace, "Pod", appVersion, version, map[string]string{
"app": baseName + "-datadog",
})

if err != nil {
return err
}

comp.LinuxClusterAgent, err = agent.NewKubernetesObjRef(e, baseName+"-clusterAgent", params.Namespace, "Pod", appVersion, version, map[string]string{
comp.LinuxClusterAgent, err = componentskube.NewKubernetesObjRef(e, baseName+"-clusterAgent", params.Namespace, "Pod", appVersion, version, map[string]string{
"app": baseName + "-datadog-cluster-agent",
})

if err != nil {
return err
}

comp.LinuxClusterChecks, err = agent.NewKubernetesObjRef(e, baseName+"-clusterChecks", params.Namespace, "Pod", appVersion, version, map[string]string{
comp.LinuxClusterChecks, err = componentskube.NewKubernetesObjRef(e, baseName+"-clusterChecks", params.Namespace, "Pod", appVersion, version, map[string]string{
"app": baseName + "-datadog-clusterchecks",
})

Expand All @@ -70,21 +71,21 @@ func NewKubernetesAgent(e config.Env, resourceName string, kubeProvider *kuberne

baseName = "dda-" + platform

comp.WindowsNodeAgent, err = agent.NewKubernetesObjRef(e, baseName+"-nodeAgent", params.Namespace, "Pod", appVersion, version, map[string]string{
comp.WindowsNodeAgent, err = componentskube.NewKubernetesObjRef(e, baseName+"-nodeAgent", params.Namespace, "Pod", appVersion, version, map[string]string{
"app": baseName + "-datadog",
})
if err != nil {
return err
}

comp.WindowsClusterAgent, err = agent.NewKubernetesObjRef(e, baseName+"-clusterAgent", params.Namespace, "Pod", appVersion, version, map[string]string{
comp.WindowsClusterAgent, err = componentskube.NewKubernetesObjRef(e, baseName+"-clusterAgent", params.Namespace, "Pod", appVersion, version, map[string]string{
"app": baseName + "-datadog-cluster-agent",
})
if err != nil {
return err
}

comp.WindowsClusterChecks, err = agent.NewKubernetesObjRef(e, baseName+"-clusterChecks", params.Namespace, "Pod", appVersion, version, map[string]string{
comp.WindowsClusterChecks, err = componentskube.NewKubernetesObjRef(e, baseName+"-clusterChecks", params.Namespace, "Pod", appVersion, version, map[string]string{
"app": baseName + "-datadog-clusterchecks",
})
if err != nil {
Expand Down
25 changes: 13 additions & 12 deletions components/datadog/agent/kubernetes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"

"github.com/DataDog/test-infra-definitions/components"
Expand All @@ -9,27 +10,27 @@ import (
type KubernetesAgentOutput struct {
components.JSONImporter

LinuxNodeAgent KubernetesObjRefOutput `json:"linuxNodeAgent"`
LinuxClusterAgent KubernetesObjRefOutput `json:"linuxClusterAgent"`
LinuxClusterChecks KubernetesObjRefOutput `json:"linuxClusterChecks"`
LinuxNodeAgent kubernetes.KubernetesObjRefOutput `json:"linuxNodeAgent"`
LinuxClusterAgent kubernetes.KubernetesObjRefOutput `json:"linuxClusterAgent"`
LinuxClusterChecks kubernetes.KubernetesObjRefOutput `json:"linuxClusterChecks"`

WindowsNodeAgent KubernetesObjRefOutput `json:"windowsNodeAgent"`
WindowsClusterAgent KubernetesObjRefOutput `json:"windowsClusterAgent"`
WindowsClusterChecks KubernetesObjRefOutput `json:"windowsClusterChecks"`
WindowsNodeAgent kubernetes.KubernetesObjRefOutput `json:"windowsNodeAgent"`
WindowsClusterAgent kubernetes.KubernetesObjRefOutput `json:"windowsClusterAgent"`
WindowsClusterChecks kubernetes.KubernetesObjRefOutput `json:"windowsClusterChecks"`
}

// KubernetesAgent is an installer to install the Datadog Agent on a Kubernetes cluster.
type KubernetesAgent struct {
pulumi.ResourceState
components.Component

LinuxNodeAgent *KubernetesObjectRef `pulumi:"linuxNodeAgent"`
LinuxClusterAgent *KubernetesObjectRef `pulumi:"linuxClusterAgent"`
LinuxClusterChecks *KubernetesObjectRef `pulumi:"linuxClusterChecks"`
LinuxNodeAgent *kubernetes.KubernetesObjectRef `pulumi:"linuxNodeAgent"`
LinuxClusterAgent *kubernetes.KubernetesObjectRef `pulumi:"linuxClusterAgent"`
LinuxClusterChecks *kubernetes.KubernetesObjectRef `pulumi:"linuxClusterChecks"`

WindowsNodeAgent *KubernetesObjectRef `pulumi:"windowsNodeAgent"`
WindowsClusterAgent *KubernetesObjectRef `pulumi:"windowsClusterAgent"`
WindowsClusterChecks *KubernetesObjectRef `pulumi:"windowsClusterChecks"`
WindowsNodeAgent *kubernetes.KubernetesObjectRef `pulumi:"windowsNodeAgent"`
WindowsClusterAgent *kubernetes.KubernetesObjectRef `pulumi:"windowsClusterAgent"`
WindowsClusterChecks *kubernetes.KubernetesObjectRef `pulumi:"windowsClusterChecks"`
}

func (h *KubernetesAgent) Export(ctx *pulumi.Context, out *KubernetesAgentOutput) error {
Expand Down
36 changes: 11 additions & 25 deletions components/datadog/agent/kubernetes_operator.go
Original file line number Diff line number Diff line change
@@ -1,62 +1,48 @@
package agent

import (
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"

"github.com/DataDog/test-infra-definitions/common/config"
"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/DataDog/test-infra-definitions/components"
"github.com/DataDog/test-infra-definitions/components/datadog/agentwithoperatorparams"
"github.com/DataDog/test-infra-definitions/components/datadog/apps/dda"
"github.com/DataDog/test-infra-definitions/components/datadog/operator"
"github.com/DataDog/test-infra-definitions/components/datadog/operatorparams"
componentskube "github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func NewDDAWithOperator(e config.Env, resourceName string, kubeProvider *kubernetes.Provider, operatorOpts []operatorparams.Option, ddaOptions ...agentwithoperatorparams.Option) (*KubernetesAgent, error) {
func NewDDAWithOperator(e config.Env, resourceName string, kubeProvider *kubernetes.Provider, ddaOptions ...agentwithoperatorparams.Option) (*KubernetesAgent, error) {
return components.NewComponent(e, resourceName, func(comp *KubernetesAgent) error {

operatorParams, err := operatorparams.NewParams(e, operatorOpts...)
if err != nil {
return err
}

ddaParams, err := agentwithoperatorparams.NewParams(ddaOptions...)

if err != nil {
return err
}

operatorComp, err := operator.NewOperator(e, resourceName, kubeProvider, operatorOpts...)

if err != nil {
return err
}
pulumiResourceOptions := append(ddaParams.PulumiResourceOptions, pulumi.Parent(comp))

_, err = dda.K8sAppDefinition(e, kubeProvider, "datadog", ddaParams.FakeIntake, ddaParams.KubeletTLSVerify, e.Ctx().Stack(), ddaParams.DDAConfig, utils.PulumiDependsOn(operatorComp))
_, err = dda.K8sAppDefinition(e, kubeProvider, ddaParams, pulumiResourceOptions...)

if err != nil {
return err
}

baseName := "dda-linux"

comp.LinuxNodeAgent, err = NewKubernetesObjRef(e, baseName+"-nodeAgent", operatorParams.Namespace, "Pod", pulumi.String("appVersion").ToStringOutput(), pulumi.String("Version").ToStringOutput(), map[string]string{"app": baseName + "-datadog"})
comp.LinuxNodeAgent, err = componentskube.NewKubernetesObjRef(e, baseName+"-nodeAgent", ddaParams.Namespace, "Pod", pulumi.String("").ToStringOutput(), pulumi.String("datadoghq/v2alpha1").ToStringOutput(), map[string]string{"app.kubernetes.io/instance": ddaParams.DDAConfig.Name + "-agent"})

if err != nil {
return err
}

comp.LinuxClusterAgent, err = NewKubernetesObjRef(e, baseName+"-clusterAgent", operatorParams.Namespace, "Pod", pulumi.String("appVersion").ToStringOutput(), pulumi.String("Version").ToStringOutput(), map[string]string{
"app": baseName + "-datadog-cluster-agent",
comp.LinuxClusterAgent, err = componentskube.NewKubernetesObjRef(e, baseName+"-clusterAgent", ddaParams.Namespace, "Pod", pulumi.String("").ToStringOutput(), pulumi.String("datadoghq/v2alpha1").ToStringOutput(), map[string]string{
"app.kubernetes.io/instance": ddaParams.DDAConfig.Name + "-cluster-agent",
})

if err != nil {
return err
}

comp.LinuxClusterChecks, err = NewKubernetesObjRef(e, baseName+"-clusterChecks", operatorParams.Namespace, "Pod", pulumi.String("appVersion").ToStringOutput(), pulumi.String("version").ToStringOutput(), map[string]string{
"app": baseName + "-datadog-clusterchecks",
comp.LinuxClusterChecks, err = componentskube.NewKubernetesObjRef(e, baseName+"-clusterChecks", ddaParams.Namespace, "Pod", pulumi.String("").ToStringOutput(), pulumi.String("datadoghq/v2alpha1").ToStringOutput(), map[string]string{
"app.kubernetes.io/instance": ddaParams.DDAConfig.Name + "-cluster-checks-runner",
})

if err != nil {
Expand Down
36 changes: 21 additions & 15 deletions components/datadog/agentwithoperatorparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import (
type Params struct {
PulumiResourceOptions []pulumi.ResourceOption

Namespace string
FakeIntake *fakeintake.Fakeintake
DDAConfig string
KubeletTLSVerify bool
Namespace string
FakeIntake *fakeintake.Fakeintake
DDAConfig DDAConfig
}

type Option = func(*Params) error

func NewParams(options ...Option) (*Params, error) {
version := &Params{
Namespace: "datadog",
DDAConfig: DDAConfig{
Name: "dda",
},
}
return common.ApplyOption(version, options)
}
Expand All @@ -34,14 +36,6 @@ func WithNamespace(namespace string) func(*Params) error {
}
}

// WithTLSKubeletVerify toggles kubelet TLS verification.
func WithTLSKubeletVerify(verify bool) func(*Params) error {
return func(p *Params) error {
p.KubeletTLSVerify = verify
return nil
}
}

// WithPulumiResourceOptions sets the resources to depend on.
func WithPulumiResourceOptions(resources ...pulumi.ResourceOption) func(*Params) error {
return func(p *Params) error {
Expand All @@ -50,10 +44,10 @@ func WithPulumiResourceOptions(resources ...pulumi.ResourceOption) func(*Params)
}
}

// WithDDAConfig configures the DatadogAgent resource.
func WithDDAConfig(config string) func(*Params) error {
// WithDDAConfig configures the DatadogAgent custom resource.
func WithDDAConfig(config DDAConfig) func(*Params) error {
return func(p *Params) error {
p.DDAConfig = p.DDAConfig + config
p.DDAConfig = config
return nil
}
}
Expand All @@ -66,3 +60,15 @@ func WithFakeIntake(fakeintake *fakeintake.Fakeintake) func(*Params) error {
return nil
}
}

// DDAConfig is the DatadogAgent custom resource configuration.
type DDAConfig struct {
// Name of the DatadogAgent custom resource
Name string `json:"name"`
// YamlFilePath file path to the DatadogAgent custom resource YAML
YamlFilePath string `json:"yamlFilePath,omitempty"`
// YamlConfig is the YAML string of the DatadogAgent custom resource
YamlConfig string `json:"YamlConfig,omitempty"`
// MapConfig is the map representation of the DatadogAgent custom resource
MapConfig map[string]interface{} `json:"MapConfig,omitempty"`
}
Loading
Loading