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 #1251

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
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
22 changes: 8 additions & 14 deletions components/datadog/agent/kubernetes_operator.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
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"
)

func NewDDAWithOperator(e config.Env, resourceName string, kubeProvider *kubernetes.Provider, operatorOpts []operatorparams.Option, 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
}
Expand All @@ -33,29 +25,31 @@ func NewDDAWithOperator(e config.Env, resourceName string, kubeProvider *kuberne
return err
}

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

if err != nil {
return err
}

baseName := "dda-linux"
appVersion := ddaRef.AppVersion
apiVersion := ddaRef.Version

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", appVersion, apiVersion.ToStringOutput(), map[string]string{"app": baseName + "-datadog"})

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{
comp.LinuxClusterAgent, err = componentskube.NewKubernetesObjRef(e, baseName+"-clusterAgent", ddaParams.Namespace, "Pod", appVersion, apiVersion, map[string]string{
"app": baseName + "-datadog-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{
comp.LinuxClusterChecks, err = componentskube.NewKubernetesObjRef(e, baseName+"-clusterChecks", ddaParams.Namespace, "Pod", appVersion, apiVersion, map[string]string{
"app": baseName + "-datadog-clusterchecks",
})

Expand Down
4 changes: 1 addition & 3 deletions components/datadog/agentwithoperatorparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ type Params struct {
type Option = func(*Params) error

func NewParams(options ...Option) (*Params, error) {
version := &Params{
Namespace: "datadog",
}
version := &Params{}
return common.ApplyOption(version, options)
}

Expand Down
31 changes: 21 additions & 10 deletions components/datadog/apps/dda/datadogagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dda
import (
"encoding/json"
"fmt"
"strings"

"dario.cat/mergo"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
Expand All @@ -18,15 +19,15 @@ import (
componentskube "github.com/DataDog/test-infra-definitions/components/kubernetes"
)

func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace string, fakeIntake *fakeintake.Fakeintake, kubeletTLSVerify bool, clusterName string, customDda string, opts ...pulumi.ResourceOption) (*componentskube.Workload, error) {
func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace string, fakeIntake *fakeintake.Fakeintake, kubeletTLSVerify bool, clusterName string, customDda string, opts ...pulumi.ResourceOption) (*componentskube.Workload, *componentskube.KubernetesObjectRef, error) {
apiKey := e.AgentAPIKey()
appKey := e.AgentAPPKey()
baseName := "dda-with-operator"
opts = append(opts, pulumi.Provider(kubeProvider), pulumi.Parent(kubeProvider), pulumi.DeletedWith(kubeProvider))

k8sComponent := &componentskube.Workload{}
if err := e.Ctx().RegisterComponentResource("dd:agent-with-operator", "dda", k8sComponent, opts...); err != nil {
return nil, err
return nil, nil, err
}

opts = append(opts, pulumi.Parent(k8sComponent))
Expand All @@ -42,7 +43,7 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace
opts...,
)
if err != nil {
return nil, err
return nil, nil, err
}

opts = append(opts, utils.PulumiDependsOn(ns))
Expand All @@ -59,7 +60,7 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace
},
}, opts...)
if err != nil {
return nil, err
return nil, nil, err
}
opts = append(opts, utils.PulumiDependsOn(secret))

Expand All @@ -70,34 +71,44 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace
ddaConfig, err = mergeYamlToConfig(ddaConfig, customDda)

if err != nil {
return nil, err
return nil, nil, err
}

// Image pull secrets need to be configured after custom DDA config merge because pulumi.StringOutput cannot be marshalled to JSON
var imagePullSecret *corev1.Secret
if e.ImagePullRegistry() != "" {
imagePullSecret, err = utils.NewImagePullSecret(e, namespace, opts...)
if err != nil {
return nil, err
return nil, nil, err
}
opts = append(opts, utils.PulumiDependsOn(imagePullSecret))
configureImagePullSecret(ddaConfig, imagePullSecret)
}

ddaName := "datadog-agent"
if e.PipelineID() != "" {
ddaName = strings.Join([]string{ddaName, e.PipelineID()}, "-")
}

_, err = apiextensions.NewCustomResource(e.Ctx(), "datadog-agent", &apiextensions.CustomResourceArgs{
ApiVersion: pulumi.String("datadoghq.com/v2alpha1"),
Kind: pulumi.String("DatadogAgent"),
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("datadog"),
Namespace: pulumi.String("datadog"),
Name: pulumi.String(ddaName),
Namespace: pulumi.String(namespace),
},
OtherFields: ddaConfig,
}, opts...)
if err != nil {
return nil, err
return nil, nil, err
}

