diff --git a/components/datadog/agent/helm/kubernetes_agent.go b/components/datadog/agent/helm/kubernetes_agent.go index a0140cf15..4943aa411 100644 --- a/components/datadog/agent/helm/kubernetes_agent.go +++ b/components/datadog/agent/helm/kubernetes_agent.go @@ -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" @@ -43,7 +44,7 @@ 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", }) @@ -51,7 +52,7 @@ func NewKubernetesAgent(e config.Env, resourceName string, kubeProvider *kuberne 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", }) @@ -59,7 +60,7 @@ func NewKubernetesAgent(e config.Env, resourceName string, kubeProvider *kuberne 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", }) @@ -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 { diff --git a/components/datadog/agent/kubernetes.go b/components/datadog/agent/kubernetes.go index 3da247593..64b529db2 100644 --- a/components/datadog/agent/kubernetes.go +++ b/components/datadog/agent/kubernetes.go @@ -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" @@ -9,13 +10,13 @@ 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. @@ -23,13 +24,13 @@ 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 { diff --git a/components/datadog/agent/kubernetes_operator.go b/components/datadog/agent/kubernetes_operator.go index 8b666ab0b..a36f6f5a4 100644 --- a/components/datadog/agent/kubernetes_operator.go +++ b/components/datadog/agent/kubernetes_operator.go @@ -1,9 +1,6 @@ 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" @@ -11,18 +8,13 @@ import ( "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 } @@ -33,21 +25,23 @@ 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", }) @@ -55,7 +49,7 @@ func NewDDAWithOperator(e config.Env, resourceName string, kubeProvider *kuberne 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", }) diff --git a/components/datadog/agentwithoperatorparams/params.go b/components/datadog/agentwithoperatorparams/params.go index df0a39ce0..cc0342880 100644 --- a/components/datadog/agentwithoperatorparams/params.go +++ b/components/datadog/agentwithoperatorparams/params.go @@ -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) } diff --git a/components/datadog/apps/dda/datadogagent.go b/components/datadog/apps/dda/datadogagent.go index c83a943e4..f0a2b4581 100644 --- a/components/datadog/apps/dda/datadogagent.go +++ b/components/datadog/apps/dda/datadogagent.go @@ -3,6 +3,7 @@ package dda import ( "encoding/json" "fmt" + "strings" "dario.cat/mergo" "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes" @@ -18,7 +19,7 @@ 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" @@ -26,7 +27,7 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace 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)) @@ -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)) @@ -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)) @@ -70,7 +71,7 @@ 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 @@ -78,26 +79,36 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace 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 { diff --git a/components/datadog/operator/operator.go b/components/datadog/operator/operator.go index 69c90043d..f08bdf195 100644 --- a/components/datadog/operator/operator.go +++ b/components/datadog/operator/operator.go @@ -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" @@ -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 Output 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) } @@ -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, @@ -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 }) } diff --git a/components/datadog/operatorparams/params.go b/components/datadog/operatorparams/params.go index 188fb01b3..8a03d31a4 100644 --- a/components/datadog/operatorparams/params.go +++ b/components/datadog/operatorparams/params.go @@ -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())))) diff --git a/components/datadog/agent/kubernetes_object_ref.go b/components/kubernetes/kubernetes_object_ref.go similarity index 88% rename from components/datadog/agent/kubernetes_object_ref.go rename to components/kubernetes/kubernetes_object_ref.go index 7bdcf8b2e..29d79a1e5 100644 --- a/components/datadog/agent/kubernetes_object_ref.go +++ b/components/kubernetes/kubernetes_object_ref.go @@ -1,4 +1,4 @@ -package agent +package kubernetes import ( "github.com/pulumi/pulumi/sdk/v3/go/pulumi" @@ -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 Output components.JSONImporter Namespace string `json:"namespace"` @@ -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 Output pulumi.ResourceState components.Component