ddaRef, err := componentskube.NewKubernetesObjRef(e, baseName, namespace, "DatadogAgent", pulumi.String("").ToStringOutput(), pulumi.String("datadoghq.com/v2alpha1").ToStringOutput(), map[string]string{"app": baseName})
if err != nil {
return nil, nil, err
}

return k8sComponent, nil
return k8sComponent, ddaRef, nil
}

func buildDDAConfig(baseName string, clusterName string, kubeletTLSVerify bool) kubernetes.UntypedArgs {
Expand Down
15 changes: 12 additions & 3 deletions components/datadog/operator/operator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package operator

import (
compkubernetes "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 All @@ -10,17 +11,19 @@ import (
)

// OperatorOutput is used to import the Operator component
type Output struct {
type OperatorOutput struct { // nolint:revive, We want to keep the name as <Component>Output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the lint error?

components.JSONImporter
Operator compkubernetes.KubernetesObjectRef `json:"operator"`
}

// Operator represents an Operator installation
type Operator struct {
pulumi.ResourceState
components.Component
Operator *compkubernetes.KubernetesObjectRef `json:"operator"`
}

func (h *Operator) Export(ctx *pulumi.Context, out *Output) error {
func (h *Operator) Export(ctx *pulumi.Context, out *OperatorOutput) error {
return components.Export(ctx, h, out)
}

Expand All @@ -32,7 +35,7 @@ func NewOperator(e config.Env, resourceName string, kubeProvider *kubernetes.Pro
}
pulumiResourceOptions := append(params.PulumiResourceOptions, pulumi.Parent(comp))

_, err = NewHelmInstallation(e, HelmInstallationArgs{
release, err := NewHelmInstallation(e, HelmInstallationArgs{
KubeProvider: kubeProvider,
Namespace: params.Namespace,
ValuesYAML: params.HelmValues,
Expand All @@ -42,6 +45,12 @@ func NewOperator(e config.Env, resourceName string, kubeProvider *kubernetes.Pro
return err
}

comp.Operator, err = compkubernetes.NewKubernetesObjRef(e, "datadog-operator", params.Namespace, "Pod", release.LinuxHelmReleaseStatus.AppVersion().Elem(), release.LinuxHelmReleaseStatus.Version().Elem(), map[string]string{"app": "datadog-operator"})

if err != nil {
return err
}

return nil
})
}
5 changes: 1 addition & 4 deletions components/datadog/operatorparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ type Params struct {
type Option = func(*Params) error

func NewParams(e config.Env, options ...Option) (*Params, error) {
version := &Params{
Namespace: "datadog",
OperatorFullImagePath: "gcr.io/datadoghq/operator:latest",
}
version := &Params{}

if e.PipelineID() != "" && e.CommitSHA() != "" {
options = append(options, WithOperatorFullImagePath(utils.BuildDockerImagePath(fmt.Sprintf("%s/operator", e.InternalRegistry()), fmt.Sprintf("%s-%s", e.PipelineID(), e.CommitSHA()))))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package agent
package kubernetes

import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
Expand All @@ -7,7 +7,7 @@ import (
"github.com/DataDog/test-infra-definitions/components"
)

type KubernetesObjRefOutput struct {
type KubernetesObjRefOutput struct { // nolint:revive, We want to keep the name as <Component>Output
components.JSONImporter

Namespace string `json:"namespace"`
Expand All @@ -18,7 +18,7 @@ type KubernetesObjRefOutput struct {
LabelSelectors map[string]string `json:"labelSelectors"`
}

type KubernetesObjectRef struct {
type KubernetesObjectRef struct { // nolint:revive, We want to keep the name as <Component>Output
pulumi.ResourceState
components.Component

Expand Down