From 6f3a79fffe035af86ae1521c74bf0cf599f39c67 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Santos <91925154+gabedos@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:21:18 -0500 Subject: [PATCH 1/8] [CONTP-519] Support k8s admin events in operator (#1575) * Support k8s admin events in operator --- .../v2alpha1/datadogagent_default.go | 9 ++++ .../v2alpha1/datadogagent_default_test.go | 42 +++++++++++++++++ api/datadoghq/v2alpha1/datadogagent_types.go | 11 +++++ .../v2alpha1/zz_generated.deepcopy.go | 25 +++++++++++ .../bases/v1/datadoghq.com_datadogagents.yaml | 18 ++++++++ .../datadoghq.com_datadogagents_v2alpha1.json | 22 +++++++++ docs/configuration.v2alpha1.md | 1 + .../feature/admissioncontroller/envvar.go | 45 ++++++++++--------- .../feature/admissioncontroller/feature.go | 17 +++++++ 9 files changed, 168 insertions(+), 22 deletions(-) diff --git a/api/datadoghq/v2alpha1/datadogagent_default.go b/api/datadoghq/v2alpha1/datadogagent_default.go index 5caa18d50..978c22e03 100644 --- a/api/datadoghq/v2alpha1/datadogagent_default.go +++ b/api/datadoghq/v2alpha1/datadogagent_default.go @@ -79,6 +79,9 @@ const ( defaultAdmissionControllerMutationEnabled bool = true defaultAdmissionControllerMutateUnlabelled bool = false defaultAdmissionServiceName string = "datadog-admission-controller" + + defaultAdmissionControllerKubernetesAdmissionEventsEnabled bool = false + // DefaultAdmissionControllerCWSInstrumentationEnabled default CWS Instrumentation enabled value DefaultAdmissionControllerCWSInstrumentationEnabled bool = false // DefaultAdmissionControllerCWSInstrumentationMode default CWS Instrumentation mode @@ -495,6 +498,12 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { apiutils.DefaultBooleanIfUnset(&agentSidecarInjection.ClusterAgentCommunicationEnabled, defaultAdmissionControllerAgentSidecarClusterAgentEnabled) } + // K8s Admission Events in AdmissonController Feature + if ddaSpec.Features.AdmissionController.KubernetesAdmissionEvents == nil { + ddaSpec.Features.AdmissionController.KubernetesAdmissionEvents = &KubernetesAdmissionEventsConfig{} + } + apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.AdmissionController.KubernetesAdmissionEvents.Enabled, defaultAdmissionControllerKubernetesAdmissionEventsEnabled) + // CWS Instrumentation in AdmissionController Feature if ddaSpec.Features.AdmissionController.CWSInstrumentation == nil { ddaSpec.Features.AdmissionController.CWSInstrumentation = &CWSInstrumentationConfig{} diff --git a/api/datadoghq/v2alpha1/datadogagent_default_test.go b/api/datadoghq/v2alpha1/datadogagent_default_test.go index 143da79b4..fc8a80ef3 100644 --- a/api/datadoghq/v2alpha1/datadogagent_default_test.go +++ b/api/datadoghq/v2alpha1/datadogagent_default_test.go @@ -288,6 +288,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -479,6 +482,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(valueFalse), + }, }, ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), @@ -624,6 +630,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -765,6 +774,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -901,6 +913,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -1039,6 +1054,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -1182,6 +1200,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -1321,6 +1342,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -1457,6 +1481,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -1483,6 +1510,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(true), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, }, }, @@ -1605,6 +1635,9 @@ func Test_defaultFeatures(t *testing.T) { Enabled: apiutils.NewBoolPointer(valueTrue), Mode: apiutils.NewStringPointer(DefaultAdmissionControllerCWSInstrumentationMode), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -1742,6 +1775,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -1900,6 +1936,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), @@ -2049,6 +2088,9 @@ func Test_defaultFeatures(t *testing.T) { CWSInstrumentation: &CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, }, PrometheusScrape: &PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), diff --git a/api/datadoghq/v2alpha1/datadogagent_types.go b/api/datadoghq/v2alpha1/datadogagent_types.go index 1ca103536..f92c17c35 100644 --- a/api/datadoghq/v2alpha1/datadogagent_types.go +++ b/api/datadoghq/v2alpha1/datadogagent_types.go @@ -729,6 +729,10 @@ type AdmissionControllerFeatureConfig struct { // +optional Registry *string `json:"registry,omitempty"` + // KubernetesAdmissionEvents holds the Kubernetes Admission Events configuration. + // +optional + KubernetesAdmissionEvents *KubernetesAdmissionEventsConfig `json:"kubernetesAdmissionEvents,omitempty"` + // CWSInstrumentation holds the CWS Instrumentation endpoint configuration // +optional CWSInstrumentation *CWSInstrumentationConfig `json:"cwsInstrumentation,omitempty"` @@ -809,6 +813,13 @@ type Profile struct { ResourceRequirements *corev1.ResourceRequirements `json:"resources,omitempty"` } +type KubernetesAdmissionEventsConfig struct { + // Enable the Kubernetes Admission Events feature. + // Default: false + // +optional + Enabled *bool `json:"enabled,omitempty"` +} + // CWSInstrumentationConfig contains the configuration of the CWS Instrumentation admission controller endpoint. type CWSInstrumentationConfig struct { // Enable the CWS Instrumentation admission controller endpoint. diff --git a/api/datadoghq/v2alpha1/zz_generated.deepcopy.go b/api/datadoghq/v2alpha1/zz_generated.deepcopy.go index 184b291a0..f5871d649 100644 --- a/api/datadoghq/v2alpha1/zz_generated.deepcopy.go +++ b/api/datadoghq/v2alpha1/zz_generated.deepcopy.go @@ -194,6 +194,11 @@ func (in *AdmissionControllerFeatureConfig) DeepCopyInto(out *AdmissionControlle *out = new(string) **out = **in } + if in.KubernetesAdmissionEvents != nil { + in, out := &in.KubernetesAdmissionEvents, &out.KubernetesAdmissionEvents + *out = new(KubernetesAdmissionEventsConfig) + (*in).DeepCopyInto(*out) + } if in.CWSInstrumentation != nil { in, out := &in.CWSInstrumentation, &out.CWSInstrumentation *out = new(CWSInstrumentationConfig) @@ -1810,6 +1815,26 @@ func (in *KubeletConfig) DeepCopy() *KubeletConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KubernetesAdmissionEventsConfig) DeepCopyInto(out *KubernetesAdmissionEventsConfig) { + *out = *in + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubernetesAdmissionEventsConfig. +func (in *KubernetesAdmissionEventsConfig) DeepCopy() *KubernetesAdmissionEventsConfig { + if in == nil { + return nil + } + out := new(KubernetesAdmissionEventsConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LanguageDetectionConfig) DeepCopyInto(out *LanguageDetectionConfig) { *out = *in diff --git a/config/crd/bases/v1/datadoghq.com_datadogagents.yaml b/config/crd/bases/v1/datadoghq.com_datadogagents.yaml index f38cf8613..09beaf1d4 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogagents.yaml +++ b/config/crd/bases/v1/datadoghq.com_datadogagents.yaml @@ -435,6 +435,15 @@ spec: failurePolicy: description: FailurePolicy determines how unrecognized and timeout errors are handled. type: string + kubernetesAdmissionEvents: + description: KubernetesAdmissionEvents holds the Kubernetes Admission Events configuration. + properties: + enabled: + description: |- + Enable the Kubernetes Admission Events feature. + Default: false + type: boolean + type: object mutateUnlabelled: description: |- MutateUnlabelled enables config injection without the need of pod label 'admission.datadoghq.com/enabled="true"'. @@ -7170,6 +7179,15 @@ spec: failurePolicy: description: FailurePolicy determines how unrecognized and timeout errors are handled. type: string + kubernetesAdmissionEvents: + description: KubernetesAdmissionEvents holds the Kubernetes Admission Events configuration. + properties: + enabled: + description: |- + Enable the Kubernetes Admission Events feature. + Default: false + type: boolean + type: object mutateUnlabelled: description: |- MutateUnlabelled enables config injection without the need of pod label 'admission.datadoghq.com/enabled="true"'. diff --git a/config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json b/config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json index 44de06e17..2133efdcc 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json +++ b/config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json @@ -430,6 +430,17 @@ "description": "FailurePolicy determines how unrecognized and timeout errors are handled.", "type": "string" }, + "kubernetesAdmissionEvents": { + "additionalProperties": false, + "description": "KubernetesAdmissionEvents holds the Kubernetes Admission Events configuration.", + "properties": { + "enabled": { + "description": "Enable the Kubernetes Admission Events feature.\nDefault: false", + "type": "boolean" + } + }, + "type": "object" + }, "mutateUnlabelled": { "description": "MutateUnlabelled enables config injection without the need of pod label 'admission.datadoghq.com/enabled=\"true\"'.\nDefault: false", "type": "boolean" @@ -7103,6 +7114,17 @@ "description": "FailurePolicy determines how unrecognized and timeout errors are handled.", "type": "string" }, + "kubernetesAdmissionEvents": { + "additionalProperties": false, + "description": "KubernetesAdmissionEvents holds the Kubernetes Admission Events configuration.", + "properties": { + "enabled": { + "description": "Enable the Kubernetes Admission Events feature.\nDefault: false", + "type": "boolean" + } + }, + "type": "object" + }, "mutateUnlabelled": { "description": "MutateUnlabelled enables config injection without the need of pod label 'admission.datadoghq.com/enabled=\"true\"'.\nDefault: false", "type": "boolean" diff --git a/docs/configuration.v2alpha1.md b/docs/configuration.v2alpha1.md index 5e5e82982..7810746be 100644 --- a/docs/configuration.v2alpha1.md +++ b/docs/configuration.v2alpha1.md @@ -49,6 +49,7 @@ spec: | features.admissionController.cwsInstrumentation.mode | Defines the behavior of the CWS Instrumentation endpoint, and can be either "init_container" or "remote_copy". Default: "remote_copy" | | features.admissionController.enabled | Enables the Admission Controller. Default: true | | features.admissionController.failurePolicy | FailurePolicy determines how unrecognized and timeout errors are handled. | +| features.admissionController.kubernetesAdmissionEvents.enabled | Enable the Kubernetes Admission Events feature. Default: false | | features.admissionController.mutateUnlabelled | MutateUnlabelled enables config injection without the need of pod label 'admission.datadoghq.com/enabled="true"'. Default: false | | features.admissionController.mutation.enabled | Enables the Admission Controller mutation webhook. Default: true | | features.admissionController.registry | Defines an image registry for the admission controller. | diff --git a/internal/controller/datadogagent/feature/admissioncontroller/envvar.go b/internal/controller/datadogagent/feature/admissioncontroller/envvar.go index 69739f5dd..da94b900b 100644 --- a/internal/controller/datadogagent/feature/admissioncontroller/envvar.go +++ b/internal/controller/datadogagent/feature/admissioncontroller/envvar.go @@ -6,26 +6,27 @@ package admissioncontroller const ( - DDAdmissionControllerAgentSidecarEnabled = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_ENABLED" - DDAdmissionControllerAgentSidecarClusterAgentEnabled = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_CLUSTER_AGENT_ENABLED" - DDAdmissionControllerAgentSidecarProvider = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_PROVIDER" - DDAdmissionControllerAgentSidecarRegistry = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_CONTAINER_REGISTRY" - DDAdmissionControllerAgentSidecarImageName = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_IMAGE_NAME" - DDAdmissionControllerAgentSidecarImageTag = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_IMAGE_TAG" - DDAdmissionControllerAgentSidecarSelectors = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_SELECTORS" - DDAdmissionControllerAgentSidecarProfiles = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_PROFILES" - DDAdmissionControllerEnabled = "DD_ADMISSION_CONTROLLER_ENABLED" - DDAdmissionControllerValidationEnabled = "DD_ADMISSION_CONTROLLER_VALIDATION_ENABLED" - DDAdmissionControllerMutationEnabled = "DD_ADMISSION_CONTROLLER_MUTATION_ENABLED" - DDAdmissionControllerInjectConfig = "DD_ADMISSION_CONTROLLER_INJECT_CONFIG_ENABLED" - DDAdmissionControllerInjectConfigMode = "DD_ADMISSION_CONTROLLER_INJECT_CONFIG_MODE" - DDAdmissionControllerInjectTags = "DD_ADMISSION_CONTROLLER_INJECT_TAGS_ENABLED" - DDAdmissionControllerLocalServiceName = "DD_ADMISSION_CONTROLLER_INJECT_CONFIG_LOCAL_SERVICE_NAME" - DDAdmissionControllerMutateUnlabelled = "DD_ADMISSION_CONTROLLER_MUTATE_UNLABELLED" - DDAdmissionControllerServiceName = "DD_ADMISSION_CONTROLLER_SERVICE_NAME" - DDAdmissionControllerFailurePolicy = "DD_ADMISSION_CONTROLLER_FAILURE_POLICY" - DDAdmissionControllerWebhookName = "DD_ADMISSION_CONTROLLER_WEBHOOK_NAME" - DDAdmissionControllerRegistryName = "DD_ADMISSION_CONTROLLER_CONTAINER_REGISTRY" - DDAdmissionControllerCWSInstrumentationEnabled = "DD_ADMISSION_CONTROLLER_CWS_INSTRUMENTATION_ENABLED" - DDAdmissionControllerCWSInstrumentationMode = "DD_ADMISSION_CONTROLLER_CWS_INSTRUMENTATION_MODE" + DDAdmissionControllerAgentSidecarEnabled = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_ENABLED" + DDAdmissionControllerAgentSidecarClusterAgentEnabled = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_CLUSTER_AGENT_ENABLED" + DDAdmissionControllerAgentSidecarProvider = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_PROVIDER" + DDAdmissionControllerAgentSidecarRegistry = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_CONTAINER_REGISTRY" + DDAdmissionControllerAgentSidecarImageName = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_IMAGE_NAME" + DDAdmissionControllerAgentSidecarImageTag = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_IMAGE_TAG" + DDAdmissionControllerAgentSidecarSelectors = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_SELECTORS" + DDAdmissionControllerAgentSidecarProfiles = "DD_ADMISSION_CONTROLLER_AGENT_SIDECAR_PROFILES" + DDAdmissionControllerEnabled = "DD_ADMISSION_CONTROLLER_ENABLED" + DDAdmissionControllerValidationEnabled = "DD_ADMISSION_CONTROLLER_VALIDATION_ENABLED" + DDAdmissionControllerMutationEnabled = "DD_ADMISSION_CONTROLLER_MUTATION_ENABLED" + DDAdmissionControllerInjectConfig = "DD_ADMISSION_CONTROLLER_INJECT_CONFIG_ENABLED" + DDAdmissionControllerInjectConfigMode = "DD_ADMISSION_CONTROLLER_INJECT_CONFIG_MODE" + DDAdmissionControllerInjectTags = "DD_ADMISSION_CONTROLLER_INJECT_TAGS_ENABLED" + DDAdmissionControllerLocalServiceName = "DD_ADMISSION_CONTROLLER_INJECT_CONFIG_LOCAL_SERVICE_NAME" + DDAdmissionControllerMutateUnlabelled = "DD_ADMISSION_CONTROLLER_MUTATE_UNLABELLED" + DDAdmissionControllerServiceName = "DD_ADMISSION_CONTROLLER_SERVICE_NAME" + DDAdmissionControllerFailurePolicy = "DD_ADMISSION_CONTROLLER_FAILURE_POLICY" + DDAdmissionControllerWebhookName = "DD_ADMISSION_CONTROLLER_WEBHOOK_NAME" + DDAdmissionControllerRegistryName = "DD_ADMISSION_CONTROLLER_CONTAINER_REGISTRY" + DDAdmissionControllerCWSInstrumentationEnabled = "DD_ADMISSION_CONTROLLER_CWS_INSTRUMENTATION_ENABLED" + DDAdmissionControllerCWSInstrumentationMode = "DD_ADMISSION_CONTROLLER_CWS_INSTRUMENTATION_MODE" + DDAdmissionControllerKubernetesAdmissionEventsEnabled = "DD_ADMISSION_CONTROLLER_KUBERNETES_ADMISSION_EVENTS_ENABLED" ) diff --git a/internal/controller/datadogagent/feature/admissioncontroller/feature.go b/internal/controller/datadogagent/feature/admissioncontroller/feature.go index 62ddc2bd4..f2720a2fe 100644 --- a/internal/controller/datadogagent/feature/admissioncontroller/feature.go +++ b/internal/controller/datadogagent/feature/admissioncontroller/feature.go @@ -48,6 +48,8 @@ type admissionControllerFeature struct { cwsInstrumentationEnabled bool cwsInstrumentationMode string + + kubernetesAdmissionEvents *KubernetesAdmissionEventConfig } type ValidationConfig struct { @@ -69,6 +71,10 @@ type AgentSidecarInjectionConfig struct { profiles []*v2alpha1.Profile } +type KubernetesAdmissionEventConfig struct { + enabled bool +} + func buildAdmissionControllerFeature(options *feature.Options) feature.Feature { return &admissionControllerFeature{} } @@ -140,6 +146,10 @@ func (f *admissionControllerFeature) Configure(dda *v2alpha1.DatadogAgent) (reqC f.cwsInstrumentationMode = apiutils.StringValue(ac.CWSInstrumentation.Mode) } + if ac.KubernetesAdmissionEvents != nil && apiutils.BoolValue(ac.KubernetesAdmissionEvents.Enabled) { + f.kubernetesAdmissionEvents = &KubernetesAdmissionEventConfig{enabled: true} + } + _, f.networkPolicy = v2alpha1.IsNetworkPolicyEnabled(dda) sidecarConfig := dda.Spec.Features.AdmissionController.AgentSidecarInjection @@ -357,6 +367,13 @@ func (f *admissionControllerFeature) ManageClusterAgent(managers feature.PodTemp }) } + if f.kubernetesAdmissionEvents != nil { + managers.EnvVar().AddEnvVarToContainer(apicommon.ClusterAgentContainerName, &corev1.EnvVar{ + Name: DDAdmissionControllerKubernetesAdmissionEventsEnabled, + Value: apiutils.BoolToString(&f.kubernetesAdmissionEvents.enabled), + }) + } + if f.agentCommunicationMode != "" { managers.EnvVar().AddEnvVarToContainer(apicommon.ClusterAgentContainerName, &corev1.EnvVar{ Name: DDAdmissionControllerInjectConfigMode, From c17ec1de2615638a9d7c3d15b31fdfd1d70d35d2 Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Thu, 19 Dec 2024 10:32:17 -0500 Subject: [PATCH 2/8] Revert "[cleanup] remove unused v1beta1 version of PDB (#1468)" (#1580) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "[cleanup] remove unused v1beta1 version of PDB (#1468)" This reverts commit 614b10f7c754cd50d1d95f4a0e9e18b975204a9c. * use go convention * support v1beta1 for pdbs * go convetion * Revert "support v1beta1 for pdbs" This reverts commit 13b2cab2b2596c6f690d468f0803af29f48f76c3. * Reapply "support v1beta1 for pdbs" This reverts commit 59715f165a97a2e45c10d3ccf5ea53f1848db4c5. --------- Co-authored-by: Timothée Bavelier Co-authored-by: Timothée Bavelier <97530782+tbavelier@users.noreply.github.com> --- .../component/clusteragent/default_test.go | 3 +- .../component/clusteragent/utils.go | 21 ++- .../component/clusterchecksrunner/default.go | 21 ++- .../clusterchecksrunner/default_test.go | 3 +- .../datadogagent/override/dependencies.go | 6 +- .../datadogagent/testutils/client_utils.go | 2 +- .../controller/datadogagent_controller.go | 4 +- pkg/equality/equality.go | 8 + pkg/kubernetes/objects.go | 3 +- pkg/kubernetes/objectslist.go | 3 +- pkg/kubernetes/platforminfo.go | 24 +++ pkg/kubernetes/platforminfo_test.go | 162 ++++++++++++++++++ 12 files changed, 243 insertions(+), 17 deletions(-) diff --git a/internal/controller/datadogagent/component/clusteragent/default_test.go b/internal/controller/datadogagent/component/clusteragent/default_test.go index 567fb7d09..cffbda848 100644 --- a/internal/controller/datadogagent/component/clusteragent/default_test.go +++ b/internal/controller/datadogagent/component/clusteragent/default_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" + policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -46,7 +47,7 @@ func Test_getPodDisruptionBudget(t *testing.T) { Namespace: "some-namespace", }, } - testpdb := GetClusterAgentPodDisruptionBudget(&dda) + testpdb := GetClusterAgentPodDisruptionBudget(&dda, false).(*policyv1.PodDisruptionBudget) assert.Equal(t, "my-datadog-agent-cluster-agent-pdb", testpdb.Name) assert.Equal(t, intstr.FromInt(pdbMinAvailableInstances), *testpdb.Spec.MinAvailable) assert.Nil(t, testpdb.Spec.MaxUnavailable) diff --git a/internal/controller/datadogagent/component/clusteragent/utils.go b/internal/controller/datadogagent/component/clusteragent/utils.go index 3babcd74b..1f3db4d3b 100644 --- a/internal/controller/datadogagent/component/clusteragent/utils.go +++ b/internal/controller/datadogagent/component/clusteragent/utils.go @@ -13,9 +13,11 @@ import ( "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" + "sigs.k8s.io/controller-runtime/pkg/client" corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" + policyv1beta1 "k8s.io/api/policy/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/version" @@ -58,13 +60,27 @@ func GetClusterAgentService(dda metav1.Object) *corev1.Service { return service } -func GetClusterAgentPodDisruptionBudget(dda metav1.Object) *policyv1.PodDisruptionBudget { +func GetClusterAgentPodDisruptionBudget(dda metav1.Object, useV1BetaPDB bool) client.Object { // labels and annotations minAvailableStr := intstr.FromInt(pdbMinAvailableInstances) matchLabels := map[string]string{ apicommon.AgentDeploymentNameLabelKey: dda.GetName(), apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterAgentResourceSuffix} - pdb := &policyv1.PodDisruptionBudget{ + if useV1BetaPDB { + return &policyv1beta1.PodDisruptionBudget{ + ObjectMeta: metav1.ObjectMeta{ + Name: GetClusterAgentPodDisruptionBudgetName(dda), + Namespace: dda.GetNamespace(), + }, + Spec: policyv1beta1.PodDisruptionBudgetSpec{ + MinAvailable: &minAvailableStr, + Selector: &metav1.LabelSelector{ + MatchLabels: matchLabels, + }, + }, + } + } + return &policyv1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ Name: GetClusterAgentPodDisruptionBudgetName(dda), Namespace: dda.GetNamespace(), @@ -76,7 +92,6 @@ func GetClusterAgentPodDisruptionBudget(dda metav1.Object) *policyv1.PodDisrupti }, }, } - return pdb } // GetMetricsServerServiceName returns the external metrics provider service name diff --git a/internal/controller/datadogagent/component/clusterchecksrunner/default.go b/internal/controller/datadogagent/component/clusterchecksrunner/default.go index bca4eb862..13a85b1e2 100644 --- a/internal/controller/datadogagent/component/clusterchecksrunner/default.go +++ b/internal/controller/datadogagent/component/clusterchecksrunner/default.go @@ -12,8 +12,10 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" + policyv1beta1 "k8s.io/api/policy/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "sigs.k8s.io/controller-runtime/pkg/client" apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" @@ -92,12 +94,26 @@ func GetClusterChecksRunnerPodDisruptionBudgetName(dda metav1.Object) string { return fmt.Sprintf("%s-%s-pdb", dda.GetName(), v2alpha1.DefaultClusterChecksRunnerResourceSuffix) } -func GetClusterChecksRunnerPodDisruptionBudget(dda metav1.Object) *policyv1.PodDisruptionBudget { +func GetClusterChecksRunnerPodDisruptionBudget(dda metav1.Object, useV1BetaPDB bool) client.Object { maxUnavailableStr := intstr.FromInt(pdbMaxUnavailableInstances) matchLabels := map[string]string{ apicommon.AgentDeploymentNameLabelKey: dda.GetName(), apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterChecksRunnerResourceSuffix} - pdb := &policyv1.PodDisruptionBudget{ + if useV1BetaPDB { + return &policyv1beta1.PodDisruptionBudget{ + ObjectMeta: metav1.ObjectMeta{ + Name: GetClusterChecksRunnerPodDisruptionBudgetName(dda), + Namespace: dda.GetNamespace(), + }, + Spec: policyv1beta1.PodDisruptionBudgetSpec{ + MaxUnavailable: &maxUnavailableStr, + Selector: &metav1.LabelSelector{ + MatchLabels: matchLabels, + }, + }, + } + } + return &policyv1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ Name: GetClusterChecksRunnerPodDisruptionBudgetName(dda), Namespace: dda.GetNamespace(), @@ -109,7 +125,6 @@ func GetClusterChecksRunnerPodDisruptionBudget(dda metav1.Object) *policyv1.PodD }, }, } - return pdb } // getDefaultServiceAccountName return the default Cluster-Agent ServiceAccountName diff --git a/internal/controller/datadogagent/component/clusterchecksrunner/default_test.go b/internal/controller/datadogagent/component/clusterchecksrunner/default_test.go index eb1177de9..0b43ec1cc 100644 --- a/internal/controller/datadogagent/component/clusterchecksrunner/default_test.go +++ b/internal/controller/datadogagent/component/clusterchecksrunner/default_test.go @@ -10,6 +10,7 @@ import ( "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" "github.com/stretchr/testify/assert" + policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -32,7 +33,7 @@ func Test_getPodDisruptionBudget(t *testing.T) { Namespace: "some-namespace", }, } - testpdb := GetClusterChecksRunnerPodDisruptionBudget(&dda) + testpdb := GetClusterChecksRunnerPodDisruptionBudget(&dda, false).(*policyv1.PodDisruptionBudget) assert.Equal(t, "my-datadog-agent-cluster-checks-runner-pdb", testpdb.Name) assert.Equal(t, intstr.FromInt(pdbMaxUnavailableInstances), *testpdb.Spec.MaxUnavailable) assert.Nil(t, testpdb.Spec.MinAvailable) diff --git a/internal/controller/datadogagent/override/dependencies.go b/internal/controller/datadogagent/override/dependencies.go index 18006de15..dc284b96a 100644 --- a/internal/controller/datadogagent/override/dependencies.go +++ b/internal/controller/datadogagent/override/dependencies.go @@ -53,15 +53,17 @@ func Dependencies(logger logr.Logger, manager feature.ResourceManagers, dda *v2a func overridePodDisruptionBudget(logger logr.Logger, manager feature.ResourceManagers, dda *v2alpha1.DatadogAgent, createPdb *bool, component v2alpha1.ComponentName) (errs []error) { if createPdb != nil && *createPdb { + platformInfo := manager.Store().GetPlatformInfo() + useV1BetaPDB := platformInfo.UseV1Beta1PDB() if component == v2alpha1.ClusterAgentComponentName { - pdb := componentdca.GetClusterAgentPodDisruptionBudget(dda) + pdb := componentdca.GetClusterAgentPodDisruptionBudget(dda, useV1BetaPDB) if err := manager.Store().AddOrUpdate(kubernetes.PodDisruptionBudgetsKind, pdb); err != nil { errs = append(errs, err) } } else if component == v2alpha1.ClusterChecksRunnerComponentName && (dda.Spec.Features.ClusterChecks.UseClusterChecksRunners == nil || *dda.Spec.Features.ClusterChecks.UseClusterChecksRunners) { - pdb := componentccr.GetClusterChecksRunnerPodDisruptionBudget(dda) + pdb := componentccr.GetClusterChecksRunnerPodDisruptionBudget(dda, useV1BetaPDB) if err := manager.Store().AddOrUpdate(kubernetes.PodDisruptionBudgetsKind, pdb); err != nil { errs = append(errs, err) } diff --git a/internal/controller/datadogagent/testutils/client_utils.go b/internal/controller/datadogagent/testutils/client_utils.go index 86cd4cb0b..f6b94794c 100644 --- a/internal/controller/datadogagent/testutils/client_utils.go +++ b/internal/controller/datadogagent/testutils/client_utils.go @@ -12,7 +12,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" - policyv1 "k8s.io/api/policy/v1" + policyv1 "k8s.io/api/policy/v1beta1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/scheme" diff --git a/internal/controller/datadogagent_controller.go b/internal/controller/datadogagent_controller.go index 2e80cdf20..031ff6c30 100644 --- a/internal/controller/datadogagent_controller.go +++ b/internal/controller/datadogagent_controller.go @@ -13,7 +13,6 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" - policyv1 "k8s.io/api/policy/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -195,7 +194,8 @@ func (r *DatadogAgentReconciler) SetupWithManager(mgr ctrl.Manager, metricForwar Owns(&rbacv1.Role{}). Owns(&rbacv1.RoleBinding{}). Owns(&corev1.ServiceAccount{}). - Owns(&policyv1.PodDisruptionBudget{}). + // We let PlatformInfo supply PDB object based on the current API version + Owns(r.PlatformInfo.CreatePDBObject()). Owns(&networkingv1.NetworkPolicy{}) if r.Options.DatadogAgentProfileEnabled { diff --git a/pkg/equality/equality.go b/pkg/equality/equality.go index aa4fce456..fe50d6a56 100644 --- a/pkg/equality/equality.go +++ b/pkg/equality/equality.go @@ -10,6 +10,7 @@ import ( corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" policyv1 "k8s.io/api/policy/v1" + policyv1beta1 "k8s.io/api/policy/v1beta1" rbacv1 "k8s.io/api/rbac/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -181,9 +182,16 @@ func IsEqualServiceAccounts(objA, objB client.Object) bool { func IsEqualPodDisruptionBudgets(objA, objB client.Object) bool { a, okA := objA.(*policyv1.PodDisruptionBudget) b, okB := objB.(*policyv1.PodDisruptionBudget) + if okA && okB && a != nil && b != nil { return apiequality.Semantic.DeepEqual(a.Spec, b.Spec) } + ax, okA := objA.(*policyv1beta1.PodDisruptionBudget) + bx, okB := objB.(*policyv1beta1.PodDisruptionBudget) + if okA && okB && ax != nil && bx != nil { + return apiequality.Semantic.DeepEqual(ax.Spec, bx.Spec) + } + return false } diff --git a/pkg/kubernetes/objects.go b/pkg/kubernetes/objects.go index d4d356f40..7a8628055 100644 --- a/pkg/kubernetes/objects.go +++ b/pkg/kubernetes/objects.go @@ -9,7 +9,6 @@ import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" - policyv1 "k8s.io/api/policy/v1" rbacv1 "k8s.io/api/rbac/v1" apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -43,7 +42,7 @@ func ObjectFromKind(kind ObjectKind, platformInfo PlatformInfo) client.Object { case ServiceAccountsKind: return &corev1.ServiceAccount{} case PodDisruptionBudgetsKind: - return &policyv1.PodDisruptionBudget{} + return platformInfo.CreatePDBObject() case NetworkPoliciesKind: return &networkingv1.NetworkPolicy{} case CiliumNetworkPoliciesKind: diff --git a/pkg/kubernetes/objectslist.go b/pkg/kubernetes/objectslist.go index 39a638bfa..13deb20ea 100644 --- a/pkg/kubernetes/objectslist.go +++ b/pkg/kubernetes/objectslist.go @@ -9,7 +9,6 @@ import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" - policyv1 "k8s.io/api/policy/v1" rbacv1 "k8s.io/api/rbac/v1" apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -43,7 +42,7 @@ func ObjectListFromKind(kind ObjectKind, platformInfo PlatformInfo) client.Objec case ServiceAccountsKind: return &corev1.ServiceAccountList{} case PodDisruptionBudgetsKind: - return &policyv1.PodDisruptionBudgetList{} + return platformInfo.CreatePDBObjectList() case NetworkPoliciesKind: return &networkingv1.NetworkPolicyList{} case CiliumNetworkPoliciesKind: diff --git a/pkg/kubernetes/platforminfo.go b/pkg/kubernetes/platforminfo.go index 74f10f6fc..c66c120d4 100644 --- a/pkg/kubernetes/platforminfo.go +++ b/pkg/kubernetes/platforminfo.go @@ -1,8 +1,11 @@ package kubernetes import ( + policyv1 "k8s.io/api/policy/v1" + policyv1beta1 "k8s.io/api/policy/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/version" + "sigs.k8s.io/controller-runtime/pkg/client" ) type PlatformInfo struct { @@ -58,6 +61,27 @@ func NewPlatformInfoFromVersionMaps(versionInfo *version.Info, apiPreferredVersi } } +func (platformInfo *PlatformInfo) UseV1Beta1PDB() bool { + preferredVersion := platformInfo.apiPreferredVersions["PodDisruptionBudget"] + + // If policy isn't v1beta1 version, we default to v1. + return preferredVersion == "policy/v1beta1" +} + +func (platformInfo *PlatformInfo) CreatePDBObject() client.Object { + if platformInfo.UseV1Beta1PDB() { + return &policyv1beta1.PodDisruptionBudget{} + } + return &policyv1.PodDisruptionBudget{} +} + +func (platformInfo *PlatformInfo) CreatePDBObjectList() client.ObjectList { + if platformInfo.UseV1Beta1PDB() { + return &policyv1beta1.PodDisruptionBudgetList{} + } + return &policyv1.PodDisruptionBudgetList{} +} + func (platformInfo *PlatformInfo) GetAgentResourcesKind(withCiliumResources bool) []ObjectKind { return getResourcesKind(withCiliumResources) } diff --git a/pkg/kubernetes/platforminfo_test.go b/pkg/kubernetes/platforminfo_test.go index 50d7199f4..d43d25904 100644 --- a/pkg/kubernetes/platforminfo_test.go +++ b/pkg/kubernetes/platforminfo_test.go @@ -7,6 +7,124 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +func Test_createPlatformInfoFromAPIObjects(t *testing.T) { + tests := []struct { + name string + tag string + apiGroups []*v1.APIGroup + apiResourceList []*v1.APIResourceList + useV1Beta1PDB bool + pdbPreferredVersion string + pdbOtherVersion string + }{ + { + name: "v1 preferred, PDB v1 prferred, PDB v1beta1 not proferred", + apiGroups: []*v1.APIGroup{ + newApiGroupPointer( + v1.APIGroup{ + Name: "policy", + Versions: []v1.GroupVersionForDiscovery{ + { + GroupVersion: "policy/v1", + }, + { + GroupVersion: "policy/v1beta1", + }, + }, + PreferredVersion: v1.GroupVersionForDiscovery{ + GroupVersion: "policy/v1", + }, + }, + ), + }, + apiResourceList: createDefaultApiResourceList(), + useV1Beta1PDB: false, + pdbPreferredVersion: "policy/v1", + pdbOtherVersion: "policy/v1beta1", + }, + { + name: "v1beta1 preferred, PDB PDB v1 not proferred", + tag: "tag 1", + apiGroups: []*v1.APIGroup{ + newApiGroupPointer( + v1.APIGroup{ + Name: "policy", + Versions: []v1.GroupVersionForDiscovery{ + { + GroupVersion: "policy/v1", + }, + { + GroupVersion: "policy/v1beta1", + }, + }, + PreferredVersion: v1.GroupVersionForDiscovery{ + GroupVersion: "policy/v1beta1", + }, + }, + ), + }, + apiResourceList: createDefaultApiResourceList(), + useV1Beta1PDB: true, + pdbPreferredVersion: "policy/v1beta1", + pdbOtherVersion: "policy/v1", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + platformInfo := NewPlatformInfo(nil, tt.apiGroups, tt.apiResourceList) + assert.Equal(t, tt.useV1Beta1PDB, platformInfo.UseV1Beta1PDB()) + assert.Equal(t, tt.pdbPreferredVersion, platformInfo.apiPreferredVersions["PodDisruptionBudget"]) + assert.Equal(t, tt.pdbOtherVersion, platformInfo.apiOtherVersions["PodDisruptionBudget"]) + }) + } +} + +func Test_getPDBFlag(t *testing.T) { + tests := []struct { + name string + preferred map[string]string + other map[string]string + useV1Beta1PDB bool + }{ + { + name: "Chooses preferred version of PodDisruptionBudget", + preferred: map[string]string{ + "PodDisruptionBudget": "policy/v1", + }, + other: map[string]string{ + "PodDisruptionBudget": "policy/v1beta1", + }, + useV1Beta1PDB: false, + }, + { + name: "Chooses preferred version of PodDisruptionBudget", + preferred: map[string]string{ + "PodDisruptionBudget": "policy/v1beta1", + }, + other: map[string]string{ + "PodDisruptionBudget": "policy/v1", + }, + useV1Beta1PDB: true, + }, + { + name: "Unrecognized preferred version, defaults to v1", + preferred: map[string]string{ + "PodDisruptionBudget": "xyz", + }, + other: map[string]string{}, + useV1Beta1PDB: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + platformInfo := NewPlatformInfoFromVersionMaps(nil, tt.preferred, tt.other) + assert.Equal(t, tt.useV1Beta1PDB, platformInfo.UseV1Beta1PDB()) + }) + } +} + func Test_getDatadogAgentVersions(t *testing.T) { tests := []struct { name string @@ -92,6 +210,41 @@ func Test_getDatadogAgentVersions(t *testing.T) { } } +func createDefaultApiResourceList() []*v1.APIResourceList { + return []*v1.APIResourceList{ + newApiResourceListPointer( + v1.APIResourceList{ + GroupVersion: "policy/v1", + APIResources: []v1.APIResource{ + { + Kind: "PodDisruptionBudget", + }, + }, + }, + ), + newApiResourceListPointer( + v1.APIResourceList{ + GroupVersion: "policy/v1beta1", + APIResources: []v1.APIResource{ + { + Kind: "PodDisruptionBudget", + }, + }, + }, + ), + newApiResourceListPointer( + v1.APIResourceList{ + GroupVersion: "datadoghq/v1alpha1", + APIResources: []v1.APIResource{ + { + Kind: "DatadogAgent", + }, + }, + }, + ), + } +} + func createDatadogAgentResourceList() []*v1.APIResourceList { return []*v1.APIResourceList{ newApiResourceListPointer( @@ -124,3 +277,12 @@ func newApiGroupPointer(apiGroup v1.APIGroup) *v1.APIGroup { func newApiResourceListPointer(apiResourceList v1.APIResourceList) *v1.APIResourceList { return &apiResourceList } + +func containsObjectKind(list []ObjectKind, s ObjectKind) bool { + for _, v := range list { + if v == s { + return true + } + } + return false +} From 459d28e996e4d768fdb81df8948ebef0ce1b03a7 Mon Sep 17 00:00:00 2001 From: Jennifer Chen <32009013+jennchenn@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:08:34 -0500 Subject: [PATCH 3/8] [datadogpodautoscalers] Add stabilization window to scaling policy (#1519) * Add stabilization window to scaling policy autoscaling CRD * fixup! Add stabilization window to scaling policy autoscaling CRD * Reorder fields alphabetically * Add validation for stabilization window * Generate DPA CRD files * fixup! Generate DPA CRD files * Remove default setting of stabilization window seconds to 0 * Update minimum stabilization window seconds to 0 * fixup! Update minimum stabilization window seconds to 0 --------- Co-authored-by: levan-m <116471169+levan-m@users.noreply.github.com> --- .../v1alpha1/datadogpodautoscaler_types.go | 7 +++++++ .../v1/datadoghq.com_datadogpodautoscalers.yaml | 16 ++++++++++++++++ .../datadoghq.com_datadogpodautoscalers.yaml | 10 ++++++++++ 3 files changed, 33 insertions(+) diff --git a/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go b/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go index 4500d4eed..b442ccd7c 100644 --- a/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go +++ b/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go @@ -191,6 +191,13 @@ type DatadogPodAutoscalerScalingPolicy struct { // +listType=atomic // +optional Rules []DatadogPodAutoscalerScalingRule `json:"rules,omitempty"` + + // StabilizationWindowSeconds is the number of seconds the controller should lookback at previous recommendations + // before deciding to apply a new one. Defaults to 0. + // +optional + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:validation:Maximum=1800 + StabilizationWindowSeconds int32 `json:"stabilizationWindowSeconds,omitempty"` } // DatadogPodAutoscalerScalingRuleType defines how scaling rule value should be interpreted. diff --git a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml index 148d84206..5a30875db 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml +++ b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml @@ -225,6 +225,14 @@ spec: type: object type: array x-kubernetes-list-type: atomic + stabilizationWindowSeconds: + description: |- + StabilizationWindowSeconds is the number of seconds the controller should lookback at previous recommendations + before deciding to apply a new one. Defaults to 0. + format: int32 + maximum: 1800 + minimum: 0 + type: integer strategy: description: |- Strategy is used to specify which policy should be used. @@ -291,6 +299,14 @@ spec: type: object type: array x-kubernetes-list-type: atomic + stabilizationWindowSeconds: + description: |- + StabilizationWindowSeconds is the number of seconds the controller should lookback at previous recommendations + before deciding to apply a new one. Defaults to 0. + format: int32 + maximum: 1800 + minimum: 0 + type: integer strategy: description: |- Strategy is used to specify which policy should be used. diff --git a/config/crd/bases/v1beta1/datadoghq.com_datadogpodautoscalers.yaml b/config/crd/bases/v1beta1/datadoghq.com_datadogpodautoscalers.yaml index 377924183..2eca96e63 100644 --- a/config/crd/bases/v1beta1/datadoghq.com_datadogpodautoscalers.yaml +++ b/config/crd/bases/v1beta1/datadoghq.com_datadogpodautoscalers.yaml @@ -200,6 +200,11 @@ spec: type: object type: array x-kubernetes-list-type: atomic + stabilizationWindowSeconds: + description: StabilizationWindowSeconds is used to specify the number of seconds to lookback to stabilize new recommendations before deciding to apply a new one. Defaults to 0. + format: int32 + minimum: 0 + type: integer strategy: description: Strategy is used to specify which policy should be used. If not set, the default value Max is used. enum: @@ -256,6 +261,11 @@ spec: type: object type: array x-kubernetes-list-type: atomic + stabilizationWindowSeconds: + description: StabilizationWindowSeconds is used to specify the number of seconds to lookback to stabilize new recommendations. Defaults to 0. + format: int32 + minimum: 0 + type: integer strategy: description: Strategy is used to specify which policy should be used. If not set, the default value Max is used. enum: From f517775059d19bab22f1a15c91fcab195f5207b1 Mon Sep 17 00:00:00 2001 From: levan-m <116471169+levan-m@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:05:56 -0500 Subject: [PATCH 4/8] Regenerate stale datadogpodautoscalers CRD (#1584) --- ...tadoghq.com_datadogpodautoscalers_v1alpha1.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha1.json b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha1.json index 4bd00a7d7..984898c87 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha1.json +++ b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha1.json @@ -263,6 +263,13 @@ "type": "array", "x-kubernetes-list-type": "atomic" }, + "stabilizationWindowSeconds": { + "description": "StabilizationWindowSeconds is the number of seconds the controller should lookback at previous recommendations\nbefore deciding to apply a new one. Defaults to 0.", + "format": "int32", + "maximum": 1800, + "minimum": 0, + "type": "integer" + }, "strategy": { "description": "Strategy is used to specify which policy should be used.\nIf not set, the default value Max is used.", "enum": [ @@ -340,6 +347,13 @@ "type": "array", "x-kubernetes-list-type": "atomic" }, + "stabilizationWindowSeconds": { + "description": "StabilizationWindowSeconds is the number of seconds the controller should lookback at previous recommendations\nbefore deciding to apply a new one. Defaults to 0.", + "format": "int32", + "maximum": 1800, + "minimum": 0, + "type": "integer" + }, "strategy": { "description": "Strategy is used to specify which policy should be used.\nIf not set, the default value Max is used.", "enum": [ From e2f08ba2633ede362fba67662624f8448a908935 Mon Sep 17 00:00:00 2001 From: Mackenzie <63265430+mackjmr@users.noreply.github.com> Date: Fri, 20 Dec 2024 18:29:35 +0100 Subject: [PATCH 5/8] OTel Agent Feature Support (#1559) * OTel Agent Feature Support * update test * add port documentation * remove flag support * add examples * fix * fix examples * fix * fix test * rename feature from otelAgent to otelCollector * rename * rename directory/ pkg * undo change to InitConfig volumes * remove unrelated changes * add empty line * add otel collector feature to Test_defaultFeatures * add otel agent feature to factory test * add annotation enabled/ feature disabled test * Use Replace with i=1 instead of ReplaceAll as we know there is only 1 instance to replace * fix examples * update example ports to 0.0.0.0 (defaults to localhost) and add annotations example with remove note * update o.ports rather than DDA directly * add support for core config * Move image to images.go per feedback * fix test after merge of main * add non default auth path volume mount, required for staging * add vm logs * change sync delay to 30s --------- Co-authored-by: levan-m <116471169+levan-m@users.noreply.github.com> --- api/datadoghq/v2alpha1/const.go | 2 + .../v2alpha1/datadogagent_default.go | 7 + .../v2alpha1/datadogagent_default_test.go | 185 ++++++++++ api/datadoghq/v2alpha1/datadogagent_types.go | 47 +++ api/datadoghq/v2alpha1/envvar.go | 4 + api/datadoghq/v2alpha1/test/builder.go | 69 ++++ .../v2alpha1/zz_generated.deepcopy.go | 76 +++++ .../v2alpha1/zz_generated.openapi.go | 91 ++++- cmd/main.go | 3 - .../bases/v1/datadoghq.com_datadogagents.yaml | 238 +++++++++++++ .../datadoghq.com_datadogagents_v2alpha1.json | 242 +++++++++++++ docs/configuration.v2alpha1.md | 8 + ...dog-agent-with-otel-agent-annotations.yaml | 89 +++++ ...tadog-agent-with-otel-agent-configmap.yaml | 58 ++++ .../datadog-agent-with-otel-agent.yaml | 48 +++ .../datadogagent/component/agent/default.go | 39 ++- .../controller/datadogagent/controller.go | 3 +- .../feature/enabledefault/feature.go | 8 +- .../controller/datadogagent/feature/ids.go | 2 + .../feature/otelcollector/configmap_test.go | 43 +++ .../defaultconfig/defaultconfig.go | 49 +++ .../feature/otelcollector/feature.go | 212 ++++++++++++ .../feature/otelcollector/feature_test.go | 322 ++++++++++++++++++ .../datadogagent/feature/test/factory_test.go | 53 ++- .../controller/datadogagent/feature/types.go | 2 - internal/controller/setup.go | 2 - pkg/defaulting/images.go | 5 +- 27 files changed, 1867 insertions(+), 40 deletions(-) create mode 100644 examples/datadogagent/datadog-agent-with-otel-agent-annotations.yaml create mode 100644 examples/datadogagent/datadog-agent-with-otel-agent-configmap.yaml create mode 100644 examples/datadogagent/datadog-agent-with-otel-agent.yaml create mode 100644 internal/controller/datadogagent/feature/otelcollector/configmap_test.go create mode 100644 internal/controller/datadogagent/feature/otelcollector/defaultconfig/defaultconfig.go create mode 100644 internal/controller/datadogagent/feature/otelcollector/feature.go create mode 100644 internal/controller/datadogagent/feature/otelcollector/feature_test.go diff --git a/api/datadoghq/v2alpha1/const.go b/api/datadoghq/v2alpha1/const.go index 83b86c6bb..d14341593 100644 --- a/api/datadoghq/v2alpha1/const.go +++ b/api/datadoghq/v2alpha1/const.go @@ -102,6 +102,8 @@ const ( DefaultDogstatsdPort = 8125 // DefaultDogstatsdPortName default dogstatsd port name DefaultDogstatsdPortName = "dogstatsdport" + // DefaultOTelAgentConf default otel agent ConfigMap name + DefaultOTelAgentConf string = "otel-agent-config" // DefaultKubeStateMetricsCoreConf default ksm core ConfigMap name DefaultKubeStateMetricsCoreConf string = "kube-state-metrics-core-config" // DefaultOrchestratorExplorerConf default orchestrator explorer ConfigMap name diff --git a/api/datadoghq/v2alpha1/datadogagent_default.go b/api/datadoghq/v2alpha1/datadogagent_default.go index 978c22e03..97d54f895 100644 --- a/api/datadoghq/v2alpha1/datadogagent_default.go +++ b/api/datadoghq/v2alpha1/datadogagent_default.go @@ -25,6 +25,7 @@ const ( defaultLogPodLogsPath string = "/var/log/pods" defaultLogContainerSymlinksPath string = "/var/log/containers" + defaultOtelCollectorEnabled bool = false defaultLiveProcessCollectionEnabled bool = false defaultLiveContainerCollectionEnabled bool = true defaultProcessDiscoveryEnabled bool = true @@ -222,6 +223,12 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.LiveContainerCollection.Enabled, defaultLiveContainerCollectionEnabled) + // OTelCollector Feature + if ddaSpec.Features.OtelCollector == nil { + ddaSpec.Features.OtelCollector = &OtelCollectorFeatureConfig{} + } + apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OtelCollector.Enabled, defaultOtelCollectorEnabled) + // LiveProcessCollection Feature if ddaSpec.Features.LiveProcessCollection == nil { ddaSpec.Features.LiveProcessCollection = &LiveProcessCollectionFeatureConfig{} diff --git a/api/datadoghq/v2alpha1/datadogagent_default_test.go b/api/datadoghq/v2alpha1/datadogagent_default_test.go index fc8a80ef3..35804fce8 100644 --- a/api/datadoghq/v2alpha1/datadogagent_default_test.go +++ b/api/datadoghq/v2alpha1/datadogagent_default_test.go @@ -212,6 +212,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -332,6 +335,9 @@ func Test_defaultFeatures(t *testing.T) { APM: &APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), @@ -419,6 +425,9 @@ func Test_defaultFeatures(t *testing.T) { APM: &APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), @@ -554,6 +563,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -698,6 +710,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -837,6 +852,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -976,6 +994,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -1124,6 +1145,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -1263,6 +1287,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -1405,6 +1432,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -1542,6 +1572,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -1698,6 +1731,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -1788,6 +1824,149 @@ func Test_defaultFeatures(t *testing.T) { }, }, }, + + { + name: "OTel Collector is enabled", + ddaSpec: &DatadogAgentSpec{ + Features: &DatadogFeatures{ + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(valueTrue), + }, + }, + }, + want: &DatadogAgentSpec{ + Features: &DatadogFeatures{ + LogCollection: &LogCollectionFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), + }, + LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), + }, + LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), + }, + ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), + }, + OOMKill: &OOMKillFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), + }, + TCPQueueLength: &TCPQueueLengthFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), + }, + EBPFCheck: &EBPFCheckFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), + }, + ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), + }, + APM: &APMFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), + HostPortConfig: &HostPortConfig{ + Port: apiutils.NewInt32Pointer(defaultAPMHostPort), + Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), + }, + UnixDomainSocketConfig: &UnixDomainSocketConfig{ + Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), + Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), + }, + SingleStepInstrumentation: &SingleStepInstrumentation{ + Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), + LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + }, + }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(valueTrue), + }, + ASM: &ASMFeatureConfig{ + Threats: &ASMThreatsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), + }, + SCA: &ASMSCAConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), + }, + IAST: &ASMIASTConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), + }, + }, + CSPM: &CSPMFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), + }, + CWS: &CWSFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), + }, + NPM: &NPMFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), + }, + USM: &USMFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), + }, + Dogstatsd: &DogstatsdFeatureConfig{ + OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), + HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &UnixDomainSocketConfig{ + Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), + Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), + }, + }, + OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ + GRPC: &OTLPGRPCConfig{ + Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), + }, + HTTP: &OTLPHTTPConfig{ + Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), + HostPortConfig: nil, + Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), + }, + }}}, + RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), + }, + EventCollection: &EventCollectionFeatureConfig{ + CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), + }, + OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), + ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), + }, + ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), + }, + KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), + }, + ClusterChecks: &ClusterChecksFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), + UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), + }, + AdmissionController: &AdmissionControllerFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), + Validation: &AdmissionControllerValidationConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), + }, + Mutation: &AdmissionControllerMutationConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), + }, + MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), + ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), + CWSInstrumentation: &CWSInstrumentationConfig{ + Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), + }, + KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), + }, + }, + PrometheusScrape: &PrometheusScrapeFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), + }, + HelmCheck: &HelmCheckFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), + }, + }, + }, + }, { // This test sets same defaults as the one with `Features: nil`; and leaves other configs as empty structs. name: "all feature configs are empty structs, configures defaults where applicable, leaves others empty", @@ -1860,6 +2039,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), @@ -2002,6 +2184,9 @@ func Test_defaultFeatures(t *testing.T) { LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, + OtelCollector: &OtelCollectorFeatureConfig{ + Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), + }, ASM: &ASMFeatureConfig{ Threats: &ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), diff --git a/api/datadoghq/v2alpha1/datadogagent_types.go b/api/datadoghq/v2alpha1/datadogagent_types.go index f92c17c35..5a0a39a51 100644 --- a/api/datadoghq/v2alpha1/datadogagent_types.go +++ b/api/datadoghq/v2alpha1/datadogagent_types.go @@ -44,6 +44,8 @@ type DatadogAgentSpec struct { type DatadogFeatures struct { // Application-level features + // OtelCollector configuration. + OtelCollector *OtelCollectorFeatureConfig `json:"otelCollector,omitempty"` // LogCollection configuration. LogCollection *LogCollectionFeatureConfig `json:"logCollection,omitempty"` // LiveProcessCollection configuration. @@ -682,6 +684,51 @@ type KubeStateMetricsCoreFeatureConfig struct { Conf *CustomConfig `json:"conf,omitempty"` } +// OtelCollectorFeatureConfig contains the configuration for the otel-agent. +// +k8s:openapi-gen=true +type OtelCollectorFeatureConfig struct { + // Enabled enables the OTel Agent. + // Default: true + // +optional + Enabled *bool `json:"enabled,omitempty"` + + // Conf overrides the configuration for the default Kubernetes State Metrics Core check. + // This must point to a ConfigMap containing a valid cluster check configuration. + // When passing a configmap, file name *must* be otel-config.yaml. + // +optional + Conf *CustomConfig `json:"conf,omitempty"` + + // Ports contains the ports for the otel-agent. + // Defaults: otel-grpc:4317 / otel-http:4318. Note: setting 4317 + // or 4318 manually is *only* supported if name match default names (otel-grpc, otel-http). + // If not, this will lead to a port conflict. + // This limitation will be lifted once annotations support is removed. + // +optional + Ports []*corev1.ContainerPort `json:"ports,omitempty"` + + // OTelCollector Config Relevant to the Core agent + // +optional + CoreConfig *CoreConfig `json:"coreConfig,omitempty"` +} + +// CoreConfig exposes the otel collector configs relevant to the core agent. +// +k8s:openapi-gen=true +type CoreConfig struct { + // Enabled marks otelcollector as enabled in core agent. + // +optional + Enabled *bool `json:"enabled,omitempty"` + + // +optional + // Extension URL provides the URL of the ddflareextension to + // the core agent. + ExtensionURL *string `json:"extension_url,omitempty"` + + // +optional + // Extension URL provides the timout of the ddflareextension to + // the core agent. + ExtensionTimeout *int `json:"extension_timeout,omitempty"` +} + // AdmissionControllerFeatureConfig contains the Admission Controller feature configuration. // The Admission Controller runs in the Cluster Agent. type AdmissionControllerFeatureConfig struct { diff --git a/api/datadoghq/v2alpha1/envvar.go b/api/datadoghq/v2alpha1/envvar.go index 4b1780cad..dee11f317 100644 --- a/api/datadoghq/v2alpha1/envvar.go +++ b/api/datadoghq/v2alpha1/envvar.go @@ -62,6 +62,10 @@ const ( DDSystemProbeExternal = "DD_SYSTEM_PROBE_EXTERNAL" DDSystemProbeSocket = "DD_SYSPROBE_SOCKET" DDTags = "DD_TAGS" + // otelcollector core agent configs + DDOtelCollectorCoreConfigEnabled = "DD_OTELCOLLECTOR_ENABLED" + DDOtelCollectorCoreConfigExtensionURL = "DD_OTELCOLLECTOR_EXTENSION_URL" + DDOtelCollectorCoreConfigExtensionTimeout = "DD_OTELCOLLECTOR_EXTENSION_TIMEOUT" DockerHost = "DOCKER_HOST" // KubernetesEnvvarName Env var used by the Datadog Agent container entrypoint diff --git a/api/datadoghq/v2alpha1/test/builder.go b/api/datadoghq/v2alpha1/test/builder.go index 260919894..b8d754938 100644 --- a/api/datadoghq/v2alpha1/test/builder.go +++ b/api/datadoghq/v2alpha1/test/builder.go @@ -9,6 +9,7 @@ import ( "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" "github.com/DataDog/datadog-operator/api/utils" apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otelcollector/defaultconfig" defaulting "github.com/DataDog/datadog-operator/pkg/defaulting" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -374,6 +375,74 @@ func (builder *DatadogAgentBuilder) WithProcessDiscoveryEnabled(enabled bool) *D return builder } +// OTel Agent +func (builder *DatadogAgentBuilder) initOtelCollector() { + if builder.datadogAgent.Spec.Features.OtelCollector == nil { + builder.datadogAgent.Spec.Features.OtelCollector = &v2alpha1.OtelCollectorFeatureConfig{} + } +} + +func (builder *DatadogAgentBuilder) WithOTelCollectorEnabled(enabled bool) *DatadogAgentBuilder { + builder.initOtelCollector() + builder.datadogAgent.Spec.Features.OtelCollector.Enabled = apiutils.NewBoolPointer(enabled) + return builder +} + +func (builder *DatadogAgentBuilder) WithOTelCollectorConfig() *DatadogAgentBuilder { + builder.datadogAgent.Spec.Features.OtelCollector.Conf = &v2alpha1.CustomConfig{} + builder.datadogAgent.Spec.Features.OtelCollector.Conf.ConfigData = + apiutils.NewStringPointer(defaultconfig.DefaultOtelCollectorConfig) + return builder +} + +func (builder *DatadogAgentBuilder) WithOTelCollectorCoreConfigEnabled(enabled bool) *DatadogAgentBuilder { + if builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig == nil { + builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig = &v2alpha1.CoreConfig{} + } + builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig.Enabled = apiutils.NewBoolPointer(enabled) + return builder +} + +func (builder *DatadogAgentBuilder) WithOTelCollectorCoreConfigExtensionTimeout(timeout int) *DatadogAgentBuilder { + if builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig == nil { + builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig = &v2alpha1.CoreConfig{} + } + builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig.ExtensionTimeout = apiutils.NewIntPointer(timeout) + return builder +} + +func (builder *DatadogAgentBuilder) WithOTelCollectorCoreConfigExtensionURL(url string) *DatadogAgentBuilder { + if builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig == nil { + builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig = &v2alpha1.CoreConfig{} + } + builder.datadogAgent.Spec.Features.OtelCollector.CoreConfig.ExtensionURL = apiutils.NewStringPointer(url) + return builder +} + +func (builder *DatadogAgentBuilder) WithOTelCollectorConfigMap() *DatadogAgentBuilder { + builder.datadogAgent.Spec.Features.OtelCollector.Conf = &v2alpha1.CustomConfig{} + builder.datadogAgent.Spec.Features.OtelCollector.Conf.ConfigMap = &v2alpha1.ConfigMapConfig{ + Name: "user-provided-config-map", + } + return builder +} + +func (builder *DatadogAgentBuilder) WithOTelCollectorPorts(grpcPort int32, httpPort int32) *DatadogAgentBuilder { + builder.datadogAgent.Spec.Features.OtelCollector.Ports = []*corev1.ContainerPort{ + { + Name: "otel-http", + ContainerPort: httpPort, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "otel-grpc", + ContainerPort: grpcPort, + Protocol: corev1.ProtocolTCP, + }, + } + return builder +} + // Log Collection func (builder *DatadogAgentBuilder) initLogCollection() { if builder.datadogAgent.Spec.Features.LogCollection == nil { diff --git a/api/datadoghq/v2alpha1/zz_generated.deepcopy.go b/api/datadoghq/v2alpha1/zz_generated.deepcopy.go index f5871d649..a36ac9778 100644 --- a/api/datadoghq/v2alpha1/zz_generated.deepcopy.go +++ b/api/datadoghq/v2alpha1/zz_generated.deepcopy.go @@ -599,6 +599,36 @@ func (in *ConfigMapConfig) DeepCopy() *ConfigMapConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CoreConfig) DeepCopyInto(out *CoreConfig) { + *out = *in + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } + if in.ExtensionURL != nil { + in, out := &in.ExtensionURL, &out.ExtensionURL + *out = new(string) + **out = **in + } + if in.ExtensionTimeout != nil { + in, out := &in.ExtensionTimeout, &out.ExtensionTimeout + *out = new(int) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CoreConfig. +func (in *CoreConfig) DeepCopy() *CoreConfig { + if in == nil { + return nil + } + out := new(CoreConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CustomConfig) DeepCopyInto(out *CustomConfig) { *out = *in @@ -1107,6 +1137,11 @@ func (in *DatadogCredentials) DeepCopy() *DatadogCredentials { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DatadogFeatures) DeepCopyInto(out *DatadogFeatures) { *out = *in + if in.OtelCollector != nil { + in, out := &in.OtelCollector, &out.OtelCollector + *out = new(OtelCollectorFeatureConfig) + (*in).DeepCopyInto(*out) + } if in.LogCollection != nil { in, out := &in.LogCollection, &out.LogCollection *out = new(LogCollectionFeatureConfig) @@ -2271,6 +2306,47 @@ func (in *OriginDetectionUnified) DeepCopy() *OriginDetectionUnified { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OtelCollectorFeatureConfig) DeepCopyInto(out *OtelCollectorFeatureConfig) { + *out = *in + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } + if in.Conf != nil { + in, out := &in.Conf, &out.Conf + *out = new(CustomConfig) + (*in).DeepCopyInto(*out) + } + if in.Ports != nil { + in, out := &in.Ports, &out.Ports + *out = make([]*corev1.ContainerPort, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(corev1.ContainerPort) + **out = **in + } + } + } + if in.CoreConfig != nil { + in, out := &in.CoreConfig, &out.CoreConfig + *out = new(CoreConfig) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OtelCollectorFeatureConfig. +func (in *OtelCollectorFeatureConfig) DeepCopy() *OtelCollectorFeatureConfig { + if in == nil { + return nil + } + out := new(OtelCollectorFeatureConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ProcessDiscoveryFeatureConfig) DeepCopyInto(out *ProcessDiscoveryFeatureConfig) { *out = *in diff --git a/api/datadoghq/v2alpha1/zz_generated.openapi.go b/api/datadoghq/v2alpha1/zz_generated.openapi.go index 813a4d3b1..0568f4e9f 100644 --- a/api/datadoghq/v2alpha1/zz_generated.openapi.go +++ b/api/datadoghq/v2alpha1/zz_generated.openapi.go @@ -18,6 +18,7 @@ import ( func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { return map[string]common.OpenAPIDefinition{ "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CSPMHostBenchmarksConfig": schema_datadog_operator_api_datadoghq_v2alpha1_CSPMHostBenchmarksConfig(ref), + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CoreConfig": schema_datadog_operator_api_datadoghq_v2alpha1_CoreConfig(ref), "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CustomConfig": schema_datadog_operator_api_datadoghq_v2alpha1_CustomConfig(ref), "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.DaemonSetStatus": schema_datadog_operator_api_datadoghq_v2alpha1_DaemonSetStatus(ref), "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.DatadogAgent": schema_datadog_operator_api_datadoghq_v2alpha1_DatadogAgent(ref), @@ -40,6 +41,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OTLPProtocolsConfig": schema_datadog_operator_api_datadoghq_v2alpha1_OTLPProtocolsConfig(ref), "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OTLPReceiverConfig": schema_datadog_operator_api_datadoghq_v2alpha1_OTLPReceiverConfig(ref), "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OrchestratorExplorerFeatureConfig": schema_datadog_operator_api_datadoghq_v2alpha1_OrchestratorExplorerFeatureConfig(ref), + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OtelCollectorFeatureConfig": schema_datadog_operator_api_datadoghq_v2alpha1_OtelCollectorFeatureConfig(ref), "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.PrometheusScrapeFeatureConfig": schema_datadog_operator_api_datadoghq_v2alpha1_PrometheusScrapeFeatureConfig(ref), "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.RemoteConfigConfiguration": schema_datadog_operator_api_datadoghq_v2alpha1_RemoteConfigConfiguration(ref), "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.SeccompConfig": schema_datadog_operator_api_datadoghq_v2alpha1_SeccompConfig(ref), @@ -69,6 +71,40 @@ func schema_datadog_operator_api_datadoghq_v2alpha1_CSPMHostBenchmarksConfig(ref } } +func schema_datadog_operator_api_datadoghq_v2alpha1_CoreConfig(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "CoreConfig exposes the otel collector configs relevant to the core agent.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "enabled": { + SchemaProps: spec.SchemaProps{ + Description: "Enabled marks otelcollector as enabled in core agent.", + Type: []string{"boolean"}, + Format: "", + }, + }, + "extension_url": { + SchemaProps: spec.SchemaProps{ + Description: "Extension URL provides the URL of the ddflareextension to the core agent.", + Type: []string{"string"}, + Format: "", + }, + }, + "extension_timeout": { + SchemaProps: spec.SchemaProps{ + Description: "Extension URL provides the timout of the ddflareextension to the core agent.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + }, + }, + } +} + func schema_datadog_operator_api_datadoghq_v2alpha1_CustomConfig(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -525,6 +561,12 @@ func schema_datadog_operator_api_datadoghq_v2alpha1_DatadogFeatures(ref common.R Description: "DatadogFeatures are features running on the Agent and Cluster Agent.", Type: []string{"object"}, Properties: map[string]spec.Schema{ + "otelCollector": { + SchemaProps: spec.SchemaProps{ + Description: "OtelCollector configuration.", + Ref: ref("github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OtelCollectorFeatureConfig"), + }, + }, "logCollection": { SchemaProps: spec.SchemaProps{ Description: "LogCollection configuration.", @@ -691,7 +733,7 @@ func schema_datadog_operator_api_datadoghq_v2alpha1_DatadogFeatures(ref common.R }, }, Dependencies: []string{ - "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.APMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ASMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.AdmissionControllerFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.AutoscalingFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CSPMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CWSFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ClusterChecksFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.DogstatsdFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.EBPFCheckFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.EventCollectionFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ExternalMetricsServerFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.HelmCheckFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.KubeStateMetricsCoreFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.LiveContainerCollectionFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.LiveProcessCollectionFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.LogCollectionFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.NPMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OOMKillFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OTLPFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OrchestratorExplorerFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ProcessDiscoveryFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.PrometheusScrapeFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.RemoteConfigurationFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.SBOMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ServiceDiscoveryFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.TCPQueueLengthFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.USMFeatureConfig"}, + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.APMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ASMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.AdmissionControllerFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.AutoscalingFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CSPMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CWSFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ClusterChecksFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.DogstatsdFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.EBPFCheckFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.EventCollectionFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ExternalMetricsServerFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.HelmCheckFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.KubeStateMetricsCoreFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.LiveContainerCollectionFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.LiveProcessCollectionFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.LogCollectionFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.NPMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OOMKillFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OTLPFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OrchestratorExplorerFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.OtelCollectorFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ProcessDiscoveryFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.PrometheusScrapeFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.RemoteConfigurationFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.SBOMFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.ServiceDiscoveryFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.TCPQueueLengthFeatureConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.USMFeatureConfig"}, } } @@ -1355,6 +1397,53 @@ func schema_datadog_operator_api_datadoghq_v2alpha1_OrchestratorExplorerFeatureC } } +func schema_datadog_operator_api_datadoghq_v2alpha1_OtelCollectorFeatureConfig(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "OtelCollectorFeatureConfig contains the configuration for the otel-agent.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "enabled": { + SchemaProps: spec.SchemaProps{ + Description: "Enabled enables the OTel Agent. Default: true", + Type: []string{"boolean"}, + Format: "", + }, + }, + "conf": { + SchemaProps: spec.SchemaProps{ + Description: "Conf overrides the configuration for the default Kubernetes State Metrics Core check. This must point to a ConfigMap containing a valid cluster check configuration. When passing a configmap, file name *must* be otel-config.yaml.", + Ref: ref("github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CustomConfig"), + }, + }, + "ports": { + SchemaProps: spec.SchemaProps{ + Description: "Ports contains the ports for the otel-agent. Defaults: otel-grpc:4317 / otel-http:4318. Note: setting 4317 or 4318 manually is *only* supported if name match default names (otel-grpc, otel-http). If not, this will lead to a port conflict. This limitation will be lifted once annotations support is removed.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/api/core/v1.ContainerPort"), + }, + }, + }, + }, + }, + "coreConfig": { + SchemaProps: spec.SchemaProps{ + Description: "OTelCollector Config Relevant to the Core agent", + Ref: ref("github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CoreConfig"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CoreConfig", "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1.CustomConfig", "k8s.io/api/core/v1.ContainerPort"}, + } +} + func schema_datadog_operator_api_datadoghq_v2alpha1_PrometheusScrapeFeatureConfig(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/cmd/main.go b/cmd/main.go index 5fe587c12..82201d7ad 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -123,7 +123,6 @@ type options struct { introspectionEnabled bool datadogAgentProfileEnabled bool remoteConfigEnabled bool - otelAgentEnabled bool datadogDashboardEnabled bool // Secret Backend options @@ -157,7 +156,6 @@ func (opts *options) Parse() { flag.BoolVar(&opts.introspectionEnabled, "introspectionEnabled", false, "Enable introspection (beta)") flag.BoolVar(&opts.datadogAgentProfileEnabled, "datadogAgentProfileEnabled", false, "Enable DatadogAgentProfile controller (beta)") flag.BoolVar(&opts.remoteConfigEnabled, "remoteConfigEnabled", false, "Enable RemoteConfig capabilities in the Operator (beta)") - flag.BoolVar(&opts.otelAgentEnabled, "otelAgentEnabled", false, "Enable the OTel agent container (beta)") flag.BoolVar(&opts.datadogDashboardEnabled, "datadogDashboardEnabled", false, "Enable the DatadogDashboard controller") // ExtendedDaemonset configuration @@ -301,7 +299,6 @@ func run(opts *options) error { V2APIEnabled: true, IntrospectionEnabled: opts.introspectionEnabled, DatadogAgentProfileEnabled: opts.datadogAgentProfileEnabled, - OtelAgentEnabled: opts.otelAgentEnabled, DatadogDashboardEnabled: opts.datadogDashboardEnabled, } diff --git a/config/crd/bases/v1/datadoghq.com_datadogagents.yaml b/config/crd/bases/v1/datadoghq.com_datadogagents.yaml index 09beaf1d4..ee4066cf2 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogagents.yaml +++ b/config/crd/bases/v1/datadoghq.com_datadogagents.yaml @@ -1293,6 +1293,125 @@ spec: Default: true type: boolean type: object + otelCollector: + description: OtelCollector configuration. + properties: + conf: + description: |- + Conf overrides the configuration for the default Kubernetes State Metrics Core check. + This must point to a ConfigMap containing a valid cluster check configuration. + When passing a configmap, file name *must* be otel-config.yaml. + properties: + configData: + description: ConfigData corresponds to the configuration file content. + type: string + configMap: + description: ConfigMap references an existing ConfigMap with the configuration file content. + properties: + items: + description: Items maps a ConfigMap data `key` to a file `path` mount. + items: + description: Maps a string key to a path within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-map-keys: + - key + x-kubernetes-list-type: map + name: + description: Name is the name of the ConfigMap. + type: string + type: object + type: object + coreConfig: + description: OTelCollector Config Relevant to the Core agent + properties: + enabled: + description: Enabled marks otelcollector as enabled in core agent. + type: boolean + extension_timeout: + description: |- + Extension URL provides the timout of the ddflareextension to + the core agent. + type: integer + extension_url: + description: |- + Extension URL provides the URL of the ddflareextension to + the core agent. + type: string + type: object + enabled: + description: |- + Enabled enables the OTel Agent. + Default: true + type: boolean + ports: + description: |- + Ports contains the ports for the otel-agent. + Defaults: otel-grpc:4317 / otel-http:4318. Note: setting 4317 + or 4318 manually is *only* supported if name match default names (otel-grpc, otel-http). + If not, this will lead to a port conflict. + This limitation will be lifted once annotations support is removed. + items: + description: ContainerPort represents a network port in a single container. + properties: + containerPort: + description: |- + Number of port to expose on the pod's IP address. + This must be a valid port number, 0 < x < 65536. + format: int32 + type: integer + hostIP: + description: What host IP to bind the external port to. + type: string + hostPort: + description: |- + Number of port to expose on the host. + If specified, this must be a valid port number, 0 < x < 65536. + If HostNetwork is specified, this must match ContainerPort. + Most containers do not need this. + format: int32 + type: integer + name: + description: |- + If specified, this must be an IANA_SVC_NAME and unique within the pod. Each + named port in a pod must have a unique name. Name for the port that can be + referred to by services. + type: string + protocol: + default: TCP + description: |- + Protocol for port. Must be UDP, TCP, or SCTP. + Defaults to "TCP". + type: string + required: + - containerPort + type: object + type: array + type: object otlp: description: OTLP ingest configuration properties: @@ -8037,6 +8156,125 @@ spec: Default: true type: boolean type: object + otelCollector: + description: OtelCollector configuration. + properties: + conf: + description: |- + Conf overrides the configuration for the default Kubernetes State Metrics Core check. + This must point to a ConfigMap containing a valid cluster check configuration. + When passing a configmap, file name *must* be otel-config.yaml. + properties: + configData: + description: ConfigData corresponds to the configuration file content. + type: string + configMap: + description: ConfigMap references an existing ConfigMap with the configuration file content. + properties: + items: + description: Items maps a ConfigMap data `key` to a file `path` mount. + items: + description: Maps a string key to a path within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-map-keys: + - key + x-kubernetes-list-type: map + name: + description: Name is the name of the ConfigMap. + type: string + type: object + type: object + coreConfig: + description: OTelCollector Config Relevant to the Core agent + properties: + enabled: + description: Enabled marks otelcollector as enabled in core agent. + type: boolean + extension_timeout: + description: |- + Extension URL provides the timout of the ddflareextension to + the core agent. + type: integer + extension_url: + description: |- + Extension URL provides the URL of the ddflareextension to + the core agent. + type: string + type: object + enabled: + description: |- + Enabled enables the OTel Agent. + Default: true + type: boolean + ports: + description: |- + Ports contains the ports for the otel-agent. + Defaults: otel-grpc:4317 / otel-http:4318. Note: setting 4317 + or 4318 manually is *only* supported if name match default names (otel-grpc, otel-http). + If not, this will lead to a port conflict. + This limitation will be lifted once annotations support is removed. + items: + description: ContainerPort represents a network port in a single container. + properties: + containerPort: + description: |- + Number of port to expose on the pod's IP address. + This must be a valid port number, 0 < x < 65536. + format: int32 + type: integer + hostIP: + description: What host IP to bind the external port to. + type: string + hostPort: + description: |- + Number of port to expose on the host. + If specified, this must be a valid port number, 0 < x < 65536. + If HostNetwork is specified, this must match ContainerPort. + Most containers do not need this. + format: int32 + type: integer + name: + description: |- + If specified, this must be an IANA_SVC_NAME and unique within the pod. Each + named port in a pod must have a unique name. Name for the port that can be + referred to by services. + type: string + protocol: + default: TCP + description: |- + Protocol for port. Must be UDP, TCP, or SCTP. + Defaults to "TCP". + type: string + required: + - containerPort + type: object + type: array + type: object otlp: description: OTLP ingest configuration properties: diff --git a/config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json b/config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json index 2133efdcc..944437b60 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json +++ b/config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json @@ -1341,6 +1341,127 @@ }, "type": "object" }, + "otelCollector": { + "additionalProperties": false, + "description": "OtelCollector configuration.", + "properties": { + "conf": { + "additionalProperties": false, + "description": "Conf overrides the configuration for the default Kubernetes State Metrics Core check.\nThis must point to a ConfigMap containing a valid cluster check configuration.\nWhen passing a configmap, file name *must* be otel-config.yaml.", + "properties": { + "configData": { + "description": "ConfigData corresponds to the configuration file content.", + "type": "string" + }, + "configMap": { + "additionalProperties": false, + "description": "ConfigMap references an existing ConfigMap with the configuration file content.", + "properties": { + "items": { + "description": "Items maps a ConfigMap data `key` to a file `path` mount.", + "items": { + "additionalProperties": false, + "description": "Maps a string key to a path within a volume.", + "properties": { + "key": { + "description": "key is the key to project.", + "type": "string" + }, + "mode": { + "description": "mode is Optional: mode bits used to set permissions on this file.\nMust be an octal value between 0000 and 0777 or a decimal value between 0 and 511.\nYAML accepts both octal and decimal values, JSON requires decimal values for mode bits.\nIf not specified, the volume defaultMode will be used.\nThis might be in conflict with other options that affect the file\nmode, like fsGroup, and the result can be other mode bits set.", + "format": "int32", + "type": "integer" + }, + "path": { + "description": "path is the relative path of the file to map the key to.\nMay not be an absolute path.\nMay not contain the path element '..'.\nMay not start with the string '..'.", + "type": "string" + } + }, + "required": [ + "key", + "path" + ], + "type": "object" + }, + "type": "array", + "x-kubernetes-list-map-keys": [ + "key" + ], + "x-kubernetes-list-type": "map" + }, + "name": { + "description": "Name is the name of the ConfigMap.", + "type": "string" + } + }, + "type": "object" + } + }, + "type": "object" + }, + "coreConfig": { + "additionalProperties": false, + "description": "OTelCollector Config Relevant to the Core agent", + "properties": { + "enabled": { + "description": "Enabled marks otelcollector as enabled in core agent.", + "type": "boolean" + }, + "extension_timeout": { + "description": "Extension URL provides the timout of the ddflareextension to\nthe core agent.", + "type": "integer" + }, + "extension_url": { + "description": "Extension URL provides the URL of the ddflareextension to\nthe core agent.", + "type": "string" + } + }, + "type": "object" + }, + "enabled": { + "description": "Enabled enables the OTel Agent.\nDefault: true", + "type": "boolean" + }, + "ports": { + "description": "Ports contains the ports for the otel-agent.\nDefaults: otel-grpc:4317 / otel-http:4318. Note: setting 4317\nor 4318 manually is *only* supported if name match default names (otel-grpc, otel-http).\nIf not, this will lead to a port conflict.\nThis limitation will be lifted once annotations support is removed.", + "items": { + "additionalProperties": false, + "description": "ContainerPort represents a network port in a single container.", + "properties": { + "containerPort": { + "description": "Number of port to expose on the pod's IP address.\nThis must be a valid port number, 0 \u003c x \u003c 65536.", + "format": "int32", + "type": "integer" + }, + "hostIP": { + "description": "What host IP to bind the external port to.", + "type": "string" + }, + "hostPort": { + "description": "Number of port to expose on the host.\nIf specified, this must be a valid port number, 0 \u003c x \u003c 65536.\nIf HostNetwork is specified, this must match ContainerPort.\nMost containers do not need this.", + "format": "int32", + "type": "integer" + }, + "name": { + "description": "If specified, this must be an IANA_SVC_NAME and unique within the pod. Each\nnamed port in a pod must have a unique name. Name for the port that can be\nreferred to by services.", + "type": "string" + }, + "protocol": { + "default": "TCP", + "description": "Protocol for port. Must be UDP, TCP, or SCTP.\nDefaults to \"TCP\".", + "type": "string" + } + }, + "required": [ + "containerPort" + ], + "type": "object" + }, + "type": "array" + } + }, + "type": "object" + }, "otlp": { "additionalProperties": false, "description": "OTLP ingest configuration", @@ -8025,6 +8146,127 @@ }, "type": "object" }, + "otelCollector": { + "additionalProperties": false, + "description": "OtelCollector configuration.", + "properties": { + "conf": { + "additionalProperties": false, + "description": "Conf overrides the configuration for the default Kubernetes State Metrics Core check.\nThis must point to a ConfigMap containing a valid cluster check configuration.\nWhen passing a configmap, file name *must* be otel-config.yaml.", + "properties": { + "configData": { + "description": "ConfigData corresponds to the configuration file content.", + "type": "string" + }, + "configMap": { + "additionalProperties": false, + "description": "ConfigMap references an existing ConfigMap with the configuration file content.", + "properties": { + "items": { + "description": "Items maps a ConfigMap data `key` to a file `path` mount.", + "items": { + "additionalProperties": false, + "description": "Maps a string key to a path within a volume.", + "properties": { + "key": { + "description": "key is the key to project.", + "type": "string" + }, + "mode": { + "description": "mode is Optional: mode bits used to set permissions on this file.\nMust be an octal value between 0000 and 0777 or a decimal value between 0 and 511.\nYAML accepts both octal and decimal values, JSON requires decimal values for mode bits.\nIf not specified, the volume defaultMode will be used.\nThis might be in conflict with other options that affect the file\nmode, like fsGroup, and the result can be other mode bits set.", + "format": "int32", + "type": "integer" + }, + "path": { + "description": "path is the relative path of the file to map the key to.\nMay not be an absolute path.\nMay not contain the path element '..'.\nMay not start with the string '..'.", + "type": "string" + } + }, + "required": [ + "key", + "path" + ], + "type": "object" + }, + "type": "array", + "x-kubernetes-list-map-keys": [ + "key" + ], + "x-kubernetes-list-type": "map" + }, + "name": { + "description": "Name is the name of the ConfigMap.", + "type": "string" + } + }, + "type": "object" + } + }, + "type": "object" + }, + "coreConfig": { + "additionalProperties": false, + "description": "OTelCollector Config Relevant to the Core agent", + "properties": { + "enabled": { + "description": "Enabled marks otelcollector as enabled in core agent.", + "type": "boolean" + }, + "extension_timeout": { + "description": "Extension URL provides the timout of the ddflareextension to\nthe core agent.", + "type": "integer" + }, + "extension_url": { + "description": "Extension URL provides the URL of the ddflareextension to\nthe core agent.", + "type": "string" + } + }, + "type": "object" + }, + "enabled": { + "description": "Enabled enables the OTel Agent.\nDefault: true", + "type": "boolean" + }, + "ports": { + "description": "Ports contains the ports for the otel-agent.\nDefaults: otel-grpc:4317 / otel-http:4318. Note: setting 4317\nor 4318 manually is *only* supported if name match default names (otel-grpc, otel-http).\nIf not, this will lead to a port conflict.\nThis limitation will be lifted once annotations support is removed.", + "items": { + "additionalProperties": false, + "description": "ContainerPort represents a network port in a single container.", + "properties": { + "containerPort": { + "description": "Number of port to expose on the pod's IP address.\nThis must be a valid port number, 0 \u003c x \u003c 65536.", + "format": "int32", + "type": "integer" + }, + "hostIP": { + "description": "What host IP to bind the external port to.", + "type": "string" + }, + "hostPort": { + "description": "Number of port to expose on the host.\nIf specified, this must be a valid port number, 0 \u003c x \u003c 65536.\nIf HostNetwork is specified, this must match ContainerPort.\nMost containers do not need this.", + "format": "int32", + "type": "integer" + }, + "name": { + "description": "If specified, this must be an IANA_SVC_NAME and unique within the pod. Each\nnamed port in a pod must have a unique name. Name for the port that can be\nreferred to by services.", + "type": "string" + }, + "protocol": { + "default": "TCP", + "description": "Protocol for port. Must be UDP, TCP, or SCTP.\nDefaults to \"TCP\".", + "type": "string" + } + }, + "required": [ + "containerPort" + ], + "type": "object" + }, + "type": "array" + } + }, + "type": "object" + }, "otlp": { "additionalProperties": false, "description": "OTLP ingest configuration", diff --git a/docs/configuration.v2alpha1.md b/docs/configuration.v2alpha1.md index 7810746be..121c51d52 100644 --- a/docs/configuration.v2alpha1.md +++ b/docs/configuration.v2alpha1.md @@ -142,6 +142,14 @@ spec: | features.orchestratorExplorer.enabled | Enables the Orchestrator Explorer. Default: true | | features.orchestratorExplorer.extraTags | Additional tags to associate with the collected data in the form of `a b c`. This is a Cluster Agent option distinct from DD_TAGS that is used in the Orchestrator Explorer. | | features.orchestratorExplorer.scrubContainers | ScrubContainers enables scrubbing of sensitive container data (passwords, tokens, etc. ). Default: true | +| features.otelCollector.conf.configData | ConfigData corresponds to the configuration file content. | +| features.otelCollector.conf.configMap.items | Maps a ConfigMap data `key` to a file `path` mount. | +| features.otelCollector.conf.configMap.name | Is the name of the ConfigMap. | +| features.otelCollector.coreConfig.enabled | Marks otelcollector as enabled in core agent. | +| features.otelCollector.coreConfig.extension_timeout | Extension URL provides the timout of the ddflareextension to the core agent. | +| features.otelCollector.coreConfig.extension_url | Extension URL provides the URL of the ddflareextension to the core agent. | +| features.otelCollector.enabled | Enables the OTel Agent. Default: true | +| features.otelCollector.ports | Contains the ports for the otel-agent. Defaults: otel-grpc:4317 / otel-http:4318. Note: setting 4317 or 4318 manually is *only* supported if name match default names (otel-grpc, otel-http). If not, this will lead to a port conflict. This limitation will be lifted once annotations support is removed. | | features.otlp.receiver.protocols.grpc.enabled | Enable the OTLP/gRPC endpoint. Host port is enabled by default and can be disabled. | | features.otlp.receiver.protocols.grpc.endpoint | For OTLP/gRPC. gRPC supports several naming schemes: https://github.com/grpc/grpc/blob/master/doc/naming.md The Datadog Operator supports only 'host:port' (usually `0.0.0.0:port`). Default: `0.0.0.0:4317`. | | features.otlp.receiver.protocols.grpc.hostPortConfig.enabled | Enables host port configuration | diff --git a/examples/datadogagent/datadog-agent-with-otel-agent-annotations.yaml b/examples/datadogagent/datadog-agent-with-otel-agent-annotations.yaml new file mode 100644 index 000000000..e4970e7d4 --- /dev/null +++ b/examples/datadogagent/datadog-agent-with-otel-agent-annotations.yaml @@ -0,0 +1,89 @@ +apiVersion: datadoghq.com/v2alpha1 +kind: DatadogAgent +metadata: + annotations: + # Note: annotations support is temporary and will be removed in the future. + # Please use otelCollector Feature instead. + agent.datadoghq.com/otel-agent-enabled: "true" + name: datadog +spec: + global: + credentials: + apiKey: + override: + nodeAgent: + customConfigurations: + otel-config.yaml: + configMap: + name: my-datadog-otel-config + items: + - key: otel-config.yaml + path: otel-config.yaml +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: my-datadog-otel-config + labels: + app.kubernetes.io/name: "my-datadog" + app.kubernetes.io/version: "7" +data: + otel-config.yaml: |- + receivers: + prometheus: + config: + scrape_configs: + - job_name: "otel-agent" + scrape_interval: 10s + static_configs: + - targets: ["0.0.0.0:8888"] + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + exporters: + debug: + verbosity: detailed + datadog: + api: + key: ${env:DD_API_KEY} + processors: + infraattributes: + cardinality: 2 + probabilistic_sampler: + hash_seed: 22 + sampling_percentage: 15.3 + batch: + timeout: 10s + connectors: + datadog/connector: + traces: + compute_top_level_by_span_kind: true + peer_tags_aggregation: true + compute_stats_by_span_kind: true + extensions: + health_check: + service: + extensions: [health_check] + telemetry: + logs: + level: debug + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [datadog/connector] + traces/sampled: + receivers: [otlp] + processors: [probabilistic_sampler, infraattributes, batch] + exporters: [datadog] + metrics: + receivers: [otlp, datadog/connector, prometheus] + processors: [infraattributes, batch] + exporters: [datadog] + logs: + receivers: [otlp] + processors: [infraattributes, batch] + exporters: [datadog] \ No newline at end of file diff --git a/examples/datadogagent/datadog-agent-with-otel-agent-configmap.yaml b/examples/datadogagent/datadog-agent-with-otel-agent-configmap.yaml new file mode 100644 index 000000000..9ac53828d --- /dev/null +++ b/examples/datadogagent/datadog-agent-with-otel-agent-configmap.yaml @@ -0,0 +1,58 @@ +apiVersion: datadoghq.com/v2alpha1 +kind: DatadogAgent +metadata: + name: datadog +spec: + global: + credentials: + apiKey: + features: + otelCollector: + enabled: true + ports: + - containerPort: 4317 + name: otel-grpc + - containerPort: 4318 + name: otel-http + conf: + configMap: + name: custom-config-map +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: custom-config-map + namespace: system +data: + # must be named otel-config.yaml. + otel-config.yaml: |- + receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + exporters: + debug: + verbosity: detailed + datadog: + api: + key: ${env:DD_API_KEY} + processors: + batch: + connectors: + service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [datadog] + metrics: + receivers: [otlp] + processors: [batch] + exporters: [datadog] + logs: + receivers: [otlp] + processors: [batch] + exporters: [datadog] diff --git a/examples/datadogagent/datadog-agent-with-otel-agent.yaml b/examples/datadogagent/datadog-agent-with-otel-agent.yaml new file mode 100644 index 000000000..6f4236e35 --- /dev/null +++ b/examples/datadogagent/datadog-agent-with-otel-agent.yaml @@ -0,0 +1,48 @@ +apiVersion: datadoghq.com/v2alpha1 +kind: DatadogAgent +metadata: + name: datadog +spec: + global: + credentials: + apiKey: + features: + otelCollector: + enabled: true + ports: + - containerPort: 4317 + name: otel-grpc + - containerPort: 4318 + name: otel-http + conf: + configData: |- + receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + exporters: + debug: + verbosity: detailed + datadog: + api: + key: ${env:DD_API_KEY} + processors: + batch: + connectors: + service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [datadog] + metrics: + receivers: [otlp] + processors: [batch] + exporters: [datadog] + logs: + receivers: [otlp] + processors: [batch] + exporters: [datadog] diff --git a/internal/controller/datadogagent/component/agent/default.go b/internal/controller/datadogagent/component/agent/default.go index f8ba73281..1461f4b4b 100644 --- a/internal/controller/datadogagent/component/agent/default.go +++ b/internal/controller/datadogagent/component/agent/default.go @@ -104,6 +104,12 @@ func agentImage() string { return fmt.Sprintf("%s/%s:%s", v2alpha1.DefaultImageRegistry, v2alpha1.DefaultAgentImageName, defaulting.AgentLatestVersion) } +func otelAgentImage() string { + // todo(mackjmr): make this dynamic once we have otel agent image which releases with regular agent. + return fmt.Sprintf("%s:%s", defaulting.AgentDevImageName, defaulting.OTelAgentNightlyTag) + +} + func initContainers(dda metav1.Object, requiredContainers []apicommon.AgentContainerName) []corev1.Container { initContainers := []corev1.Container{ initVolumeContainer(), @@ -201,25 +207,30 @@ func processAgentContainer(dda metav1.Object) corev1.Container { } } -func otelAgentContainer(dda metav1.Object) corev1.Container { +func otelAgentContainer(_ metav1.Object) corev1.Container { return corev1.Container{ Name: string(apicommon.OtelAgent), - Image: agentImage(), + Image: otelAgentImage(), Command: []string{ - "/otel-agent", - fmt.Sprintf("--config=%s", v2alpha1.OtelCustomConfigVolumePath), + "otel-agent", + "--config=" + v2alpha1.OtelCustomConfigVolumePath, + "--core-config=" + v2alpha1.AgentCustomConfigVolumePath, + "--sync-delay=30s", }, - Env: envVarsForOtelAgent(dda), + Env: []corev1.EnvVar{}, VolumeMounts: volumeMountsForOtelAgent(), + // todo(mackjmr): remove once support for annotations is removed. + // the otel-agent feature adds these ports if none are supplied by + // the user. Ports: []corev1.ContainerPort{ { - Name: "grpc", + Name: "otel-grpc", ContainerPort: 4317, HostPort: 4317, Protocol: corev1.ProtocolTCP, }, { - Name: "http", + Name: "otel-http", ContainerPort: 4318, HostPort: 4318, Protocol: corev1.ProtocolTCP, @@ -397,14 +408,6 @@ func envVarsForSecurityAgent(dda metav1.Object) []corev1.EnvVar { return append(envs, commonEnvVars(dda)...) } -func envVarsForOtelAgent(dda metav1.Object) []corev1.EnvVar { - envs := []corev1.EnvVar{ - // TODO: add additional env vars here - } - - return append(envs, commonEnvVars(dda)...) -} - func volumeMountsForInitConfig() []corev1.VolumeMount { return []corev1.VolumeMount{ common.GetVolumeMountForLogs(), @@ -507,13 +510,9 @@ func volumeMountsForSeccompSetup() []corev1.VolumeMount { func volumeMountsForOtelAgent() []corev1.VolumeMount { return []corev1.VolumeMount{ - // TODO: add/remove volume mounts common.GetVolumeMountForLogs(), - common.GetVolumeMountForAuth(true), common.GetVolumeMountForConfig(), - common.GetVolumeMountForDogstatsdSocket(false), - common.GetVolumeMountForRuntimeSocket(true), - common.GetVolumeMountForProc(), + common.GetVolumeMountForAuth(true), } } diff --git a/internal/controller/datadogagent/controller.go b/internal/controller/datadogagent/controller.go index d498e6bef..7c29bdd31 100644 --- a/internal/controller/datadogagent/controller.go +++ b/internal/controller/datadogagent/controller.go @@ -42,6 +42,7 @@ import ( _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/npm" _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/oomkill" _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/orchestratorexplorer" + _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otelcollector" _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otlp" _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/processdiscovery" _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/prometheusscrape" @@ -63,7 +64,6 @@ type ReconcilerOptions struct { OperatorMetricsEnabled bool IntrospectionEnabled bool DatadogAgentProfileEnabled bool - OtelAgentEnabled bool } // Reconciler is the internal reconciler for Datadog Agent @@ -107,7 +107,6 @@ func reconcilerOptionsToFeatureOptions(opts *ReconcilerOptions, logger logr.Logg return &feature.Options{ SupportExtendedDaemonset: opts.ExtendedDaemonsetOptions.Enabled, Logger: logger, - OtelAgentEnabled: opts.OtelAgentEnabled, } } diff --git a/internal/controller/datadogagent/feature/enabledefault/feature.go b/internal/controller/datadogagent/feature/enabledefault/feature.go index f7e8a7b72..8532429f6 100644 --- a/internal/controller/datadogagent/feature/enabledefault/feature.go +++ b/internal/controller/datadogagent/feature/enabledefault/feature.go @@ -52,7 +52,6 @@ func buildDefaultFeature(options *feature.Options) feature.Feature { if options != nil { dF.logger = options.Logger - dF.otelAgentEnabled = options.OtelAgentEnabled } return dF @@ -68,7 +67,6 @@ type defaultFeature struct { clusterChecksRunner clusterChecksRunnerConfig logger logr.Logger disableNonResourceRules bool - otelAgentEnabled bool adpEnabled bool customConfigAnnotationKey string @@ -134,10 +132,6 @@ func (f *defaultFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredC f.agent.serviceAccountAnnotations = v2alpha1.GetAgentServiceAccountAnnotations(dda) f.clusterChecksRunner.serviceAccountAnnotations = v2alpha1.GetClusterChecksRunnerServiceAccountAnnotations(dda) - if dda.ObjectMeta.Annotations != nil { - f.otelAgentEnabled = f.otelAgentEnabled || featureutils.HasOtelAgentAnnotation(dda) - } - if dda.ObjectMeta.Annotations != nil { f.adpEnabled = featureutils.HasAgentDataPlaneAnnotation(dda) } @@ -216,7 +210,7 @@ func (f *defaultFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredC // feature. // // NOTE: This is a temporary solution until the OTel Agent is fully integrated into the Operator via a dedicated feature. - if f.otelAgentEnabled { + if dda.ObjectMeta.Annotations != nil && featureutils.HasOtelAgentAnnotation(dda) { agentContainers = append(agentContainers, apicommon.OtelAgent) } diff --git a/internal/controller/datadogagent/feature/ids.go b/internal/controller/datadogagent/feature/ids.go index 812a00a7b..b395d720d 100644 --- a/internal/controller/datadogagent/feature/ids.go +++ b/internal/controller/datadogagent/feature/ids.go @@ -25,6 +25,8 @@ const ( LiveContainerIDType = "live_container" // LiveProcessIDType Live Process feature. LiveProcessIDType = "live_process" + // OtelAgentIDType Otel Agent feature. + OtelAgentIDType = "otel_agent" // ProcessDiscoveryIDType Process Discovery feature. ProcessDiscoveryIDType = "process_discovery" // KubernetesAPIServerIDType Kube APIServer feature. diff --git a/internal/controller/datadogagent/feature/otelcollector/configmap_test.go b/internal/controller/datadogagent/feature/otelcollector/configmap_test.go new file mode 100644 index 000000000..3115aadcb --- /dev/null +++ b/internal/controller/datadogagent/feature/otelcollector/configmap_test.go @@ -0,0 +1,43 @@ +// 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 otelcollector + +import ( + "testing" + + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otelcollector/defaultconfig" + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func Test_buildOtelCollectorConfigMap(t *testing.T) { + // check config map + configMapWant := &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "-otel-agent-config", + }, + Data: map[string]string{ + "otel-config.yaml": defaultconfig.DefaultOtelCollectorConfig, + }, + } + + otelCollectorFeature, ok := buildOtelCollectorFeature(&feature.Options{}).(*otelCollectorFeature) + assert.True(t, ok) + + otelCollectorFeature.owner = &metav1.ObjectMeta{ + Name: "-otel-agent-config", + } + otelCollectorFeature.configMapName = "-otel-agent-config" + otelCollectorFeature.customConfig = &v2alpha1.CustomConfig{} + otelCollectorFeature.customConfig.ConfigData = &defaultconfig.DefaultOtelCollectorConfig + + configMap, err := otelCollectorFeature.buildOTelAgentCoreConfigMap() + assert.NoError(t, err) + assert.Equal(t, configMapWant, configMap) +} diff --git a/internal/controller/datadogagent/feature/otelcollector/defaultconfig/defaultconfig.go b/internal/controller/datadogagent/feature/otelcollector/defaultconfig/defaultconfig.go new file mode 100644 index 000000000..5ec9362ee --- /dev/null +++ b/internal/controller/datadogagent/feature/otelcollector/defaultconfig/defaultconfig.go @@ -0,0 +1,49 @@ +// package defaultconfig exposes the otel-agent default config +package defaultconfig + +var DefaultOtelCollectorConfig = ` +receivers: + prometheus: + config: + scrape_configs: + - job_name: "otelcol" + scrape_interval: 10s + static_configs: + - targets: ["0.0.0.0:8888"] + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 +exporters: + debug: + verbosity: detailed + datadog: + api: + key: "" +processors: + infraattributes: + cardinality: 2 + batch: + timeout: 10s +connectors: + datadog/connector: + traces: + compute_top_level_by_span_kind: true + peer_tags_aggregation: true + compute_stats_by_span_kind: true +service: + pipelines: + traces: + receivers: [otlp] + processors: [infraattributes, batch] + exporters: [datadog, datadog/connector] + metrics: + receivers: [otlp, datadog/connector, prometheus] + processors: [infraattributes, batch] + exporters: [datadog] + logs: + receivers: [otlp] + processors: [infraattributes, batch] + exporters: [datadog]` diff --git a/internal/controller/datadogagent/feature/otelcollector/feature.go b/internal/controller/datadogagent/feature/otelcollector/feature.go new file mode 100644 index 000000000..8c091d963 --- /dev/null +++ b/internal/controller/datadogagent/feature/otelcollector/feature.go @@ -0,0 +1,212 @@ +package otelcollector + +import ( + "strconv" + "strings" + + apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" + apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otelcollector/defaultconfig" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/configmap" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/kubernetes" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + otelAgentVolumeName = "otel-agent-config-volume" + otelConfigFileName = "otel-config.yaml" +) + +func init() { + err := feature.Register(feature.OtelAgentIDType, buildOtelCollectorFeature) + if err != nil { + panic(err) + } +} + +func buildOtelCollectorFeature(options *feature.Options) feature.Feature { + return &otelCollectorFeature{} +} + +type otelCollectorFeature struct { + customConfig *v2alpha1.CustomConfig + owner metav1.Object + configMapName string + ports []*corev1.ContainerPort + coreAgentConfig coreAgentConfig +} + +type coreAgentConfig struct { + extension_timeout *int + extension_url *string + enabled *bool +} + +func (o otelCollectorFeature) ID() feature.IDType { + return feature.OtelAgentIDType +} + +func (o *otelCollectorFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredComponents { + o.owner = dda + if dda.Spec.Features.OtelCollector.Conf != nil { + o.customConfig = dda.Spec.Features.OtelCollector.Conf + } + o.configMapName = v2alpha1.GetConfName(dda, o.customConfig, v2alpha1.DefaultOTelAgentConf) + + if dda.Spec.Features.OtelCollector.CoreConfig != nil { + o.coreAgentConfig.enabled = dda.Spec.Features.OtelCollector.CoreConfig.Enabled + o.coreAgentConfig.extension_timeout = dda.Spec.Features.OtelCollector.CoreConfig.ExtensionTimeout + o.coreAgentConfig.extension_url = dda.Spec.Features.OtelCollector.CoreConfig.ExtensionURL + } + + if len(dda.Spec.Features.OtelCollector.Ports) == 0 { + o.ports = []*corev1.ContainerPort{ + { + Name: "otel-http", + ContainerPort: 4318, + HostPort: 4318, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "otel-grpc", + ContainerPort: 4317, + HostPort: 4317, + Protocol: corev1.ProtocolTCP, + }, + } + } else { + o.ports = dda.Spec.Features.OtelCollector.Ports + } + + var reqComp feature.RequiredComponents + if apiutils.BoolValue(dda.Spec.Features.OtelCollector.Enabled) { + reqComp = feature.RequiredComponents{ + Agent: feature.RequiredComponent{ + IsRequired: apiutils.NewBoolPointer(true), + Containers: []apicommon.AgentContainerName{ + apicommon.CoreAgentContainerName, + apicommon.OtelAgent, + }, + }, + } + + } + return reqComp +} + +func (o *otelCollectorFeature) buildOTelAgentCoreConfigMap() (*corev1.ConfigMap, error) { + if o.customConfig != nil && o.customConfig.ConfigData != nil { + return configmap.BuildConfigMapConfigData(o.owner.GetNamespace(), o.customConfig.ConfigData, o.configMapName, otelConfigFileName) + } + return nil, nil +} + +func (o otelCollectorFeature) ManageDependencies(managers feature.ResourceManagers, components feature.RequiredComponents) error { + // check if an otel collector config was provided. If not, use default. + if o.customConfig == nil { + o.customConfig = &v2alpha1.CustomConfig{} + } + if o.customConfig.ConfigData == nil && o.customConfig.ConfigMap == nil { + var defaultConfig = defaultconfig.DefaultOtelCollectorConfig + for _, port := range o.ports { + if port.Name == "otel-grpc" { + defaultConfig = strings.Replace(defaultConfig, "4317", strconv.Itoa(int(port.ContainerPort)), 1) + } + if port.Name == "otel-http" { + defaultConfig = strings.Replace(defaultConfig, "4318", strconv.Itoa(int(port.ContainerPort)), 1) + } + } + o.customConfig.ConfigData = &defaultConfig + } + + // create configMap if customConfig is provided + configMap, err := o.buildOTelAgentCoreConfigMap() + if err != nil { + return err + } + + if configMap != nil { + if err := managers.Store().AddOrUpdate(kubernetes.ConfigMapKind, configMap); err != nil { + return err + } + } + return nil +} + +func (o otelCollectorFeature) ManageClusterAgent(managers feature.PodTemplateManagers) error { + return nil +} + +func (o otelCollectorFeature) ManageNodeAgent(managers feature.PodTemplateManagers, provider string) error { + var vol corev1.Volume + if o.customConfig != nil && o.customConfig.ConfigMap != nil { + // Custom config is referenced via ConfigMap + vol = volume.GetVolumeFromConfigMap( + o.customConfig.ConfigMap, + o.configMapName, + otelAgentVolumeName, + ) + } else { + // Otherwise, configMap was created in ManageDependencies (whether from CustomConfig.ConfigData or using defaults, so mount default volume) + vol = volume.GetBasicVolume(o.configMapName, otelAgentVolumeName) + } + + // create volume + managers.Volume().AddVolume(&vol) + + // [investigation needed]: When the user provides a custom config map, the file name *must be* otel-config.yaml. If we choose to allow + // any file name, we would need to update both the volume mount here, as well as the otel-agent container command. I haven't seen this + // done for other containers, which is why I think it's acceptable to force users to use the `otel-config.yaml` name. + volMount := volume.GetVolumeMountWithSubPath(otelAgentVolumeName, v2alpha1.ConfigVolumePath+"/"+otelConfigFileName, otelConfigFileName) + managers.VolumeMount().AddVolumeMountToContainer(&volMount, apicommon.OtelAgent) + + // add ports + for _, port := range o.ports { + // bind container port to host port. + port.HostPort = port.ContainerPort + managers.Port().AddPortToContainer(apicommon.OtelAgent, port) + } + + var enableEnvVar *corev1.EnvVar + if o.coreAgentConfig.enabled != nil { + if *o.coreAgentConfig.enabled { + // only need to set env var if true, as it will default to false. + enableEnvVar = &corev1.EnvVar{ + Name: v2alpha1.DDOtelCollectorCoreConfigEnabled, + Value: apiutils.BoolToString(o.coreAgentConfig.enabled), + } + managers.EnvVar().AddEnvVarToContainers([]apicommon.AgentContainerName{apicommon.CoreAgentContainerName}, enableEnvVar) + } + } else { + managers.EnvVar().AddEnvVarToContainers([]apicommon.AgentContainerName{apicommon.CoreAgentContainerName}, &corev1.EnvVar{ + Name: v2alpha1.DDOtelCollectorCoreConfigEnabled, + Value: "true", + }) + } + + if o.coreAgentConfig.extension_timeout != nil { + managers.EnvVar().AddEnvVarToContainers([]apicommon.AgentContainerName{apicommon.CoreAgentContainerName}, &corev1.EnvVar{ + Name: v2alpha1.DDOtelCollectorCoreConfigExtensionTimeout, + Value: strconv.Itoa(*o.coreAgentConfig.extension_timeout), + }) + } + if o.coreAgentConfig.extension_url != nil { + managers.EnvVar().AddEnvVarToContainers([]apicommon.AgentContainerName{apicommon.CoreAgentContainerName}, &corev1.EnvVar{ + Name: v2alpha1.DDOtelCollectorCoreConfigExtensionURL, + Value: *o.coreAgentConfig.extension_url, + }) + } + return nil +} + +func (o otelCollectorFeature) ManageSingleContainerNodeAgent(managers feature.PodTemplateManagers, provider string) error { + return nil +} + +func (o otelCollectorFeature) ManageClusterChecksRunner(managers feature.PodTemplateManagers) error { + return nil +} diff --git a/internal/controller/datadogagent/feature/otelcollector/feature_test.go b/internal/controller/datadogagent/feature/otelcollector/feature_test.go new file mode 100644 index 000000000..93843b2e6 --- /dev/null +++ b/internal/controller/datadogagent/feature/otelcollector/feature_test.go @@ -0,0 +1,322 @@ +package otelcollector + +import ( + "strings" + "testing" + + apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" + v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" + apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otelcollector/defaultconfig" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" + "github.com/DataDog/datadog-operator/pkg/kubernetes" + + "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" +) + +type expectedPorts struct { + httpPort int32 + grpcPort int32 +} + +type expectedEnvVars struct { + enabled expectedEnvVar + extension_timeout expectedEnvVar + extension_url expectedEnvVar +} + +type expectedEnvVar struct { + present bool + value string +} + +var ( + defaultExpectedPorts = expectedPorts{ + httpPort: 4318, + grpcPort: 4317, + } + defaultLocalObjectReferenceName = "-otel-agent-config" + defaultExpectedEnvVars = expectedEnvVars{ + enabled: expectedEnvVar{ + present: true, + value: "true", + }, + extension_timeout: expectedEnvVar{}, + extension_url: expectedEnvVar{}, + } +) + +func Test_otelCollectorFeature_Configure(t *testing.T) { + tests := test.FeatureTestSuite{ + // disabled + { + Name: "otel agent disabled without config", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(false). + Build(), + WantConfigure: false, + }, + { + Name: "otel agent disabled with config", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(false). + WithOTelCollectorConfig(). + Build(), + WantConfigure: false, + }, + // enabled + { + Name: "otel agent enabled with config", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + WithOTelCollectorConfig(). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, defaultExpectedPorts, defaultLocalObjectReferenceName, defaultExpectedEnvVars), + }, + { + Name: "otel agent enabled with configMap", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + WithOTelCollectorConfigMap(). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, defaultExpectedPorts, "user-provided-config-map", defaultExpectedEnvVars), + }, + { + Name: "otel agent enabled without config", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, defaultExpectedPorts, defaultLocalObjectReferenceName, defaultExpectedEnvVars), + }, + { + Name: "otel agent enabled without config non default ports", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + WithOTelCollectorPorts(4444, 5555). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, expectedPorts{ + grpcPort: 4444, + httpPort: 5555, + }, + defaultLocalObjectReferenceName, + defaultExpectedEnvVars, + ), + }, + // coreconfig + { + Name: "otel agent coreconfig enabled", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + WithOTelCollectorCoreConfigEnabled(true). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, defaultExpectedPorts, defaultLocalObjectReferenceName, defaultExpectedEnvVars), + }, + { + Name: "otel agent coreconfig disabled", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + WithOTelCollectorCoreConfigEnabled(false). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, defaultExpectedPorts, defaultLocalObjectReferenceName, expectedEnvVars{}), + }, + { + Name: "otel agent coreconfig extensionTimeout", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + WithOTelCollectorCoreConfigEnabled(false). + WithOTelCollectorCoreConfigExtensionTimeout(13). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, defaultExpectedPorts, defaultLocalObjectReferenceName, expectedEnvVars{ + extension_timeout: expectedEnvVar{ + present: true, + value: "13", + }, + }), + }, + { + Name: "otel agent coreconfig extensionURL", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + WithOTelCollectorCoreConfigEnabled(false). + WithOTelCollectorCoreConfigExtensionURL("https://localhost:1234"). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, defaultExpectedPorts, defaultLocalObjectReferenceName, expectedEnvVars{ + extension_url: expectedEnvVar{ + present: true, + value: "https://localhost:1234", + }, + }), + }, + { + Name: "otel agent coreconfig all env vars", + DDA: v2alpha1test.NewDatadogAgentBuilder(). + WithOTelCollectorEnabled(true). + WithOTelCollectorCoreConfigEnabled(true). + WithOTelCollectorCoreConfigExtensionTimeout(13). + WithOTelCollectorCoreConfigExtensionURL("https://localhost:1234"). + Build(), + WantConfigure: true, + WantDependenciesFunc: testExpectedDepsCreatedCM, + Agent: testExpectedAgent(apicommon.OtelAgent, defaultExpectedPorts, defaultLocalObjectReferenceName, expectedEnvVars{ + extension_url: expectedEnvVar{ + present: true, + value: "https://localhost:1234", + }, + extension_timeout: expectedEnvVar{ + present: true, + value: "13", + }, + enabled: expectedEnvVar{ + present: true, + value: "true", + }, + }), + }, + } + tests.Run(t, buildOtelCollectorFeature) +} + +func testExpectedAgent(agentContainerName apicommon.AgentContainerName, expectedPorts expectedPorts, localObjectReferenceName string, expectedEnvVars expectedEnvVars) *test.ComponentTest { + return test.NewDefaultComponentTest().WithWantFunc( + func(t testing.TB, mgrInterface feature.PodTemplateManagers) { + mgr := mgrInterface.(*fake.PodTemplateManagers) + // check volume mounts + wantVolumeMounts := []corev1.VolumeMount{ + { + Name: otelAgentVolumeName, + MountPath: v2alpha1.ConfigVolumePath + "/" + otelConfigFileName, + SubPath: otelConfigFileName, + ReadOnly: true, + }, + } + + agentMounts := mgr.VolumeMountMgr.VolumeMountsByC[agentContainerName] + assert.True(t, apiutils.IsEqualStruct(agentMounts, wantVolumeMounts), "%s volume mounts \ndiff = %s", agentContainerName, cmp.Diff(agentMounts, wantVolumeMounts)) + + // check volumes "otel-agent-config" + wantVolumes := []corev1.Volume{ + { + Name: otelAgentVolumeName, + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: localObjectReferenceName, + }, + }, + }, + }, + } + + volumes := mgr.VolumeMgr.Volumes + assert.True(t, apiutils.IsEqualStruct(volumes, wantVolumes), "Volumes \ndiff = %s", cmp.Diff(volumes, wantVolumes)) + + // check ports + wantPorts := []*corev1.ContainerPort{ + { + Name: "otel-http", + ContainerPort: expectedPorts.httpPort, + HostPort: expectedPorts.httpPort, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "otel-grpc", + ContainerPort: expectedPorts.grpcPort, + HostPort: expectedPorts.grpcPort, + Protocol: corev1.ProtocolTCP, + }, + } + + ports := mgr.PortMgr.PortsByC[agentContainerName] + assert.Equal(t, wantPorts, ports) + + // check env vars + wantEnvVars := []*corev1.EnvVar{} + + if expectedEnvVars.enabled.present { + wantEnvVars = append(wantEnvVars, &corev1.EnvVar{ + Name: v2alpha1.DDOtelCollectorCoreConfigEnabled, + Value: expectedEnvVars.enabled.value, + }) + } + + if expectedEnvVars.extension_timeout.present { + wantEnvVars = append(wantEnvVars, &corev1.EnvVar{ + Name: v2alpha1.DDOtelCollectorCoreConfigExtensionTimeout, + Value: expectedEnvVars.extension_timeout.value, + }) + } + + if expectedEnvVars.extension_url.present { + wantEnvVars = append(wantEnvVars, &corev1.EnvVar{ + Name: v2alpha1.DDOtelCollectorCoreConfigExtensionURL, + Value: expectedEnvVars.extension_url.value, + }) + } + + if len(wantEnvVars) == 0 { + wantEnvVars = nil + } + + agentEnvVars := mgr.EnvVarMgr.EnvVarsByC[apicommon.CoreAgentContainerName] + assert.True(t, apiutils.IsEqualStruct(agentEnvVars, wantEnvVars), "Agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, wantEnvVars)) + + }, + ) +} + +func testExpectedDepsCreatedCM(t testing.TB, store store.StoreClient) { + // hacky to need to hardcode test name but unaware of a better approach that doesn't require + // modifying WantDependenciesFunc definition. + if t.Name() == "Test_otelCollectorFeature_Configure/otel_agent_enabled_with_configMap" { + // configMap is provided by user, no need to create it. + _, found := store.Get(kubernetes.ConfigMapKind, "", "-otel-agent-config") + assert.False(t, found) + return + } + configMapObject, found := store.Get(kubernetes.ConfigMapKind, "", "-otel-agent-config") + assert.True(t, found) + + configMap := configMapObject.(*corev1.ConfigMap) + expectedCM := map[string]string{ + "otel-config.yaml": defaultconfig.DefaultOtelCollectorConfig} + + // validate that default ports were overriden by user provided ports in default config. hacky to need to + // hardcode test name but unaware of a better approach that doesn't require modifying WantDependenciesFunc definition. + if t.Name() == "Test_otelCollectorFeature_Configure/otel_agent_enabled_without_config_non_default_ports" { + expectedCM["otel-config.yaml"] = strings.Replace(expectedCM["otel-config.yaml"], "4317", "4444", 1) + expectedCM["otel-config.yaml"] = strings.Replace(expectedCM["otel-config.yaml"], "4318", "5555", 1) + assert.True( + t, + apiutils.IsEqualStruct(configMap.Data, expectedCM), + "ConfigMap \ndiff = %s", cmp.Diff(configMap.Data, expectedCM), + ) + return + } + assert.True( + t, + apiutils.IsEqualStruct(configMap.Data, expectedCM), + "ConfigMap \ndiff = %s", cmp.Diff(configMap.Data, expectedCM), + ) +} diff --git a/internal/controller/datadogagent/feature/test/factory_test.go b/internal/controller/datadogagent/feature/test/factory_test.go index 0ef867e9d..0fd469644 100644 --- a/internal/controller/datadogagent/feature/test/factory_test.go +++ b/internal/controller/datadogagent/feature/test/factory_test.go @@ -14,6 +14,7 @@ import ( _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/enabledefault" _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/livecontainer" _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/npm" + _ "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otelcollector" ) func TestBuilder(t *testing.T) { @@ -200,9 +201,57 @@ func TestBuilder(t *testing.T) { dda: v2alpha1test.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "false"}). BuildWithDefaults(), - featureOptions: feature.Options{ - OtelAgentEnabled: true, + wantAgentContainer: map[common.AgentContainerName]bool{ + common.UnprivilegedSingleAgentContainerName: false, + common.CoreAgentContainerName: true, + common.ProcessAgentContainerName: true, + common.TraceAgentContainerName: true, + common.SystemProbeContainerName: false, + common.SecurityAgentContainerName: false, + common.OtelAgent: false, + common.AgentDataPlaneContainerName: false, + }, + }, + { + name: "Default DDA, otel annotation false, otel collector feature enabled", + dda: v2alpha1test.NewDatadogAgentBuilder(). + WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "false"}). + WithOTelCollectorEnabled(true). + BuildWithDefaults(), + wantAgentContainer: map[common.AgentContainerName]bool{ + common.UnprivilegedSingleAgentContainerName: false, + common.CoreAgentContainerName: true, + common.ProcessAgentContainerName: true, + common.TraceAgentContainerName: true, + common.SystemProbeContainerName: false, + common.SecurityAgentContainerName: false, + common.OtelAgent: true, + common.AgentDataPlaneContainerName: false, + }, + }, + { + name: "Default DDA, otel annotation true, otel collector feature disabled", + dda: v2alpha1test.NewDatadogAgentBuilder(). + WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "true"}). + WithOTelCollectorEnabled(false). + BuildWithDefaults(), + wantAgentContainer: map[common.AgentContainerName]bool{ + common.UnprivilegedSingleAgentContainerName: false, + common.CoreAgentContainerName: true, + common.ProcessAgentContainerName: true, + common.TraceAgentContainerName: true, + common.SystemProbeContainerName: false, + common.SecurityAgentContainerName: false, + common.OtelAgent: true, + common.AgentDataPlaneContainerName: false, }, + }, + { + name: "Default DDA, otel annotation true, otel collector feature enabled", + dda: v2alpha1test.NewDatadogAgentBuilder(). + WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "true"}). + WithOTelCollectorEnabled(true). + BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ common.UnprivilegedSingleAgentContainerName: false, common.CoreAgentContainerName: true, diff --git a/internal/controller/datadogagent/feature/types.go b/internal/controller/datadogagent/feature/types.go index 04767246d..c0d34f177 100644 --- a/internal/controller/datadogagent/feature/types.go +++ b/internal/controller/datadogagent/feature/types.go @@ -150,8 +150,6 @@ type Options struct { SupportExtendedDaemonset bool Logger logr.Logger - - OtelAgentEnabled bool } // BuildFunc function type used by each Feature during its factory registration. diff --git a/internal/controller/setup.go b/internal/controller/setup.go index b7e580fc9..7f3eef8af 100644 --- a/internal/controller/setup.go +++ b/internal/controller/setup.go @@ -47,7 +47,6 @@ type SetupOptions struct { V2APIEnabled bool IntrospectionEnabled bool DatadogAgentProfileEnabled bool - OtelAgentEnabled bool DatadogDashboardEnabled bool } @@ -160,7 +159,6 @@ func startDatadogAgent(logger logr.Logger, mgr manager.Manager, pInfo kubernetes OperatorMetricsEnabled: options.OperatorMetricsEnabled, IntrospectionEnabled: options.IntrospectionEnabled, DatadogAgentProfileEnabled: options.DatadogAgentProfileEnabled, - OtelAgentEnabled: options.OtelAgentEnabled, }, }).SetupWithManager(mgr, metricForwardersMgr) } diff --git a/pkg/defaulting/images.go b/pkg/defaulting/images.go index 1e1a7b37c..70fcdebb0 100644 --- a/pkg/defaulting/images.go +++ b/pkg/defaulting/images.go @@ -30,7 +30,10 @@ const ( // DefaultImageRegistry corresponds to the datadoghq containers registry DefaultImageRegistry = GCRContainerRegistry // TODO: this is also defined elsewhere and not used; consolidate // JMXTagSuffix prefix tag for agent JMX images - JMXTagSuffix = "-jmx" + JMXTagSuffix = "-jmx" + AgentDevImageName = "datadog/agent-dev" + // Nightly dev image tag for otel agent + OTelAgentNightlyTag = "nightly-ot-beta-main" agentImageName = "agent" clusterAgentImageName = "cluster-agent" From efaa4e9634cf3c89658d903f4332a40f7f6b2696 Mon Sep 17 00:00:00 2001 From: khewonc <39867936+khewonc@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:08:02 -0500 Subject: [PATCH 6/8] Remove kube-rbac-proxy image (#1551) * Remove kube-rbac-proxy image * Run verify-licenses --- LICENSE-3rdparty.csv | 28 ++++++++++++- cmd/main.go | 22 ++++++++--- config/default/kustomization.yaml | 11 ++++-- config/default/manager_auth_proxy_patch.yaml | 25 ------------ config/default/manager_metrics_patch.yaml | 4 ++ .../metrics_service.yaml} | 3 +- config/manager/manager.yaml | 1 + .../rbac/auth_proxy_client_clusterrole.yaml | 7 ---- config/rbac/kustomization.yaml | 14 +++---- ...proxy_role.yaml => metrics_auth_role.yaml} | 14 ++++--- ...ng.yaml => metrics_auth_role_binding.yaml} | 6 +-- config/rbac/metrics_reader_role.yaml | 9 +++++ config/test-v1/kustomization.yaml | 5 --- config/test-v1/manager_auth_proxy_patch.yaml | 25 ------------ go.mod | 19 +++++++++ go.sum | 39 +++++++++++++++++++ 16 files changed, 143 insertions(+), 89 deletions(-) delete mode 100644 config/default/manager_auth_proxy_patch.yaml create mode 100644 config/default/manager_metrics_patch.yaml rename config/{rbac/auth_proxy_service.yaml => default/metrics_service.yaml} (86%) delete mode 100644 config/rbac/auth_proxy_client_clusterrole.yaml rename config/rbac/{auth_proxy_role.yaml => metrics_auth_role.yaml} (50%) rename config/rbac/{auth_proxy_role_binding.yaml => metrics_auth_role_binding.yaml} (69%) create mode 100644 config/rbac/metrics_reader_role.yaml delete mode 100644 config/test-v1/manager_auth_proxy_patch.yaml diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 074c2d407..12a5345a8 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -25,9 +25,13 @@ core,github.com/DataDog/viper,MIT core,github.com/DataDog/zstd,BSD-3-Clause core,github.com/Masterminds/semver,MIT core,github.com/Masterminds/semver/v3,MIT +core,github.com/antlr4-go/antlr/v4,BSD-3-Clause +core,github.com/asaskevich/govalidator,MIT core,github.com/benbjohnson/clock,MIT core,github.com/beorn7/perks/quantile,MIT +core,github.com/blang/semver/v4,MIT core,github.com/cenkalti/backoff,MIT +core,github.com/cenkalti/backoff/v4,MIT core,github.com/cespare/xxhash/v2,MIT core,github.com/cihub/seelog,BSD-3-Clause core,github.com/davecgh/go-spew/spew,ISC @@ -35,9 +39,11 @@ core,github.com/dustin/go-humanize,MIT core,github.com/ebitengine/purego,Apache-2.0 core,github.com/emicklei/go-restful/v3,MIT core,github.com/evanphx/json-patch/v5,BSD-3-Clause +core,github.com/felixge/httpsnoop,MIT core,github.com/fsnotify/fsnotify,BSD-3-Clause core,github.com/fxamacker/cbor/v2,MIT core,github.com/go-logr/logr,Apache-2.0 +core,github.com/go-logr/stdr,Apache-2.0 core,github.com/go-logr/zapr,Apache-2.0 core,github.com/go-openapi/jsonpointer,Apache-2.0 core,github.com/go-openapi/jsonreference,Apache-2.0 @@ -46,6 +52,7 @@ core,github.com/gobwas/glob,MIT core,github.com/gogo/protobuf,BSD-3-Clause core,github.com/golang/groupcache/lru,Apache-2.0 core,github.com/golang/protobuf,BSD-3-Clause +core,github.com/google/cel-go,Apache-2.0 core,github.com/google/gnostic-models,Apache-2.0 core,github.com/google/go-cmp/cmp,BSD-3-Clause core,github.com/google/gofuzz,Apache-2.0 @@ -53,6 +60,7 @@ core,github.com/google/pprof/profile,Apache-2.0 core,github.com/google/uuid,BSD-3-Clause core,github.com/grpc-ecosystem/go-grpc-middleware,Apache-2.0 core,github.com/grpc-ecosystem/grpc-gateway,BSD-3-Clause +core,github.com/grpc-ecosystem/grpc-gateway/v2,BSD-3-Clause core,github.com/hashicorp/hcl,MPL-2.0 core,github.com/imdario/mergo,BSD-3-Clause core,github.com/josharian/intern,MIT @@ -83,14 +91,24 @@ core,github.com/shirou/gopsutil/v3,BSD-3-Clause core,github.com/spaolacci/murmur3,BSD-3-Clause core,github.com/spf13/afero,Apache-2.0 core,github.com/spf13/cast,MIT +core,github.com/spf13/cobra,Apache-2.0 core,github.com/spf13/jwalterweatherman,MIT core,github.com/spf13/pflag,BSD-3-Clause +core,github.com/stoewer/go-strcase,MIT core,github.com/stretchr/objx,MIT core,github.com/stretchr/testify,MIT core,github.com/tinylib/msgp/msgp,MIT core,github.com/x448/float16,MIT core,github.com/zorkian/go-datadog-api,BSD-3-Clause core,go.etcd.io/bbolt,MIT +core,go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp,Apache-2.0 +core,go.opentelemetry.io/otel,Apache-2.0 +core,go.opentelemetry.io/otel/exporters/otlp/otlptrace,Apache-2.0 +core,go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc,Apache-2.0 +core,go.opentelemetry.io/otel/metric,Apache-2.0 +core,go.opentelemetry.io/otel/sdk,Apache-2.0 +core,go.opentelemetry.io/otel/trace,Apache-2.0 +core,go.opentelemetry.io/proto/otlp,Apache-2.0 core,go.uber.org/atomic,MIT core,go.uber.org/multierr,MIT core,go.uber.org/zap,MIT @@ -98,6 +116,7 @@ core,golang.org/x/exp,BSD-3-Clause core,golang.org/x/mod/semver,BSD-3-Clause core,golang.org/x/net,BSD-3-Clause core,golang.org/x/oauth2,BSD-3-Clause +core,golang.org/x/sync/singleflight,BSD-3-Clause core,golang.org/x/sys/unix,BSD-3-Clause core,golang.org/x/term,BSD-3-Clause core,golang.org/x/text,BSD-3-Clause @@ -105,7 +124,7 @@ core,golang.org/x/time/rate,BSD-3-Clause core,golang.org/x/xerrors,BSD-3-Clause core,gomodules.xyz/jsonpatch/v2,Apache-2.0 core,google.golang.org/genproto/googleapis/api,Apache-2.0 -core,google.golang.org/genproto/googleapis/rpc/status,Apache-2.0 +core,google.golang.org/genproto/googleapis/rpc,Apache-2.0 core,google.golang.org/genproto/protobuf/field_mask,Apache-2.0 core,google.golang.org/grpc,Apache-2.0 core,google.golang.org/protobuf,BSD-3-Clause @@ -117,14 +136,19 @@ core,k8s.io/api,Apache-2.0 core,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions,Apache-2.0 core,k8s.io/apimachinery/pkg,Apache-2.0 core,k8s.io/apimachinery/third_party/forked/golang,BSD-3-Clause +core,k8s.io/apiserver,Apache-2.0 core,k8s.io/client-go,Apache-2.0 +core,k8s.io/component-base,Apache-2.0 core,k8s.io/klog/v2,Apache-2.0 core,k8s.io/kube-aggregator/pkg/apis/apiregistration,Apache-2.0 core,k8s.io/kube-openapi/pkg,Apache-2.0 core,k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json,BSD-3-Clause +core,k8s.io/kube-openapi/pkg/validation/errors,Apache-2.0 core,k8s.io/kube-openapi/pkg/validation/spec,Apache-2.0 +core,k8s.io/kube-openapi/pkg/validation/strfmt,Apache-2.0 core,k8s.io/utils,Apache-2.0 -core,k8s.io/utils/internal/third_party/forked/golang/net,BSD-3-Clause +core,k8s.io/utils/internal/third_party/forked/golang,BSD-3-Clause +core,sigs.k8s.io/apiserver-network-proxy/konnectivity-client,Apache-2.0 core,sigs.k8s.io/controller-runtime,Apache-2.0 core,sigs.k8s.io/json,Apache-2.0 core,sigs.k8s.io/structured-merge-diff/v4,Apache-2.0 diff --git a/cmd/main.go b/cmd/main.go index 82201d7ad..089aa3e75 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -24,6 +24,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" ctrlzap "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/metrics/filters" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -93,6 +94,7 @@ const ( type options struct { // Observability options metricsAddr string + secureMetrics bool profilingEnabled bool logLevel *zapcore.Level logEncoder string @@ -133,6 +135,7 @@ type options struct { func (opts *options) Parse() { // Observability flags flag.StringVar(&opts.metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") + flag.BoolVar(&opts.secureMetrics, "metrics-secure", false, "If true, the metrics endpoint is served securely via HTTPS. Use false to use HTTP instead.") flag.BoolVar(&opts.profilingEnabled, "profiling-enabled", false, "Enable Datadog profile in the Datadog Operator process.") opts.logLevel = zap.LevelFlag("loglevel", zapcore.InfoLevel, "Set log level") flag.StringVar(&opts.logEncoder, "logEncoder", "json", "log encoding ('json' or 'console')") @@ -228,14 +231,23 @@ func run(opts *options) error { renewDeadline := opts.leaderElectionLeaseDuration / 2 retryPeriod := opts.leaderElectionLeaseDuration / 4 + metricsServerOptions := metricsserver.Options{ + BindAddress: opts.metricsAddr, + SecureServing: opts.secureMetrics, + ExtraHandlers: debug.GetExtraMetricHandlers(), + } + + if opts.secureMetrics { + // FilterProvider is used to protect the metrics endpoint with authn/authz. + metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization + } + restConfig := ctrl.GetConfigOrDie() restConfig.UserAgent = "datadog-operator" mgr, err := ctrl.NewManager(restConfig, ctrl.Options{ - Scheme: scheme, - Metrics: metricsserver.Options{ - BindAddress: opts.metricsAddr, - ExtraHandlers: debug.GetExtraMetricHandlers(), - }, HealthProbeBindAddress: ":8081", + Scheme: scheme, + Metrics: metricsServerOptions, + HealthProbeBindAddress: ":8081", LeaderElection: opts.enableLeaderElection, LeaderElectionID: "datadog-operator-lock", LeaderElectionResourceLock: resourcelock.LeasesResourceLock, diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 702be8701..267f62b41 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -24,12 +24,15 @@ resources: #- ../certmanager # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. #- ../prometheus +# [METRICS] Expose the controller manager metrics service. +#- metrics_service.yaml #patches: -# Protect the /metrics endpoint by putting it behind auth. -# If you want your controller-manager to expose the /metrics -# endpoint w/o any authn/z, please comment the following line. -#- path: manager_auth_proxy_patch.yaml +# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443. +# More info: https://book.kubebuilder.io/reference/metrics +#- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml #- path: manager_webhook_patch.yaml diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml deleted file mode 100644 index 02b5c2f4f..000000000 --- a/config/default/manager_auth_proxy_patch.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# This patch inject a sidecar container which is a HTTP proxy for the -# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. -apiVersion: apps/v1 -kind: Deployment -metadata: - name: manager - namespace: system -spec: - template: - spec: - containers: - - name: kube-rbac-proxy - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 - args: - - "--secure-listen-address=0.0.0.0:8443" - - "--upstream=http://127.0.0.1:8080/" - - "--logtostderr=true" - - "--v=10" - ports: - - containerPort: 8443 - name: https - - name: manager - args: - - "--metrics-addr=127.0.0.1:8080" - - "--enable-leader-election" diff --git a/config/default/manager_metrics_patch.yaml b/config/default/manager_metrics_patch.yaml new file mode 100644 index 000000000..07d1b5444 --- /dev/null +++ b/config/default/manager_metrics_patch.yaml @@ -0,0 +1,4 @@ +# This patch adds the args to allow exposing the metrics endpoint using HTTPS +- op: add + path: /spec/template/spec/containers/0/args/0 + value: --metrics-addr=:8443 diff --git a/config/rbac/auth_proxy_service.yaml b/config/default/metrics_service.yaml similarity index 86% rename from config/rbac/auth_proxy_service.yaml rename to config/default/metrics_service.yaml index 6cf656be1..ef4147424 100644 --- a/config/rbac/auth_proxy_service.yaml +++ b/config/default/metrics_service.yaml @@ -9,6 +9,7 @@ spec: ports: - name: https port: 8443 - targetPort: https + protocol: TCP + targetPort: 8443 selector: control-plane: controller-manager diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 312196f0e..9158f9cd7 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -22,6 +22,7 @@ spec: metadata: labels: app.kubernetes.io/name: datadog-operator + control-plane: controller-manager annotations: ad.datadoghq.com/manager.check_names: '["openmetrics"]' ad.datadoghq.com/manager.init_configs: '[{}]' diff --git a/config/rbac/auth_proxy_client_clusterrole.yaml b/config/rbac/auth_proxy_client_clusterrole.yaml deleted file mode 100644 index 7d62534c5..000000000 --- a/config/rbac/auth_proxy_client_clusterrole.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1beta1 -kind: ClusterRole -metadata: - name: metrics-reader -rules: -- nonResourceURLs: ["/metrics"] - verbs: ["get"] diff --git a/config/rbac/kustomization.yaml b/config/rbac/kustomization.yaml index 9de348943..711b0f70c 100644 --- a/config/rbac/kustomization.yaml +++ b/config/rbac/kustomization.yaml @@ -4,12 +4,12 @@ resources: - role_binding.yaml - leader_election_role.yaml - leader_election_role_binding.yaml -# Comment the following 4 lines if you want to disable -# the auth proxy (https://github.com/brancz/kube-rbac-proxy) -# which protects your /metrics endpoint. -#- auth_proxy_service.yaml -#- auth_proxy_role.yaml -#- auth_proxy_role_binding.yaml -#- auth_proxy_client_clusterrole.yaml +# The following RBAC configurations are used to protect +# the metrics endpoint with authn/authz. These configurations +# ensure that only authorized users and service accounts +# can access the metrics endpoint. +# - metrics_auth_role.yaml +# - metrics_auth_role_binding.yaml +# - metrics_reader_role.yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization \ No newline at end of file diff --git a/config/rbac/auth_proxy_role.yaml b/config/rbac/metrics_auth_role.yaml similarity index 50% rename from config/rbac/auth_proxy_role.yaml rename to config/rbac/metrics_auth_role.yaml index 618f5e417..32d2e4ec6 100644 --- a/config/rbac/auth_proxy_role.yaml +++ b/config/rbac/metrics_auth_role.yaml @@ -1,13 +1,17 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: proxy-role + name: metrics-auth-role rules: -- apiGroups: ["authentication.k8s.io"] +- apiGroups: + - authentication.k8s.io resources: - tokenreviews - verbs: ["create"] -- apiGroups: ["authorization.k8s.io"] + verbs: + - create +- apiGroups: + - authorization.k8s.io resources: - subjectaccessreviews - verbs: ["create"] + verbs: + - create diff --git a/config/rbac/auth_proxy_role_binding.yaml b/config/rbac/metrics_auth_role_binding.yaml similarity index 69% rename from config/rbac/auth_proxy_role_binding.yaml rename to config/rbac/metrics_auth_role_binding.yaml index 48ed1e4b8..e775d67ff 100644 --- a/config/rbac/auth_proxy_role_binding.yaml +++ b/config/rbac/metrics_auth_role_binding.yaml @@ -1,12 +1,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: proxy-rolebinding + name: metrics-auth-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: proxy-role + name: metrics-auth-role subjects: - kind: ServiceAccount - name: default + name: controller-manager namespace: system diff --git a/config/rbac/metrics_reader_role.yaml b/config/rbac/metrics_reader_role.yaml new file mode 100644 index 000000000..51a75db47 --- /dev/null +++ b/config/rbac/metrics_reader_role.yaml @@ -0,0 +1,9 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: metrics-reader +rules: +- nonResourceURLs: + - "/metrics" + verbs: + - get diff --git a/config/test-v1/kustomization.yaml b/config/test-v1/kustomization.yaml index c38863cde..869ebd6a6 100644 --- a/config/test-v1/kustomization.yaml +++ b/config/test-v1/kustomization.yaml @@ -43,11 +43,6 @@ resources: # namespace: system # version: v1 -# Protect the /metrics endpoint by putting it behind auth. -# If you want your controller-manager to expose the /metrics -# endpoint w/o any authn/z, please comment the following line. -#- path: manager_auth_proxy_patch.yaml - # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml #- path: manager_webhook_patch.yaml diff --git a/config/test-v1/manager_auth_proxy_patch.yaml b/config/test-v1/manager_auth_proxy_patch.yaml deleted file mode 100644 index 02b5c2f4f..000000000 --- a/config/test-v1/manager_auth_proxy_patch.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# This patch inject a sidecar container which is a HTTP proxy for the -# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. -apiVersion: apps/v1 -kind: Deployment -metadata: - name: manager - namespace: system -spec: - template: - spec: - containers: - - name: kube-rbac-proxy - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 - args: - - "--secure-listen-address=0.0.0.0:8443" - - "--upstream=http://127.0.0.1:8080/" - - "--logtostderr=true" - - "--v=10" - ports: - - containerPort: 8443 - name: https - - name: manager - args: - - "--metrics-addr=127.0.0.1:8080" - - "--enable-leader-election" diff --git a/go.mod b/go.mod index 43f484ffb..ee0b9c75e 100644 --- a/go.mod +++ b/go.mod @@ -72,9 +72,12 @@ require ( github.com/Masterminds/semver v1.5.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/andybalholm/brotli v1.0.6 // indirect + github.com/antlr4-go/antlr/v4 v4.13.0 // indirect + github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver/v4 v4.0.0 // indirect + github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect @@ -83,9 +86,11 @@ require ( github.com/ebitengine/purego v0.6.0-alpha.5 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-errors/errors v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-logr/zapr v1.3.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -97,6 +102,7 @@ require ( github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.0.1 // indirect + github.com/google/cel-go v0.20.1 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af // indirect @@ -105,6 +111,7 @@ require ( github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect github.com/hashicorp/hcl v1.0.1-vault-5 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -149,6 +156,7 @@ require ( github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/stoewer/go-strcase v1.2.0 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/tinylib/msgp v1.1.8 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect @@ -159,6 +167,14 @@ require ( github.com/xlab/treeprint v1.2.0 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect go.etcd.io/bbolt v1.3.9 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect + go.opentelemetry.io/otel v1.28.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect + go.opentelemetry.io/otel/metric v1.28.0 // indirect + go.opentelemetry.io/otel/sdk v1.28.0 // indirect + go.opentelemetry.io/otel/trace v1.28.0 // indirect + go.opentelemetry.io/proto/otlp v1.3.1 // indirect go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect @@ -180,9 +196,12 @@ require ( gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect + k8s.io/apiserver v0.31.1 // indirect + k8s.io/component-base v0.31.1 // indirect k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 // indirect k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect modernc.org/sqlite v1.29.5 // indirect + sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kustomize/api v0.17.2 // indirect sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect diff --git a/go.sum b/go.sum index 6e8170a0b..593524c07 100644 --- a/go.sum +++ b/go.sum @@ -70,9 +70,13 @@ github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sx github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= +github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= +github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o= github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -83,6 +87,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -136,6 +142,8 @@ github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCv github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -152,8 +160,11 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2 github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= @@ -207,6 +218,8 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= +github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84= +github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg= github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -247,6 +260,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.13.0/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b h1:wDUNC2eKiL35DbLvsDhiblTUXHxcOPwQSCzi7xpQUN4= github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b/go.mod h1:VzxiSdG6j1pi7rwGm/xYI5RbtpBgM8sARDXlvEvxlu0= github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 h1:UpiO20jno/eV1eVZcxqWnUohyKRe1g8FPV/xH1s/2qs= @@ -457,6 +472,8 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= +github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU= +github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= @@ -509,6 +526,22 @@ github.com/zorkian/go-datadog-api v2.30.0+incompatible/go.mod h1:PkXwHX9CUQa/FpB go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI= go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg= +go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= +go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= +go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= +go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= +go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= +go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= +go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= +go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93VanwNIi5bIKnDrJdEY= go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -747,10 +780,14 @@ k8s.io/apiextensions-apiserver v0.31.1 h1:L+hwULvXx+nvTYX/MKM3kKMZyei+UiSXQWciX/ k8s.io/apiextensions-apiserver v0.31.1/go.mod h1:tWMPR3sgW+jsl2xm9v7lAyRF1rYEK71i9G5dRtkknoQ= k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U= k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= +k8s.io/apiserver v0.31.1 h1:Sars5ejQDCRBY5f7R3QFHdqN3s61nhkpaX8/k1iEw1c= +k8s.io/apiserver v0.31.1/go.mod h1:lzDhpeToamVZJmmFlaLwdYZwd7zB+WYRYIboqA1kGxM= k8s.io/cli-runtime v0.31.1 h1:/ZmKhmZ6hNqDM+yf9s3Y4KEYakNXUn5sod2LWGGwCuk= k8s.io/cli-runtime v0.31.1/go.mod h1:pKv1cDIaq7ehWGuXQ+A//1OIF+7DI+xudXtExMCbe9U= k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0= k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg= +k8s.io/component-base v0.31.1 h1:UpOepcrX3rQ3ab5NB6g5iP0tvsgJWzxTyAo20sgYSy8= +k8s.io/component-base v0.31.1/go.mod h1:WGeaw7t/kTsqpVTaCoVEtillbqAhF2/JgvO0LDOMa0w= k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo= k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= @@ -777,6 +814,8 @@ modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw= sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q= sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= From 6eae6177c798cddaf4509eadadea0168494099ac Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Thu, 26 Dec 2024 15:27:55 -0500 Subject: [PATCH 7/8] [cleanup] Remove operator reference in /api folder, refactor v2alpha files (#1576) * remove move utils and reference to defaulting from api * moving more out of api v2alpha1/test to pkg/testutils and v2alpha1/datadogagent_default to internal/controller/defaults * refactoring otel collector * Update datadogagent_default_test.go --- api/datadoghq/v2alpha1/const.go | 54 - .../controller/datadogagent/common/utils.go | 3 +- .../datadogagent/component/agent/default.go | 31 +- .../component/clusteragent/default.go | 23 +- .../component/clusteragent/default_test.go | 3 +- .../component/clusteragent/utils.go | 7 +- .../component/clusterchecksrunner/default.go | 21 +- .../controller_reconcile_agent.go | 5 +- .../controller_reconcile_agent_test.go | 95 +- .../datadogagent/controller_reconcile_ccr.go | 3 +- .../controller_reconcile_ccr_test.go | 13 +- .../datadogagent/controller_reconcile_dca.go | 3 +- .../controller_reconcile_dca_test.go | 16 +- .../datadogagent/controller_reconcile_v2.go | 3 +- .../datadogagent/controller_v2_test.go | 32 +- .../defaults}/datadogagent_default.go | 131 +- .../defaults}/datadogagent_default_test.go | 1502 +++++++++-------- .../feature/admissioncontroller/feature.go | 9 +- .../admissioncontroller/feature_test.go | 32 +- .../datadogagent/feature/apm/feature.go | 21 +- .../datadogagent/feature/apm/feature_test.go | 46 +- .../datadogagent/feature/asm/feature_test.go | 16 +- .../feature/autoscaling/feature.go | 3 +- .../feature/clusterchecks/feature.go | 3 +- .../feature/clusterchecks/feature_test.go | 22 +- .../datadogagent/feature/cspm/feature.go | 5 +- .../datadogagent/feature/cws/feature.go | 3 +- .../datadogagent/feature/dogstatsd/feature.go | 5 +- .../feature/dogstatsd/feature_test.go | 24 +- .../feature/enabledefault/feature.go | 13 +- .../feature/enabledefault/feature_test.go | 4 +- .../feature/enabledefault/rbac.go | 4 +- .../feature/enabledefault/utils_test.go | 6 +- .../feature/eventcollection/feature.go | 5 +- .../feature/eventcollection/feature_test.go | 8 +- .../feature/externalmetrics/feature.go | 7 +- .../datadogagent/feature/helmcheck/feature.go | 7 +- .../feature/helmcheck/feature_test.go | 8 +- .../feature/kubernetesstatecore/feature.go | 7 +- .../kubernetesstatecore/feature_test.go | 14 +- .../feature/livecontainer/feature_test.go | 14 +- .../feature/liveprocess/feature_test.go | 18 +- .../feature/logcollection/feature_test.go | 14 +- .../feature/orchestratorexplorer/feature.go | 11 +- .../orchestratorexplorer/feature_test.go | 10 +- .../feature/otelcollector/configmap_test.go | 4 +- .../feature/otelcollector/feature.go | 3 +- .../feature/otelcollector/feature_test.go | 24 +- .../datadogagent/feature/otlp/feature.go | 5 +- .../datadogagent/feature/otlp/feature_test.go | 6 +- .../feature/processdiscovery/feature_test.go | 18 +- .../feature/prometheusscrape/feature_test.go | 12 +- .../feature/remoteconfig/feature_test.go | 8 +- .../datadogagent/feature/test/factory_test.go | 34 +- internal/controller/datadogagent/finalizer.go | 3 +- .../datadogagent/override/container.go | 13 +- .../controller/datadogagent/override/fips.go | 3 +- .../datadogagent/override/fips_test.go | 12 +- .../datadogagent/override/global.go | 9 +- .../datadogagent/override/global_test.go | 21 +- .../datadogagent/override/podtemplatespec.go | 3 +- internal/controller/testutils/agent.go | 13 +- pkg/config/config.go | 3 +- pkg/constants/const.go | 62 + .../v2alpha1 => pkg/constants}/utils.go | 55 +- .../v2alpha1 => pkg/constants}/utils_test.go | 102 +- .../utils/datadog/metrics_forwarder_test.go | 22 +- .../test => pkg/testutils}/builder.go | 14 +- .../v2alpha1/test => pkg/testutils}/new.go | 2 +- 69 files changed, 1392 insertions(+), 1343 deletions(-) rename {api/datadoghq/v2alpha1 => internal/controller/datadogagent/defaults}/datadogagent_default.go (81%) rename {api/datadoghq/v2alpha1 => internal/controller/datadogagent/defaults}/datadogagent_default_test.go (58%) create mode 100644 pkg/constants/const.go rename {api/datadoghq/v2alpha1 => pkg/constants}/utils.go (73%) rename {api/datadoghq/v2alpha1 => pkg/constants}/utils_test.go (69%) rename {api/datadoghq/v2alpha1/test => pkg/testutils}/builder.go (99%) rename {api/datadoghq/v2alpha1/test => pkg/testutils}/new.go (98%) diff --git a/api/datadoghq/v2alpha1/const.go b/api/datadoghq/v2alpha1/const.go index d14341593..ef52fb674 100644 --- a/api/datadoghq/v2alpha1/const.go +++ b/api/datadoghq/v2alpha1/const.go @@ -8,7 +8,6 @@ package v2alpha1 // This file tracks constants related to the DatadogAgent CRD const ( - // ClusterAgentReconcileConditionType ReconcileConditionType for Cluster Agent component ClusterAgentReconcileConditionType = "ClusterAgentReconcile" // AgentReconcileConditionType ReconcileConditionType for Agent component @@ -25,59 +24,6 @@ const ( // ExtraChecksdConfigMapName is the name of the ConfigMap storing Custom Checksd data ExtraChecksdConfigMapName = "%s-extra-checksd" - // DefaultAgentHealthPort default agent health port - DefaultAgentHealthPort int32 = 5555 - - // Liveness probe default config - DefaultLivenessProbeInitialDelaySeconds int32 = 15 - DefaultLivenessProbePeriodSeconds int32 = 15 - DefaultLivenessProbeTimeoutSeconds int32 = 5 - DefaultLivenessProbeSuccessThreshold int32 = 1 - DefaultLivenessProbeFailureThreshold int32 = 6 - DefaultLivenessProbeHTTPPath = "/live" - - // Readiness probe default config - DefaultReadinessProbeInitialDelaySeconds int32 = 15 - DefaultReadinessProbePeriodSeconds int32 = 15 - DefaultReadinessProbeTimeoutSeconds int32 = 5 - DefaultReadinessProbeSuccessThreshold int32 = 1 - DefaultReadinessProbeFailureThreshold int32 = 6 - DefaultReadinessProbeHTTPPath = "/ready" - - // Startup probe default config - DefaultStartupProbeInitialDelaySeconds int32 = 15 - DefaultStartupProbePeriodSeconds int32 = 15 - DefaultStartupProbeTimeoutSeconds int32 = 5 - DefaultStartupProbeSuccessThreshold int32 = 1 - DefaultStartupProbeFailureThreshold int32 = 6 - DefaultStartupProbeHTTPPath = "/startup" - - // Agent Data plane default liveness/readiness probe configs - DefaultADPLivenessProbeInitialDelaySeconds int32 = 5 - DefaultADPLivenessProbePeriodSeconds int32 = 5 - DefaultADPLivenessProbeTimeoutSeconds int32 = 5 - DefaultADPLivenessProbeSuccessThreshold int32 = 1 - DefaultADPLivenessProbeFailureThreshold int32 = 12 - - DefaultADPReadinessProbeInitialDelaySeconds int32 = 5 - DefaultADPReadinessProbePeriodSeconds int32 = 5 - DefaultADPReadinessProbeTimeoutSeconds int32 = 5 - DefaultADPReadinessProbeSuccessThreshold int32 = 1 - DefaultADPReadinessProbeFailureThreshold int32 = 12 - - DefaultADPHealthPort = 5100 - - // DefaultApmPort default apm port - DefaultApmPort = 8126 - // DefaultApmPortName default apm port name - DefaultApmPortName = "traceport" - - // DefaultAgentResourceSuffix use as suffix for agent resource naming - DefaultAgentResourceSuffix = "agent" - // DefaultClusterAgentResourceSuffix use as suffix for cluster-agent resource naming - DefaultClusterAgentResourceSuffix = "cluster-agent" - // DefaultClusterChecksRunnerResourceSuffix use as suffix for cluster-checks-runner resource naming - DefaultClusterChecksRunnerResourceSuffix = "cluster-checks-runner" // DefaultMetricsServerResourceSuffix use as suffix for cluster-agent metrics-server resource naming DefaultMetricsServerResourceSuffix = "cluster-agent-metrics-server" // DefaultAPPKeyKey default app-key key (use in secret for instance). diff --git a/internal/controller/datadogagent/common/utils.go b/internal/controller/datadogagent/common/utils.go index b6e716408..6cb0a9e3d 100644 --- a/internal/controller/datadogagent/common/utils.go +++ b/internal/controller/datadogagent/common/utils.go @@ -12,6 +12,7 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/DataDog/datadog-operator/pkg/utils" @@ -120,7 +121,7 @@ const ( func GetAgentLocalServiceSelector(dda metav1.Object) map[string]string { return map[string]string{ kubernetes.AppKubernetesPartOfLabelKey: object.NewPartOfLabelValue(dda).String(), - apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, } } diff --git a/internal/controller/datadogagent/component/agent/default.go b/internal/controller/datadogagent/component/agent/default.go index 1461f4b4b..3eaa40fd4 100644 --- a/internal/controller/datadogagent/component/agent/default.go +++ b/internal/controller/datadogagent/component/agent/default.go @@ -18,6 +18,7 @@ import ( componentdca "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/clusteragent" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils" "github.com/DataDog/datadog-operator/pkg/defaulting" @@ -28,7 +29,7 @@ import ( // NewDefaultAgentDaemonset return a new default agent DaemonSet func NewDefaultAgentDaemonset(dda metav1.Object, edsOptions *ExtendedDaemonsetOptions, agentComponent feature.RequiredComponent) *appsv1.DaemonSet { - daemonset := NewDaemonset(dda, edsOptions, v2alpha1.DefaultAgentResourceSuffix, GetAgentName(dda), common.GetAgentVersion(dda), nil) + daemonset := NewDaemonset(dda, edsOptions, constants.DefaultAgentResourceSuffix, GetAgentName(dda), common.GetAgentVersion(dda), nil) podTemplate := NewDefaultAgentPodTemplateSpec(dda, agentComponent, daemonset.GetLabels()) daemonset.Spec.Template = *podTemplate return daemonset @@ -36,7 +37,7 @@ func NewDefaultAgentDaemonset(dda metav1.Object, edsOptions *ExtendedDaemonsetOp // NewDefaultAgentExtendedDaemonset return a new default agent DaemonSet func NewDefaultAgentExtendedDaemonset(dda metav1.Object, edsOptions *ExtendedDaemonsetOptions, agentComponent feature.RequiredComponent) *edsv1alpha1.ExtendedDaemonSet { - edsDaemonset := NewExtendedDaemonset(dda, edsOptions, v2alpha1.DefaultAgentResourceSuffix, GetAgentName(dda), common.GetAgentVersion(dda), nil) + edsDaemonset := NewExtendedDaemonset(dda, edsOptions, constants.DefaultAgentResourceSuffix, GetAgentName(dda), common.GetAgentVersion(dda), nil) edsDaemonset.Spec.Template = *NewDefaultAgentPodTemplateSpec(dda, agentComponent, edsDaemonset.GetLabels()) return edsDaemonset } @@ -88,16 +89,16 @@ func DefaultCapabilitiesForSystemProbe() []corev1.Capability { // GetAgentName return the Agent name based on the DatadogAgent info func GetAgentName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultAgentResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultAgentResourceSuffix) } // GetAgentRoleName returns the name of the role for the Agent func GetAgentRoleName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultAgentResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultAgentResourceSuffix) } func getDefaultServiceAccountName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultAgentResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultAgentResourceSuffix) } func agentImage() string { @@ -130,9 +131,9 @@ func agentSingleContainer(dda metav1.Object) []corev1.Container { Image: agentImage(), Env: envVarsForCoreAgent(dda), VolumeMounts: volumeMountsForCoreAgent(), - LivenessProbe: v2alpha1.GetDefaultLivenessProbe(), - ReadinessProbe: v2alpha1.GetDefaultReadinessProbe(), - StartupProbe: v2alpha1.GetDefaultStartupProbe(), + LivenessProbe: constants.GetDefaultLivenessProbe(), + ReadinessProbe: constants.GetDefaultReadinessProbe(), + StartupProbe: constants.GetDefaultStartupProbe(), } containers := []corev1.Container{ @@ -174,9 +175,9 @@ func coreAgentContainer(dda metav1.Object) corev1.Container { Command: []string{"agent", "run"}, Env: envVarsForCoreAgent(dda), VolumeMounts: volumeMountsForCoreAgent(), - LivenessProbe: v2alpha1.GetDefaultLivenessProbe(), - ReadinessProbe: v2alpha1.GetDefaultReadinessProbe(), - StartupProbe: v2alpha1.GetDefaultStartupProbe(), + LivenessProbe: constants.GetDefaultLivenessProbe(), + ReadinessProbe: constants.GetDefaultReadinessProbe(), + StartupProbe: constants.GetDefaultStartupProbe(), } } @@ -190,7 +191,7 @@ func traceAgentContainer(dda metav1.Object) corev1.Container { }, Env: envVarsForTraceAgent(dda), VolumeMounts: volumeMountsForTraceAgent(), - LivenessProbe: v2alpha1.GetDefaultTraceAgentProbe(), + LivenessProbe: constants.GetDefaultTraceAgentProbe(), } } @@ -282,8 +283,8 @@ func agentDataPlaneContainer(dda metav1.Object) corev1.Container { }, Env: commonEnvVars(dda), VolumeMounts: volumeMountsForAgentDataPlane(), - LivenessProbe: v2alpha1.GetDefaultAgentDataPlaneLivenessProbe(), - ReadinessProbe: v2alpha1.GetDefaultAgentDataPlaneReadinessProbe(), + LivenessProbe: constants.GetDefaultAgentDataPlaneLivenessProbe(), + ReadinessProbe: constants.GetDefaultAgentDataPlaneReadinessProbe(), } } @@ -361,7 +362,7 @@ func envVarsForCoreAgent(dda metav1.Object) []corev1.EnvVar { envs := []corev1.EnvVar{ { Name: v2alpha1.DDHealthPort, - Value: strconv.Itoa(int(v2alpha1.DefaultAgentHealthPort)), + Value: strconv.Itoa(int(constants.DefaultAgentHealthPort)), }, { Name: v2alpha1.DDLeaderElection, diff --git a/internal/controller/datadogagent/component/clusteragent/default.go b/internal/controller/datadogagent/component/clusteragent/default.go index 4742536a9..3bf1a8347 100644 --- a/internal/controller/datadogagent/component/clusteragent/default.go +++ b/internal/controller/datadogagent/component/clusteragent/default.go @@ -19,23 +19,24 @@ import ( apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/common" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils" "github.com/DataDog/datadog-operator/pkg/defaulting" ) // GetClusterAgentServiceName return the Cluster-Agent service name based on the DatadogAgent name func GetClusterAgentServiceName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultClusterAgentResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultClusterAgentResourceSuffix) } // GetClusterAgentPodDisruptionBudgetName return the Cluster-Agent PodDisruptionBudget name based on the DatadogAgent name func GetClusterAgentPodDisruptionBudgetName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s-pdb", dda.GetName(), v2alpha1.DefaultClusterAgentResourceSuffix) + return fmt.Sprintf("%s-%s-pdb", dda.GetName(), constants.DefaultClusterAgentResourceSuffix) } // GetClusterAgentName return the Cluster-Agent name based on the DatadogAgent name func GetClusterAgentName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultClusterAgentResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultClusterAgentResourceSuffix) } // GetClusterAgentVersion return the Cluster-Agent version based on the DatadogAgent info @@ -46,17 +47,17 @@ func GetClusterAgentVersion(dda metav1.Object) string { // GetClusterAgentRbacResourcesName return the Cluster-Agent RBAC resource name func GetClusterAgentRbacResourcesName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultClusterAgentResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultClusterAgentResourceSuffix) } // getDefaultServiceAccountName return the default Cluster-Agent ServiceAccountName func getDefaultServiceAccountName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultClusterAgentResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultClusterAgentResourceSuffix) } // NewDefaultClusterAgentDeployment return a new default cluster-agent deployment func NewDefaultClusterAgentDeployment(dda metav1.Object) *appsv1.Deployment { - deployment := common.NewDeployment(dda, v2alpha1.DefaultClusterAgentResourceSuffix, GetClusterAgentName(dda), GetClusterAgentVersion(dda), nil) + deployment := common.NewDeployment(dda, constants.DefaultClusterAgentResourceSuffix, GetClusterAgentName(dda), GetClusterAgentVersion(dda), nil) podTemplate := NewDefaultClusterAgentPodTemplateSpec(dda) for key, val := range deployment.GetLabels() { podTemplate.Labels[key] = val @@ -126,9 +127,9 @@ func defaultPodSpec(dda metav1.Object, volumes []corev1.Volume, volumeMounts []c }, Env: envVars, VolumeMounts: volumeMounts, - LivenessProbe: v2alpha1.GetDefaultLivenessProbe(), - ReadinessProbe: v2alpha1.GetDefaultReadinessProbe(), - StartupProbe: v2alpha1.GetDefaultStartupProbe(), + LivenessProbe: constants.GetDefaultLivenessProbe(), + ReadinessProbe: constants.GetDefaultReadinessProbe(), + StartupProbe: constants.GetDefaultStartupProbe(), Command: nil, Args: nil, SecurityContext: &corev1.SecurityContext{ @@ -172,7 +173,7 @@ func defaultEnvVars(dda metav1.Object) []corev1.EnvVar { }, { Name: v2alpha1.DDHealthPort, - Value: strconv.Itoa(int(v2alpha1.DefaultAgentHealthPort)), + Value: strconv.Itoa(int(constants.DefaultAgentHealthPort)), }, { Name: v2alpha1.DDAPMInstrumentationInstallId, @@ -207,7 +208,7 @@ func DefaultAffinity() *corev1.Affinity { PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ MatchLabels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, }, }, TopologyKey: "kubernetes.io/hostname", diff --git a/internal/controller/datadogagent/component/clusteragent/default_test.go b/internal/controller/datadogagent/component/clusteragent/default_test.go index cffbda848..d208c71c7 100644 --- a/internal/controller/datadogagent/component/clusteragent/default_test.go +++ b/internal/controller/datadogagent/component/clusteragent/default_test.go @@ -9,6 +9,7 @@ import ( datadoghqv2alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/common" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/defaulting" "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/stretchr/testify/assert" @@ -222,7 +223,7 @@ func clusterAgentDefaultEnvVars(dda *datadoghqv2alpha1.DatadogAgent) []corev1.En }, { Name: "DD_CLUSTER_AGENT_KUBERNETES_SERVICE_NAME", - Value: fmt.Sprintf("%s-%s", testDdaName, datadoghqv2alpha1.DefaultClusterAgentResourceSuffix), + Value: fmt.Sprintf("%s-%s", testDdaName, constants.DefaultClusterAgentResourceSuffix), }, { Name: "DD_LEADER_ELECTION", diff --git a/internal/controller/datadogagent/component/clusteragent/utils.go b/internal/controller/datadogagent/component/clusteragent/utils.go index 1f3db4d3b..eefeb2a24 100644 --- a/internal/controller/datadogagent/component/clusteragent/utils.go +++ b/internal/controller/datadogagent/component/clusteragent/utils.go @@ -15,6 +15,7 @@ import ( "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/DataDog/datadog-operator/pkg/constants" corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" policyv1beta1 "k8s.io/api/policy/v1beta1" @@ -29,7 +30,7 @@ const ( // GetClusterAgentService returns the Cluster-Agent service func GetClusterAgentService(dda metav1.Object) *corev1.Service { - labels := object.GetDefaultLabels(dda, v2alpha1.DefaultClusterAgentResourceSuffix, GetClusterAgentVersion(dda)) + labels := object.GetDefaultLabels(dda, constants.DefaultClusterAgentResourceSuffix, GetClusterAgentVersion(dda)) annotations := object.GetDefaultAnnotations(dda) service := &corev1.Service{ @@ -43,7 +44,7 @@ func GetClusterAgentService(dda metav1.Object) *corev1.Service { Type: corev1.ServiceTypeClusterIP, Selector: map[string]string{ apicommon.AgentDeploymentNameLabelKey: dda.GetName(), - apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, }, Ports: []corev1.ServicePort{ { @@ -65,7 +66,7 @@ func GetClusterAgentPodDisruptionBudget(dda metav1.Object, useV1BetaPDB bool) cl minAvailableStr := intstr.FromInt(pdbMinAvailableInstances) matchLabels := map[string]string{ apicommon.AgentDeploymentNameLabelKey: dda.GetName(), - apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterAgentResourceSuffix} + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix} if useV1BetaPDB { return &policyv1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/controller/datadogagent/component/clusterchecksrunner/default.go b/internal/controller/datadogagent/component/clusterchecksrunner/default.go index 13a85b1e2..58287c260 100644 --- a/internal/controller/datadogagent/component/clusterchecksrunner/default.go +++ b/internal/controller/datadogagent/component/clusterchecksrunner/default.go @@ -22,6 +22,7 @@ import ( apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/common" componentdca "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/clusteragent" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/defaulting" ) @@ -31,12 +32,12 @@ const ( // GetClusterChecksRunnerName return the Cluster-Checks-Runner name based on the DatadogAgent name func GetClusterChecksRunnerName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultClusterChecksRunnerResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultClusterChecksRunnerResourceSuffix) } // NewDefaultClusterChecksRunnerDeployment return a new default cluster-checks-runner deployment func NewDefaultClusterChecksRunnerDeployment(dda metav1.Object) *appsv1.Deployment { - deployment := common.NewDeployment(dda, v2alpha1.DefaultClusterChecksRunnerResourceSuffix, GetClusterChecksRunnerName(dda), common.GetAgentVersion(dda), nil) + deployment := common.NewDeployment(dda, constants.DefaultClusterChecksRunnerResourceSuffix, GetClusterChecksRunnerName(dda), common.GetAgentVersion(dda), nil) podTemplate := NewDefaultClusterChecksRunnerPodTemplateSpec(dda) for key, val := range deployment.GetLabels() { @@ -91,14 +92,14 @@ func NewDefaultClusterChecksRunnerPodTemplateSpec(dda metav1.Object) *corev1.Pod } func GetClusterChecksRunnerPodDisruptionBudgetName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s-pdb", dda.GetName(), v2alpha1.DefaultClusterChecksRunnerResourceSuffix) + return fmt.Sprintf("%s-%s-pdb", dda.GetName(), constants.DefaultClusterChecksRunnerResourceSuffix) } func GetClusterChecksRunnerPodDisruptionBudget(dda metav1.Object, useV1BetaPDB bool) client.Object { maxUnavailableStr := intstr.FromInt(pdbMaxUnavailableInstances) matchLabels := map[string]string{ apicommon.AgentDeploymentNameLabelKey: dda.GetName(), - apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterChecksRunnerResourceSuffix} + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix} if useV1BetaPDB { return &policyv1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ @@ -129,7 +130,7 @@ func GetClusterChecksRunnerPodDisruptionBudget(dda metav1.Object, useV1BetaPDB b // getDefaultServiceAccountName return the default Cluster-Agent ServiceAccountName func getDefaultServiceAccountName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultClusterChecksRunnerResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultClusterChecksRunnerResourceSuffix) } func clusterChecksRunnerImage() string { @@ -160,9 +161,9 @@ func defaultPodSpec(dda metav1.Object, volumes []corev1.Volume, volumeMounts []c Args: []string{ "agent run", }, - LivenessProbe: v2alpha1.GetDefaultLivenessProbe(), - ReadinessProbe: v2alpha1.GetDefaultReadinessProbe(), - StartupProbe: v2alpha1.GetDefaultStartupProbe(), + LivenessProbe: constants.GetDefaultLivenessProbe(), + ReadinessProbe: constants.GetDefaultReadinessProbe(), + StartupProbe: constants.GetDefaultStartupProbe(), SecurityContext: &corev1.SecurityContext{ ReadOnlyRootFilesystem: apiutils.NewBoolPointer(true), AllowPrivilegeEscalation: apiutils.NewBoolPointer(false), @@ -191,7 +192,7 @@ func defaultEnvVars(dda metav1.Object) []corev1.EnvVar { }, { Name: v2alpha1.DDHealthPort, - Value: strconv.Itoa(int(v2alpha1.DefaultAgentHealthPort)), + Value: strconv.Itoa(int(constants.DefaultAgentHealthPort)), }, { Name: v2alpha1.KubernetesEnvVar, @@ -266,7 +267,7 @@ func DefaultAffinity() *corev1.Affinity { PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ MatchLabels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterChecksRunnerResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix, }, }, TopologyKey: "kubernetes.io/hostname", diff --git a/internal/controller/datadogagent/controller_reconcile_agent.go b/internal/controller/datadogagent/controller_reconcile_agent.go index ca0114b77..54fcdb42d 100644 --- a/internal/controller/datadogagent/controller_reconcile_agent.go +++ b/internal/controller/datadogagent/controller_reconcile_agent.go @@ -17,6 +17,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/override" "github.com/DataDog/datadog-operator/pkg/agentprofile" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/datadog" "github.com/DataDog/datadog-operator/pkg/kubernetes" edsv1alpha1 "github.com/DataDog/extendeddaemonset/api/v1alpha1" @@ -347,7 +348,7 @@ func (r *Reconciler) cleanupPodsForProfilesThatNoLongerApply(ctx context.Context ctx, agentPods, client.MatchingLabels(map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, }), client.InNamespace(ddaNamespace), ) @@ -394,7 +395,7 @@ func (r *Reconciler) cleanupPodsForProfilesThatNoLongerApply(ctx context.Context func (r *Reconciler) cleanupExtraneousDaemonSets(ctx context.Context, logger logr.Logger, dda *datadoghqv2alpha1.DatadogAgent, newStatus *datadoghqv2alpha1.DatadogAgentStatus, providerList map[string]struct{}, profiles []v1alpha1.DatadogAgentProfile) error { matchLabels := client.MatchingLabels{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", } diff --git a/internal/controller/datadogagent/controller_reconcile_agent_test.go b/internal/controller/datadogagent/controller_reconcile_agent_test.go index edf517bca..4cc45bdd4 100644 --- a/internal/controller/datadogagent/controller_reconcile_agent_test.go +++ b/internal/controller/datadogagent/controller_reconcile_agent_test.go @@ -10,6 +10,7 @@ import ( apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/agent" "github.com/DataDog/datadog-operator/pkg/agentprofile" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/kubernetes" edsdatadoghqv1alpha1 "github.com/DataDog/extendeddaemonset/api/v1alpha1" @@ -268,7 +269,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "dda-foo-agent", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -286,7 +287,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "dda-foo-agent", ResourceVersion: "999", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -303,7 +304,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "dda-foo-agent", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -322,7 +323,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "dda-foo-agent", ResourceVersion: "999", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -340,7 +341,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -368,7 +369,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -388,7 +389,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -417,7 +418,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -435,7 +436,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }}, }, @@ -444,7 +445,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -455,7 +456,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -483,7 +484,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -502,7 +503,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -512,7 +513,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -523,7 +524,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -534,7 +535,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -545,7 +546,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -573,7 +574,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -589,7 +590,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -607,7 +608,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }}, }, @@ -617,7 +618,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }}, }, @@ -626,7 +627,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -637,7 +638,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -665,7 +666,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -684,7 +685,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -694,7 +695,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -705,7 +706,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -716,7 +717,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -727,7 +728,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -758,7 +759,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -776,7 +777,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "dda-foo-agent", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }}, }, @@ -785,7 +786,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -796,7 +797,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -829,7 +830,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -840,7 +841,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "dda-foo-agent", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -859,7 +860,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "dda-foo-agent", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -869,7 +870,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -880,7 +881,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -891,7 +892,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -902,7 +903,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -912,7 +913,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -945,7 +946,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -960,7 +961,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "dda-foo-agent", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, ResourceVersion: "999", @@ -1088,7 +1089,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, }, }, }, @@ -1107,7 +1108,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, }, }, }, @@ -1139,7 +1140,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Name: "datadog-agent-with-profile-ns-1-profile-1", Namespace: "ns-1", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, }, ResourceVersion: "999", }, @@ -1193,7 +1194,7 @@ func Test_cleanupExtraneousDaemonSets(t *testing.T) { Namespace: "ns-1", Labels: map[string]string{ datadoghqv2alpha1.MD5AgentDeploymentProviderLabelKey: gkeCosProvider, - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, }, ResourceVersion: "999", }, diff --git a/internal/controller/datadogagent/controller_reconcile_ccr.go b/internal/controller/datadogagent/controller_reconcile_ccr.go index dff82d3e7..59742be38 100644 --- a/internal/controller/datadogagent/controller_reconcile_ccr.go +++ b/internal/controller/datadogagent/controller_reconcile_ccr.go @@ -15,6 +15,7 @@ import ( componentccr "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/clusterchecksrunner" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/override" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/datadog" "github.com/DataDog/datadog-operator/pkg/kubernetes" @@ -125,7 +126,7 @@ func deleteStatusWithClusterChecksRunner(newStatus *datadoghqv2alpha1.DatadogAge // cleanupOldCCRDeployments deletes CCR deployments when a CCR Deployment's name is changed using clusterChecksRunner name override func (r *Reconciler) cleanupOldCCRDeployments(ctx context.Context, logger logr.Logger, dda *datadoghqv2alpha1.DatadogAgent, newStatus *datadoghqv2alpha1.DatadogAgentStatus) error { matchLabels := client.MatchingLabels{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterChecksRunnerResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", } deploymentName := getDeploymentNameFromCCR(dda) diff --git a/internal/controller/datadogagent/controller_reconcile_ccr_test.go b/internal/controller/datadogagent/controller_reconcile_ccr_test.go index 7151931c3..a9345798e 100644 --- a/internal/controller/datadogagent/controller_reconcile_ccr_test.go +++ b/internal/controller/datadogagent/controller_reconcile_ccr_test.go @@ -7,6 +7,7 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" datadoghqv2alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" @@ -97,7 +98,7 @@ func Test_cleanupOldCCRDeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "dda-foo-cluster-checks-runner", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterChecksRunnerResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -110,7 +111,7 @@ func Test_cleanupOldCCRDeployments(t *testing.T) { Name: "dda-foo-cluster-checks-runner", ResourceVersion: "999", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterChecksRunnerResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -126,7 +127,7 @@ func Test_cleanupOldCCRDeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "dda-foo-cluster-checks-runner", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterChecksRunnerResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -135,7 +136,7 @@ func Test_cleanupOldCCRDeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "foo-ccr", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterChecksRunnerResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -144,7 +145,7 @@ func Test_cleanupOldCCRDeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "bar-ccr", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterChecksRunnerResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -157,7 +158,7 @@ func Test_cleanupOldCCRDeployments(t *testing.T) { Name: "dda-foo-cluster-checks-runner", ResourceVersion: "999", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterChecksRunnerResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterChecksRunnerResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, diff --git a/internal/controller/datadogagent/controller_reconcile_dca.go b/internal/controller/datadogagent/controller_reconcile_dca.go index 48528c8c9..3b78145da 100644 --- a/internal/controller/datadogagent/controller_reconcile_dca.go +++ b/internal/controller/datadogagent/controller_reconcile_dca.go @@ -15,6 +15,7 @@ import ( componentdca "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/clusteragent" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/override" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/datadog" "github.com/DataDog/datadog-operator/pkg/kubernetes" @@ -138,7 +139,7 @@ func (r *Reconciler) cleanupV2ClusterAgent(logger logr.Logger, dda *datadoghqv2a // cleanupOldDCADeployments deletes DCA deployments when a DCA Deployment's name is changed using clusterAgent name override func (r *Reconciler) cleanupOldDCADeployments(ctx context.Context, logger logr.Logger, dda *datadoghqv2alpha1.DatadogAgent, resourcesManager feature.ResourceManagers, newStatus *datadoghqv2alpha1.DatadogAgentStatus) error { matchLabels := client.MatchingLabels{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", } deploymentName := getDeploymentNameFromDCA(dda) diff --git a/internal/controller/datadogagent/controller_reconcile_dca_test.go b/internal/controller/datadogagent/controller_reconcile_dca_test.go index 0c43a730b..718115ec8 100644 --- a/internal/controller/datadogagent/controller_reconcile_dca_test.go +++ b/internal/controller/datadogagent/controller_reconcile_dca_test.go @@ -7,8 +7,10 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" datadoghqv2alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/defaults" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" @@ -99,7 +101,7 @@ func Test_cleanupOldDCADeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "dda-foo-cluster-agent", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -112,7 +114,7 @@ func Test_cleanupOldDCADeployments(t *testing.T) { Name: "dda-foo-cluster-agent", ResourceVersion: "999", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -128,7 +130,7 @@ func Test_cleanupOldDCADeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "dda-foo-cluster-agent", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -137,7 +139,7 @@ func Test_cleanupOldDCADeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "foo-dca", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -146,7 +148,7 @@ func Test_cleanupOldDCADeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "bar-dca", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -159,7 +161,7 @@ func Test_cleanupOldDCADeployments(t *testing.T) { Name: "dda-foo-cluster-agent", ResourceVersion: "999", Labels: map[string]string{ - apicommon.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, kubernetes.AppKubernetesManageByLabelKey: "datadog-operator", }, }, @@ -248,7 +250,7 @@ func Test_cleanupOldDCADeployments(t *testing.T) { Scheme: r.scheme, } instance := &datadoghqv2alpha1.DatadogAgent{} - datadoghqv2alpha1.DefaultDatadogAgent(instance.DeepCopy()) + defaults.DefaultDatadogAgent(instance.DeepCopy()) depsStore := store.NewStore(instance, storeOptions) resourcesManager := feature.NewResourceManagers(depsStore) diff --git a/internal/controller/datadogagent/controller_reconcile_v2.go b/internal/controller/datadogagent/controller_reconcile_v2.go index ee893fb15..de2c05f3a 100644 --- a/internal/controller/datadogagent/controller_reconcile_v2.go +++ b/internal/controller/datadogagent/controller_reconcile_v2.go @@ -12,6 +12,7 @@ import ( datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1" datadoghqv2alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/defaults" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/override" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" @@ -87,7 +88,7 @@ func (r *Reconciler) internalReconcileV2(ctx context.Context, request reconcile. // Set default values for GlobalConfig and Features instanceCopy := instance.DeepCopy() - datadoghqv2alpha1.DefaultDatadogAgent(instanceCopy) + defaults.DefaultDatadogAgent(instanceCopy) return r.reconcileInstanceV2(ctx, reqLogger, instanceCopy) } diff --git a/internal/controller/datadogagent/controller_v2_test.go b/internal/controller/datadogagent/controller_v2_test.go index 42706c93d..ad22ec921 100644 --- a/internal/controller/datadogagent/controller_v2_test.go +++ b/internal/controller/datadogagent/controller_v2_test.go @@ -15,11 +15,11 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" componentagent "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/agent" - testutils "github.com/DataDog/datadog-operator/internal/controller/datadogagent/testutils" + agenttestutils "github.com/DataDog/datadog-operator/internal/controller/datadogagent/testutils" "github.com/DataDog/datadog-operator/pkg/kubernetes" + "github.com/DataDog/datadog-operator/pkg/testutils" assert "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" @@ -61,7 +61,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { logf.SetLogger(zap.New(zap.UseDevMode(true))) // Register operator types with the runtime scheme. - s := testutils.TestScheme() + s := agenttestutils.TestScheme() defaultRequeueDuration := 15 * time.Second @@ -83,7 +83,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). Build() _ = c.Create(context.TODO(), dda) }, @@ -110,7 +110,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithSingleContainerStrategy(false). Build() _ = c.Create(context.TODO(), dda) @@ -138,7 +138,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithSingleContainerStrategy(true). Build() _ = c.Create(context.TODO(), dda) @@ -164,7 +164,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithAPMEnabled(true). WithSingleContainerStrategy(false). Build() @@ -193,7 +193,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithAPMEnabled(true). WithSingleContainerStrategy(true). Build() @@ -220,7 +220,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithAPMEnabled(true). WithCWSEnabled(true). WithSingleContainerStrategy(false). @@ -252,7 +252,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithAPMEnabled(true). WithCWSEnabled(true). WithSingleContainerStrategy(true). @@ -285,7 +285,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithAPMEnabled(true). WithOOMKillEnabled(true). WithSingleContainerStrategy(false). @@ -316,7 +316,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithAPMEnabled(true). WithOOMKillEnabled(true). WithSingleContainerStrategy(true). @@ -350,7 +350,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { fipsConfig := v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(true), } - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithFIPS(fipsConfig). Build() _ = c.Create(context.TODO(), dda) @@ -379,7 +379,7 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithComponentOverride(v2alpha1.ClusterAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ CreatePodDisruptionBudget: apiutils.NewBoolPointer(true), }). @@ -448,7 +448,7 @@ func Test_Introspection(t *testing.T) { logf.SetLogger(zap.New(zap.UseDevMode(true))) // Register operator types with the runtime scheme. - s := testutils.TestScheme() + s := agenttestutils.TestScheme() defaultRequeueDuration := 15 * time.Second @@ -470,7 +470,7 @@ func Test_Introspection(t *testing.T) { args: args{ request: newRequest(resourcesNamespace, resourcesName), loadFunc: func(c client.Client) { - dda := v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ Affinity: &corev1.Affinity{ PodAntiAffinity: &corev1.PodAntiAffinity{ diff --git a/api/datadoghq/v2alpha1/datadogagent_default.go b/internal/controller/datadogagent/defaults/datadogagent_default.go similarity index 81% rename from api/datadoghq/v2alpha1/datadogagent_default.go rename to internal/controller/datadogagent/defaults/datadogagent_default.go index 97d54f895..1ebe56970 100644 --- a/api/datadoghq/v2alpha1/datadogagent_default.go +++ b/internal/controller/datadogagent/defaults/datadogagent_default.go @@ -3,9 +3,10 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -package v2alpha1 +package defaults import ( + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/pkg/defaulting" ) @@ -42,7 +43,7 @@ const ( defaultAPMHostPortEnabled bool = false defaultAPMHostPort int32 = 8126 defaultAPMSocketEnabled bool = true - defaultAPMSocketHostPath string = DogstatsdAPMSocketHostPath + "/" + APMSocketName + defaultAPMSocketHostPath string = v2alpha1.DogstatsdAPMSocketHostPath + "/" + v2alpha1.APMSocketName defaultAPMSingleStepInstrEnabled bool = false defaultLanguageDetectionEnabled bool = true defaultCSPMEnabled bool = false @@ -61,7 +62,7 @@ const ( defaultDogstatsdOriginDetectionEnabled bool = false defaultDogstatsdHostPortEnabled bool = false defaultDogstatsdSocketEnabled bool = true - defaultDogstatsdHostSocketPath string = DogstatsdAPMSocketHostPath + "/" + DogstatsdSocketName + defaultDogstatsdHostSocketPath string = v2alpha1.DogstatsdAPMSocketHostPath + "/" + v2alpha1.DogstatsdSocketName defaultOTLPGRPCEnabled bool = false defaultOTLPGRPCHostPortEnabled bool = true @@ -113,7 +114,7 @@ const ( // defaultKubeletAgentCAPath = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" // defaultKubeletAgentCAPathHostPathSet = "/var/run/host-kubelet-ca.crt" - defaultContainerStrategy = OptimizedContainerStrategy + defaultContainerStrategy = v2alpha1.OptimizedContainerStrategy defaultHelmCheckEnabled bool = false defaultHelmCheckCollectEvents bool = false @@ -128,16 +129,16 @@ const ( ) // DefaultDatadogAgent defaults the DatadogAgentSpec GlobalConfig and Features. -func DefaultDatadogAgent(dda *DatadogAgent) { +func DefaultDatadogAgent(dda *v2alpha1.DatadogAgent) { defaultGlobalConfig(&dda.Spec) defaultFeaturesConfig(&dda.Spec) } // defaultGlobalConfig sets default values in DatadogAgentSpec.Global. -func defaultGlobalConfig(ddaSpec *DatadogAgentSpec) { +func defaultGlobalConfig(ddaSpec *v2alpha1.DatadogAgentSpec) { if ddaSpec.Global == nil { - ddaSpec.Global = &GlobalConfig{} + ddaSpec.Global = &v2alpha1.GlobalConfig{} } if ddaSpec.Global.Site == nil { @@ -147,15 +148,15 @@ func defaultGlobalConfig(ddaSpec *DatadogAgentSpec) { if ddaSpec.Global.Registry == nil { switch *ddaSpec.Global.Site { case defaultEuropeSite: - ddaSpec.Global.Registry = apiutils.NewStringPointer(DefaultEuropeImageRegistry) + ddaSpec.Global.Registry = apiutils.NewStringPointer(v2alpha1.DefaultEuropeImageRegistry) case defaultAsiaSite: - ddaSpec.Global.Registry = apiutils.NewStringPointer(DefaultAsiaImageRegistry) + ddaSpec.Global.Registry = apiutils.NewStringPointer(v2alpha1.DefaultAsiaImageRegistry) case defaultAzureSite: - ddaSpec.Global.Registry = apiutils.NewStringPointer(DefaultAzureImageRegistry) + ddaSpec.Global.Registry = apiutils.NewStringPointer(v2alpha1.DefaultAzureImageRegistry) case defaultGovSite: - ddaSpec.Global.Registry = apiutils.NewStringPointer(DefaultGovImageRegistry) + ddaSpec.Global.Registry = apiutils.NewStringPointer(v2alpha1.DefaultGovImageRegistry) default: - ddaSpec.Global.Registry = apiutils.NewStringPointer(DefaultImageRegistry) + ddaSpec.Global.Registry = apiutils.NewStringPointer(v2alpha1.DefaultImageRegistry) } } @@ -169,13 +170,13 @@ func defaultGlobalConfig(ddaSpec *DatadogAgentSpec) { } if ddaSpec.Global.FIPS == nil { - ddaSpec.Global.FIPS = &FIPSConfig{} + ddaSpec.Global.FIPS = &v2alpha1.FIPSConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Global.FIPS.Enabled, defaultFIPSEnabled) if *ddaSpec.Global.FIPS.Enabled { if ddaSpec.Global.FIPS.Image == nil { - ddaSpec.Global.FIPS.Image = &AgentImageConfig{} + ddaSpec.Global.FIPS.Image = &v2alpha1.AgentImageConfig{} } if ddaSpec.Global.FIPS.Image.Name == "" { ddaSpec.Global.FIPS.Image.Name = defaultFIPSImageName @@ -194,14 +195,14 @@ func defaultGlobalConfig(ddaSpec *DatadogAgentSpec) { // defaultFeaturesConfig sets default values in DatadogAgentSpec.Features. // Note: many default values are set in the Datadog Agent code and are not set here. -func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { +func defaultFeaturesConfig(ddaSpec *v2alpha1.DatadogAgentSpec) { if ddaSpec.Features == nil { - ddaSpec.Features = &DatadogFeatures{} + ddaSpec.Features = &v2alpha1.DatadogFeatures{} } // LogsCollection Feature if ddaSpec.Features.LogCollection == nil { - ddaSpec.Features.LogCollection = &LogCollectionFeatureConfig{} + ddaSpec.Features.LogCollection = &v2alpha1.LogCollectionFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.LogCollection.Enabled, defaultLogCollectionEnabled) @@ -214,67 +215,67 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { apiutils.DefaultStringIfUnset(&ddaSpec.Features.LogCollection.ContainerSymlinksPath, defaultLogContainerSymlinksPath) - apiutils.DefaultStringIfUnset(&ddaSpec.Features.LogCollection.TempStoragePath, DefaultLogTempStoragePath) + apiutils.DefaultStringIfUnset(&ddaSpec.Features.LogCollection.TempStoragePath, v2alpha1.DefaultLogTempStoragePath) } // LiveContainerCollection Feature if ddaSpec.Features.LiveContainerCollection == nil { - ddaSpec.Features.LiveContainerCollection = &LiveContainerCollectionFeatureConfig{} + ddaSpec.Features.LiveContainerCollection = &v2alpha1.LiveContainerCollectionFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.LiveContainerCollection.Enabled, defaultLiveContainerCollectionEnabled) // OTelCollector Feature if ddaSpec.Features.OtelCollector == nil { - ddaSpec.Features.OtelCollector = &OtelCollectorFeatureConfig{} + ddaSpec.Features.OtelCollector = &v2alpha1.OtelCollectorFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OtelCollector.Enabled, defaultOtelCollectorEnabled) // LiveProcessCollection Feature if ddaSpec.Features.LiveProcessCollection == nil { - ddaSpec.Features.LiveProcessCollection = &LiveProcessCollectionFeatureConfig{} + ddaSpec.Features.LiveProcessCollection = &v2alpha1.LiveProcessCollectionFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.LiveProcessCollection.Enabled, defaultLiveProcessCollectionEnabled) // ProcessDiscovery Feature if ddaSpec.Features.ProcessDiscovery == nil { - ddaSpec.Features.ProcessDiscovery = &ProcessDiscoveryFeatureConfig{} + ddaSpec.Features.ProcessDiscovery = &v2alpha1.ProcessDiscoveryFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.ProcessDiscovery.Enabled, defaultProcessDiscoveryEnabled) // OOMKill Feature if ddaSpec.Features.OOMKill == nil { - ddaSpec.Features.OOMKill = &OOMKillFeatureConfig{} + ddaSpec.Features.OOMKill = &v2alpha1.OOMKillFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OOMKill.Enabled, defaultOOMKillEnabled) // TCPQueueLength Feature if ddaSpec.Features.TCPQueueLength == nil { - ddaSpec.Features.TCPQueueLength = &TCPQueueLengthFeatureConfig{} + ddaSpec.Features.TCPQueueLength = &v2alpha1.TCPQueueLengthFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.TCPQueueLength.Enabled, defaultTCPQueueLengthEnabled) // EBPFCheck Feature if ddaSpec.Features.EBPFCheck == nil { - ddaSpec.Features.EBPFCheck = &EBPFCheckFeatureConfig{} + ddaSpec.Features.EBPFCheck = &v2alpha1.EBPFCheckFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.EBPFCheck.Enabled, defaultEBPFCheckEnabled) if ddaSpec.Features.ServiceDiscovery == nil { - ddaSpec.Features.ServiceDiscovery = &ServiceDiscoveryFeatureConfig{} + ddaSpec.Features.ServiceDiscovery = &v2alpha1.ServiceDiscoveryFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.ServiceDiscovery.Enabled, defaultServiceDiscoveryEnabled) // APM Feature // APM is enabled by default if ddaSpec.Features.APM == nil { - ddaSpec.Features.APM = &APMFeatureConfig{} + ddaSpec.Features.APM = &v2alpha1.APMFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.APM.Enabled, defaultAPMEnabled) if *ddaSpec.Features.APM.Enabled { if ddaSpec.Features.APM.HostPortConfig == nil { - ddaSpec.Features.APM.HostPortConfig = &HostPortConfig{} + ddaSpec.Features.APM.HostPortConfig = &v2alpha1.HostPortConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.APM.HostPortConfig.Enabled, defaultAPMHostPortEnabled) @@ -282,7 +283,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { apiutils.DefaultInt32IfUnset(&ddaSpec.Features.APM.HostPortConfig.Port, defaultAPMHostPort) if ddaSpec.Features.APM.UnixDomainSocketConfig == nil { - ddaSpec.Features.APM.UnixDomainSocketConfig = &UnixDomainSocketConfig{} + ddaSpec.Features.APM.UnixDomainSocketConfig = &v2alpha1.UnixDomainSocketConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.APM.UnixDomainSocketConfig.Enabled, defaultAPMSocketEnabled) @@ -290,11 +291,11 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { apiutils.DefaultStringIfUnset(&ddaSpec.Features.APM.UnixDomainSocketConfig.Path, defaultAPMSocketHostPath) if ddaSpec.Features.APM.SingleStepInstrumentation == nil { - ddaSpec.Features.APM.SingleStepInstrumentation = &SingleStepInstrumentation{} + ddaSpec.Features.APM.SingleStepInstrumentation = &v2alpha1.SingleStepInstrumentation{} } if ddaSpec.Features.APM.SingleStepInstrumentation.LanguageDetection == nil { - ddaSpec.Features.APM.SingleStepInstrumentation.LanguageDetection = &LanguageDetectionConfig{} + ddaSpec.Features.APM.SingleStepInstrumentation.LanguageDetection = &v2alpha1.LanguageDetectionConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.APM.SingleStepInstrumentation.Enabled, defaultAPMSingleStepInstrEnabled) @@ -303,49 +304,49 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // ASM Features if ddaSpec.Features.ASM == nil { - ddaSpec.Features.ASM = &ASMFeatureConfig{} + ddaSpec.Features.ASM = &v2alpha1.ASMFeatureConfig{} } if ddaSpec.Features.ASM.Threats == nil { - ddaSpec.Features.ASM.Threats = &ASMThreatsConfig{} + ddaSpec.Features.ASM.Threats = &v2alpha1.ASMThreatsConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.ASM.Threats.Enabled, defaultAdmissionASMThreatsEnabled) if ddaSpec.Features.ASM.SCA == nil { - ddaSpec.Features.ASM.SCA = &ASMSCAConfig{} + ddaSpec.Features.ASM.SCA = &v2alpha1.ASMSCAConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.ASM.SCA.Enabled, defaultAdmissionASMSCAEnabled) if ddaSpec.Features.ASM.IAST == nil { - ddaSpec.Features.ASM.IAST = &ASMIASTConfig{} + ddaSpec.Features.ASM.IAST = &v2alpha1.ASMIASTConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.ASM.IAST.Enabled, defaultAdmissionASMIASTEnabled) // CSPM (Cloud Security Posture Management) Feature if ddaSpec.Features.CSPM == nil { - ddaSpec.Features.CSPM = &CSPMFeatureConfig{} + ddaSpec.Features.CSPM = &v2alpha1.CSPMFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.CSPM.Enabled, defaultCSPMEnabled) if *ddaSpec.Features.CSPM.Enabled { if ddaSpec.Features.CSPM.HostBenchmarks == nil { - ddaSpec.Features.CSPM.HostBenchmarks = &CSPMHostBenchmarksConfig{} + ddaSpec.Features.CSPM.HostBenchmarks = &v2alpha1.CSPMHostBenchmarksConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.CSPM.HostBenchmarks.Enabled, defaultCSPMHostBenchmarksEnabled) } // CWS (Cloud Workload Security) Feature if ddaSpec.Features.CWS == nil { - ddaSpec.Features.CWS = &CWSFeatureConfig{} + ddaSpec.Features.CWS = &v2alpha1.CWSFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.CWS.Enabled, defaultCWSEnabled) if *ddaSpec.Features.CWS.Enabled { if ddaSpec.Features.CWS.Network == nil { - ddaSpec.Features.CWS.Network = &CWSNetworkConfig{} + ddaSpec.Features.CWS.Network = &v2alpha1.CWSNetworkConfig{} } if ddaSpec.Features.CWS.SecurityProfiles == nil { - ddaSpec.Features.CWS.SecurityProfiles = &CWSSecurityProfilesConfig{} + ddaSpec.Features.CWS.SecurityProfiles = &v2alpha1.CWSSecurityProfilesConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.CWS.SyscallMonitorEnabled, defaultCWSSyscallMonitorEnabled) @@ -355,7 +356,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // NPM (Network Performance Monitoring) Feature if ddaSpec.Features.NPM == nil { - ddaSpec.Features.NPM = &NPMFeatureConfig{} + ddaSpec.Features.NPM = &v2alpha1.NPMFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.NPM.Enabled, defaultNPMEnabled) @@ -366,28 +367,28 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // USM (Universal Service Monitoring) Feature if ddaSpec.Features.USM == nil { - ddaSpec.Features.USM = &USMFeatureConfig{} + ddaSpec.Features.USM = &v2alpha1.USMFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.USM.Enabled, defaultUSMEnabled) // Dogstatsd Feature if ddaSpec.Features.Dogstatsd == nil { - ddaSpec.Features.Dogstatsd = &DogstatsdFeatureConfig{} + ddaSpec.Features.Dogstatsd = &v2alpha1.DogstatsdFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.Dogstatsd.OriginDetectionEnabled, defaultDogstatsdOriginDetectionEnabled) if ddaSpec.Features.Dogstatsd.HostPortConfig == nil { - ddaSpec.Features.Dogstatsd.HostPortConfig = &HostPortConfig{ + ddaSpec.Features.Dogstatsd.HostPortConfig = &v2alpha1.HostPortConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled), } } if *ddaSpec.Features.Dogstatsd.HostPortConfig.Enabled { - apiutils.DefaultInt32IfUnset(&ddaSpec.Features.Dogstatsd.HostPortConfig.Port, DefaultDogstatsdPort) + apiutils.DefaultInt32IfUnset(&ddaSpec.Features.Dogstatsd.HostPortConfig.Port, v2alpha1.DefaultDogstatsdPort) } if ddaSpec.Features.Dogstatsd.UnixDomainSocketConfig == nil { - ddaSpec.Features.Dogstatsd.UnixDomainSocketConfig = &UnixDomainSocketConfig{} + ddaSpec.Features.Dogstatsd.UnixDomainSocketConfig = &v2alpha1.UnixDomainSocketConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.Dogstatsd.UnixDomainSocketConfig.Enabled, defaultDogstatsdSocketEnabled) @@ -397,18 +398,18 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // OTLP ingest feature if ddaSpec.Features.OTLP == nil { - ddaSpec.Features.OTLP = &OTLPFeatureConfig{} + ddaSpec.Features.OTLP = &v2alpha1.OTLPFeatureConfig{} } if ddaSpec.Features.OTLP.Receiver.Protocols.GRPC == nil { - ddaSpec.Features.OTLP.Receiver.Protocols.GRPC = &OTLPGRPCConfig{} + ddaSpec.Features.OTLP.Receiver.Protocols.GRPC = &v2alpha1.OTLPGRPCConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Enabled, defaultOTLPGRPCEnabled) if apiutils.BoolValue(ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Enabled) { if ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig == nil { - ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig = &HostPortConfig{} + ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig = &v2alpha1.HostPortConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig.Enabled, defaultOTLPGRPCHostPortEnabled) } @@ -416,14 +417,14 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { apiutils.DefaultStringIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Endpoint, defaultOTLPGRPCEndpoint) if ddaSpec.Features.OTLP.Receiver.Protocols.HTTP == nil { - ddaSpec.Features.OTLP.Receiver.Protocols.HTTP = &OTLPHTTPConfig{} + ddaSpec.Features.OTLP.Receiver.Protocols.HTTP = &v2alpha1.OTLPHTTPConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.Enabled, defaultOTLPHTTPEnabled) if apiutils.BoolValue(ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.Enabled) { if ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig == nil { - ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig = &HostPortConfig{} + ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig = &v2alpha1.HostPortConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig.Enabled, defaultOTLPHTTPHostPortEnabled) } @@ -432,7 +433,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // RemoteConfiguration feature if ddaSpec.Features.RemoteConfiguration == nil { - ddaSpec.Features.RemoteConfiguration = &RemoteConfigurationFeatureConfig{} + ddaSpec.Features.RemoteConfiguration = &v2alpha1.RemoteConfigurationFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.RemoteConfiguration.Enabled, defaultRemoteConfigurationEnabled) @@ -440,11 +441,11 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // EventCollection Feature if ddaSpec.Features.EventCollection == nil { - ddaSpec.Features.EventCollection = &EventCollectionFeatureConfig{} + ddaSpec.Features.EventCollection = &v2alpha1.EventCollectionFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.EventCollection.CollectKubernetesEvents, defaultCollectKubernetesEvents) if apiutils.BoolValue(ddaSpec.Features.EventCollection.UnbundleEvents) && ddaSpec.Features.EventCollection.CollectedEventTypes == nil { - ddaSpec.Features.EventCollection.CollectedEventTypes = []EventTypes{ + ddaSpec.Features.EventCollection.CollectedEventTypes = []v2alpha1.EventTypes{ { Kind: "Pod", Reasons: []string{"Failed", "BackOff", "Unhealthy", "FailedScheduling", "FailedMount", "FailedAttachVolume"}, @@ -462,7 +463,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // OrchestratorExplorer check Feature if ddaSpec.Features.OrchestratorExplorer == nil { - ddaSpec.Features.OrchestratorExplorer = &OrchestratorExplorerFeatureConfig{} + ddaSpec.Features.OrchestratorExplorer = &v2alpha1.OrchestratorExplorerFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OrchestratorExplorer.Enabled, defaultOrchestratorExplorerEnabled) @@ -472,13 +473,13 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // KubeStateMetricsCore check Feature if ddaSpec.Features.KubeStateMetricsCore == nil { - ddaSpec.Features.KubeStateMetricsCore = &KubeStateMetricsCoreFeatureConfig{} + ddaSpec.Features.KubeStateMetricsCore = &v2alpha1.KubeStateMetricsCoreFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.KubeStateMetricsCore.Enabled, defaultKubeStateMetricsCoreEnabled) // AdmissionController Feature if ddaSpec.Features.AdmissionController == nil { - ddaSpec.Features.AdmissionController = &AdmissionControllerFeatureConfig{} + ddaSpec.Features.AdmissionController = &v2alpha1.AdmissionControllerFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.AdmissionController.Enabled, defaultAdmissionControllerEnabled) @@ -490,13 +491,13 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // AdmissionControllerValidation Feature if ddaSpec.Features.AdmissionController.Validation == nil { - ddaSpec.Features.AdmissionController.Validation = &AdmissionControllerValidationConfig{} + ddaSpec.Features.AdmissionController.Validation = &v2alpha1.AdmissionControllerValidationConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.AdmissionController.Validation.Enabled, defaultAdmissionControllerValidationEnabled) // AdmissionControllerMutation Feature if ddaSpec.Features.AdmissionController.Mutation == nil { - ddaSpec.Features.AdmissionController.Mutation = &AdmissionControllerMutationConfig{} + ddaSpec.Features.AdmissionController.Mutation = &v2alpha1.AdmissionControllerMutationConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.AdmissionController.Mutation.Enabled, defaultAdmissionControllerMutationEnabled) @@ -507,13 +508,13 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // K8s Admission Events in AdmissonController Feature if ddaSpec.Features.AdmissionController.KubernetesAdmissionEvents == nil { - ddaSpec.Features.AdmissionController.KubernetesAdmissionEvents = &KubernetesAdmissionEventsConfig{} + ddaSpec.Features.AdmissionController.KubernetesAdmissionEvents = &v2alpha1.KubernetesAdmissionEventsConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.AdmissionController.KubernetesAdmissionEvents.Enabled, defaultAdmissionControllerKubernetesAdmissionEventsEnabled) // CWS Instrumentation in AdmissionController Feature if ddaSpec.Features.AdmissionController.CWSInstrumentation == nil { - ddaSpec.Features.AdmissionController.CWSInstrumentation = &CWSInstrumentationConfig{} + ddaSpec.Features.AdmissionController.CWSInstrumentation = &v2alpha1.CWSInstrumentationConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.AdmissionController.CWSInstrumentation.Enabled, DefaultAdmissionControllerCWSInstrumentationEnabled) @@ -523,7 +524,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // ExternalMetricsServer Feature if ddaSpec.Features.ExternalMetricsServer == nil { - ddaSpec.Features.ExternalMetricsServer = &ExternalMetricsServerFeatureConfig{} + ddaSpec.Features.ExternalMetricsServer = &v2alpha1.ExternalMetricsServerFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.ExternalMetricsServer.Enabled, defaultExternalMetricsServerEnabled) @@ -535,7 +536,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // ClusterChecks Feature if ddaSpec.Features.ClusterChecks == nil { - ddaSpec.Features.ClusterChecks = &ClusterChecksFeatureConfig{} + ddaSpec.Features.ClusterChecks = &v2alpha1.ClusterChecksFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.ClusterChecks.Enabled, defaultClusterChecksEnabled) @@ -545,7 +546,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // PrometheusScrape Feature if ddaSpec.Features.PrometheusScrape == nil { - ddaSpec.Features.PrometheusScrape = &PrometheusScrapeFeatureConfig{} + ddaSpec.Features.PrometheusScrape = &v2alpha1.PrometheusScrapeFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.PrometheusScrape.Enabled, defaultPrometheusScrapeEnabled) @@ -556,7 +557,7 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) { // Helm Check Feature if ddaSpec.Features.HelmCheck == nil { - ddaSpec.Features.HelmCheck = &HelmCheckFeatureConfig{} + ddaSpec.Features.HelmCheck = &v2alpha1.HelmCheckFeatureConfig{} } apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.HelmCheck.Enabled, defaultHelmCheckEnabled) diff --git a/api/datadoghq/v2alpha1/datadogagent_default_test.go b/internal/controller/datadogagent/defaults/datadogagent_default_test.go similarity index 58% rename from api/datadoghq/v2alpha1/datadogagent_default_test.go rename to internal/controller/datadogagent/defaults/datadogagent_default_test.go index 35804fce8..98d61fd6b 100644 --- a/api/datadoghq/v2alpha1/datadogagent_default_test.go +++ b/internal/controller/datadogagent/defaults/datadogagent_default_test.go @@ -3,11 +3,12 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -package v2alpha1 +package defaults import ( "testing" + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/google/go-cmp/cmp" @@ -22,112 +23,112 @@ const ( func Test_defaultGlobal(t *testing.T) { tests := []struct { name string - ddaSpec *DatadogAgentSpec - want *DatadogAgentSpec + ddaSpec *v2alpha1.DatadogAgentSpec + want *v2alpha1.DatadogAgentSpec }{ { name: "global is nil", - ddaSpec: &DatadogAgentSpec{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ Global: nil, }, - want: &DatadogAgentSpec{ - Global: &GlobalConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultSite), - Registry: apiutils.NewStringPointer(DefaultImageRegistry), + Registry: apiutils.NewStringPointer(v2alpha1.DefaultImageRegistry), LogLevel: apiutils.NewStringPointer(defaultLogLevel), }, }, }, { name: "test registry defaulting based on site - EU", - ddaSpec: &DatadogAgentSpec{ - Global: &GlobalConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultEuropeSite), }, }, - want: &DatadogAgentSpec{ - Global: &GlobalConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultEuropeSite), - Registry: apiutils.NewStringPointer(DefaultEuropeImageRegistry), + Registry: apiutils.NewStringPointer(v2alpha1.DefaultEuropeImageRegistry), LogLevel: apiutils.NewStringPointer(defaultLogLevel), }, }, }, { name: "test registry defaulting based on site - Asia", - ddaSpec: &DatadogAgentSpec{ - Global: &GlobalConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultAsiaSite), }, }, - want: &DatadogAgentSpec{ - Global: &GlobalConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultAsiaSite), - Registry: apiutils.NewStringPointer(DefaultAsiaImageRegistry), + Registry: apiutils.NewStringPointer(v2alpha1.DefaultAsiaImageRegistry), LogLevel: apiutils.NewStringPointer(defaultLogLevel), }, }, }, { name: "test registry defaulting based on site - Azure", - ddaSpec: &DatadogAgentSpec{ - Global: &GlobalConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultAzureSite), }, }, - want: &DatadogAgentSpec{ - Global: &GlobalConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultAzureSite), - Registry: apiutils.NewStringPointer(DefaultAzureImageRegistry), + Registry: apiutils.NewStringPointer(v2alpha1.DefaultAzureImageRegistry), LogLevel: apiutils.NewStringPointer(defaultLogLevel), }, }, }, { name: "test registry defaulting based on site - Gov", - ddaSpec: &DatadogAgentSpec{ - Global: &GlobalConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultGovSite), }, }, - want: &DatadogAgentSpec{ - Global: &GlobalConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ Site: apiutils.NewStringPointer(defaultGovSite), - Registry: apiutils.NewStringPointer(DefaultGovImageRegistry), + Registry: apiutils.NewStringPointer(v2alpha1.DefaultGovImageRegistry), LogLevel: apiutils.NewStringPointer(defaultLogLevel), }, }, }, { name: "test FIPS defaulting - disabled", - ddaSpec: &DatadogAgentSpec{ - Global: &GlobalConfig{}, + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{}, }, - want: &DatadogAgentSpec{ - Global: &GlobalConfig{ - FIPS: &FIPSConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ + FIPS: &v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(defaultFIPSEnabled), }, Site: apiutils.NewStringPointer(defaultSite), - Registry: apiutils.NewStringPointer(DefaultImageRegistry), + Registry: apiutils.NewStringPointer(v2alpha1.DefaultImageRegistry), LogLevel: apiutils.NewStringPointer(defaultLogLevel), }, }, }, { name: "test FIPS defaulting - enabled", - ddaSpec: &DatadogAgentSpec{ - Global: &GlobalConfig{ - FIPS: &FIPSConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ + FIPS: &v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(true), }, }, }, - want: &DatadogAgentSpec{ - Global: &GlobalConfig{ - FIPS: &FIPSConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Global: &v2alpha1.GlobalConfig{ + FIPS: &v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(true), - Image: &AgentImageConfig{ + Image: &v2alpha1.AgentImageConfig{ Name: defaultFIPSImageName, Tag: defaultFIPSImageTag, }, @@ -137,7 +138,7 @@ func Test_defaultGlobal(t *testing.T) { UseHTTPS: apiutils.NewBoolPointer(defaultFIPSUseHTTPS), }, Site: apiutils.NewStringPointer(defaultSite), - Registry: apiutils.NewStringPointer(DefaultImageRegistry), + Registry: apiutils.NewStringPointer(v2alpha1.DefaultImageRegistry), LogLevel: apiutils.NewStringPointer(defaultLogLevel), }, }, @@ -163,142 +164,142 @@ func Test_defaultGlobal(t *testing.T) { func Test_defaultFeatures(t *testing.T) { tests := []struct { name string - ddaSpec *DatadogAgentSpec - want *DatadogAgentSpec + ddaSpec *v2alpha1.DatadogAgentSpec + want *v2alpha1.DatadogAgentSpec }{ { name: "all features are nil", - ddaSpec: &DatadogAgentSpec{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ Features: nil, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -306,208 +307,208 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "all features are disabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{Enabled: apiutils.NewBoolPointer(valueFalse)}, - HTTP: &OTLPHTTPConfig{Enabled: apiutils.NewBoolPointer(valueFalse)}, + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{Enabled: apiutils.NewBoolPointer(valueFalse)}, + HTTP: &v2alpha1.OTLPHTTPConfig{Enabled: apiutils.NewBoolPointer(valueFalse)}, }}}, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(valueFalse), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), - Validation: &AdmissionControllerValidationConfig{Enabled: apiutils.NewBoolPointer(valueFalse)}, - Mutation: &AdmissionControllerMutationConfig{Enabled: apiutils.NewBoolPointer(valueFalse)}, + Validation: &v2alpha1.AdmissionControllerValidationConfig{Enabled: apiutils.NewBoolPointer(valueFalse)}, + Mutation: &v2alpha1.AdmissionControllerMutationConfig{Enabled: apiutils.NewBoolPointer(valueFalse)}, }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(valueFalse), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueFalse), }, }, @@ -515,141 +516,141 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "liveProcess is enabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -657,146 +658,146 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "logCollection is enabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), ContainerCollectUsingFiles: apiutils.NewBoolPointer(defaultLogContainerCollectUsingFiles), ContainerLogsPath: apiutils.NewStringPointer(defaultLogContainerLogsPath), PodLogsPath: apiutils.NewStringPointer(defaultLogPodLogsPath), ContainerSymlinksPath: apiutils.NewStringPointer(defaultLogContainerSymlinksPath), - TempStoragePath: apiutils.NewStringPointer(DefaultLogTempStoragePath), + TempStoragePath: apiutils.NewStringPointer(v2alpha1.DefaultLogTempStoragePath), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -804,141 +805,141 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "APM is enabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - APM: &APMFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -946,143 +947,143 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "NPM is enabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - NPM: &NPMFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), EnableConntrack: apiutils.NewBoolPointer(defaultNPMEnableConntrack), CollectDNSStats: apiutils.NewBoolPointer(defaultNPMCollectDNSStats), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -1090,148 +1091,148 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "OTLP is enabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(true), Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(true), Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCHostPortEnabled)}, + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCHostPortEnabled)}, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCHostPortEnabled)}, + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCHostPortEnabled)}, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -1239,144 +1240,144 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "ExternalMetricsServer is enabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), RegisterAPIService: apiutils.NewBoolPointer(defaultRegisterAPIService), UseDatadogMetrics: apiutils.NewBoolPointer(defaultDatadogMetricsEnabled), Port: apiutils.NewInt32Pointer(defaultMetricsProviderPort), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -1384,141 +1385,141 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "ClusterChecks feature with a field set, but \"enabled\" field not set", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - ClusterChecks: &ClusterChecksFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(valueFalse), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -1526,156 +1527,156 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "Admission controller enabled unset, other fields set", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - AdmissionController: &AdmissionControllerFeatureConfig{ - Validation: &AdmissionControllerValidationConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(true), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(true), }, MutateUnlabelled: apiutils.NewBoolPointer(true), AgentCommunicationMode: apiutils.NewStringPointer("socket"), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(true), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(valueTrue), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), AgentCommunicationMode: apiutils.NewStringPointer("socket"), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), Mode: apiutils.NewStringPointer(DefaultAdmissionControllerCWSInstrumentationMode), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -1683,285 +1684,284 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "Orchestrator explorer enabled unset, other fields set", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ CustomResources: []string{"datadoghq.com/v1alpha1/datadogmetrics"}, }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), CustomResources: []string{"datadoghq.com/v1alpha1/datadogmetrics"}, }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, }, }, - { name: "OTel Collector is enabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - OtelCollector: &OtelCollectorFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -1970,162 +1970,162 @@ func Test_defaultFeatures(t *testing.T) { { // This test sets same defaults as the one with `Features: nil`; and leaves other configs as empty structs. name: "all feature configs are empty structs, configures defaults where applicable, leaves others empty", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{}, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{}, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{}, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{}, - OOMKill: &OOMKillFeatureConfig{}, - TCPQueueLength: &TCPQueueLengthFeatureConfig{}, - EBPFCheck: &EBPFCheckFeatureConfig{}, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{}, - APM: &APMFeatureConfig{}, - ASM: &ASMFeatureConfig{}, - CSPM: &CSPMFeatureConfig{}, - CWS: &CWSFeatureConfig{}, - NPM: &NPMFeatureConfig{}, - USM: &USMFeatureConfig{}, - OTLP: &OTLPFeatureConfig{}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{}, - EventCollection: &EventCollectionFeatureConfig{}, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{}, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{}, - AdmissionController: &AdmissionControllerFeatureConfig{}, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{}, - ClusterChecks: &ClusterChecksFeatureConfig{}, - PrometheusScrape: &PrometheusScrapeFeatureConfig{}, - HelmCheck: &HelmCheckFeatureConfig{}, + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{}, + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{}, + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{}, + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{}, + OOMKill: &v2alpha1.OOMKillFeatureConfig{}, + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{}, + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{}, + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{}, + APM: &v2alpha1.APMFeatureConfig{}, + ASM: &v2alpha1.ASMFeatureConfig{}, + CSPM: &v2alpha1.CSPMFeatureConfig{}, + CWS: &v2alpha1.CWSFeatureConfig{}, + NPM: &v2alpha1.NPMFeatureConfig{}, + USM: &v2alpha1.USMFeatureConfig{}, + OTLP: &v2alpha1.OTLPFeatureConfig{}, + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{}, + EventCollection: &v2alpha1.EventCollectionFeatureConfig{}, + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{}, + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{}, + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{}, + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{}, + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{}, + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{}, + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{}, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMEnabled), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSEnabled), }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, @@ -2133,154 +2133,156 @@ func Test_defaultFeatures(t *testing.T) { }, { name: "CSPM and CWS are enabled", - ddaSpec: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - CSPM: &CSPMFeatureConfig{ + ddaSpec: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), }, }, }, - want: &DatadogAgentSpec{ - Features: &DatadogFeatures{ - LogCollection: &LogCollectionFeatureConfig{ + want: &v2alpha1.DatadogAgentSpec{ + Features: &v2alpha1.DatadogFeatures{ + LogCollection: &v2alpha1.LogCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLogCollectionEnabled), }, - LiveProcessCollection: &LiveProcessCollectionFeatureConfig{ + LiveProcessCollection: &v2alpha1.LiveProcessCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveProcessCollectionEnabled), }, - LiveContainerCollection: &LiveContainerCollectionFeatureConfig{ + LiveContainerCollection: &v2alpha1.LiveContainerCollectionFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled), }, - ProcessDiscovery: &ProcessDiscoveryFeatureConfig{ + ProcessDiscovery: &v2alpha1.ProcessDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled), }, - OOMKill: &OOMKillFeatureConfig{ + OOMKill: &v2alpha1.OOMKillFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOOMKillEnabled), }, - TCPQueueLength: &TCPQueueLengthFeatureConfig{ + TCPQueueLength: &v2alpha1.TCPQueueLengthFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultTCPQueueLengthEnabled), }, - EBPFCheck: &EBPFCheckFeatureConfig{ + EBPFCheck: &v2alpha1.EBPFCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultEBPFCheckEnabled), }, - ServiceDiscovery: &ServiceDiscoveryFeatureConfig{ + ServiceDiscovery: &v2alpha1.ServiceDiscoveryFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultServiceDiscoveryEnabled), }, - APM: &APMFeatureConfig{ + APM: &v2alpha1.APMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMEnabled), - HostPortConfig: &HostPortConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{ Port: apiutils.NewInt32Pointer(defaultAPMHostPort), Enabled: apiutils.NewBoolPointer(defaultAPMHostPortEnabled), }, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultAPMSocketEnabled), Path: apiutils.NewStringPointer(defaultAPMSocketHostPath), }, - SingleStepInstrumentation: &SingleStepInstrumentation{ + SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{ Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled), - LanguageDetection: &LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, + LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)}, }, }, - OtelCollector: &OtelCollectorFeatureConfig{ + OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOtelCollectorEnabled), }, - ASM: &ASMFeatureConfig{ - Threats: &ASMThreatsConfig{ + ASM: &v2alpha1.ASMFeatureConfig{ + Threats: &v2alpha1.ASMThreatsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMThreatsEnabled), }, - SCA: &ASMSCAConfig{ + SCA: &v2alpha1.ASMSCAConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMSCAEnabled), }, - IAST: &ASMIASTConfig{ + IAST: &v2alpha1.ASMIASTConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionASMIASTEnabled), }, }, - CSPM: &CSPMFeatureConfig{ + CSPM: &v2alpha1.CSPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), - HostBenchmarks: &CSPMHostBenchmarksConfig{ + HostBenchmarks: &v2alpha1.CSPMHostBenchmarksConfig{ Enabled: apiutils.NewBoolPointer(defaultCSPMHostBenchmarksEnabled), }, }, - CWS: &CWSFeatureConfig{ + CWS: &v2alpha1.CWSFeatureConfig{ Enabled: apiutils.NewBoolPointer(valueTrue), SyscallMonitorEnabled: apiutils.NewBoolPointer(defaultCWSSyscallMonitorEnabled), - Network: &CWSNetworkConfig{ + Network: &v2alpha1.CWSNetworkConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSNetworkEnabled), }, - SecurityProfiles: &CWSSecurityProfilesConfig{ + SecurityProfiles: &v2alpha1.CWSSecurityProfilesConfig{ Enabled: apiutils.NewBoolPointer(defaultCWSSecurityProfilesEnabled), }, }, - NPM: &NPMFeatureConfig{ + NPM: &v2alpha1.NPMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultNPMEnabled), }, - USM: &USMFeatureConfig{ + USM: &v2alpha1.USMFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultUSMEnabled), }, - Dogstatsd: &DogstatsdFeatureConfig{ + Dogstatsd: &v2alpha1.DogstatsdFeatureConfig{ OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled), - HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, - UnixDomainSocketConfig: &UnixDomainSocketConfig{ + HostPortConfig: &v2alpha1.HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)}, + UnixDomainSocketConfig: &v2alpha1.UnixDomainSocketConfig{ Enabled: apiutils.NewBoolPointer(defaultDogstatsdSocketEnabled), Path: apiutils.NewStringPointer(defaultDogstatsdHostSocketPath), }, }, - OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{ - GRPC: &OTLPGRPCConfig{ + OTLP: &v2alpha1.OTLPFeatureConfig{Receiver: v2alpha1.OTLPReceiverConfig{Protocols: v2alpha1.OTLPProtocolsConfig{ + GRPC: &v2alpha1.OTLPGRPCConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint), }, - HTTP: &OTLPHTTPConfig{ + HTTP: &v2alpha1.OTLPHTTPConfig{ Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled), HostPortConfig: nil, Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint), }, - }}}, - RemoteConfiguration: &RemoteConfigurationFeatureConfig{ + }, + }, + }, + RemoteConfiguration: &v2alpha1.RemoteConfigurationFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultRemoteConfigurationEnabled), }, - EventCollection: &EventCollectionFeatureConfig{ + EventCollection: &v2alpha1.EventCollectionFeatureConfig{ CollectKubernetesEvents: apiutils.NewBoolPointer(defaultCollectKubernetesEvents), }, - OrchestratorExplorer: &OrchestratorExplorerFeatureConfig{ + OrchestratorExplorer: &v2alpha1.OrchestratorExplorerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultOrchestratorExplorerEnabled), ScrubContainers: apiutils.NewBoolPointer(defaultOrchestratorExplorerScrubContainers), }, - ExternalMetricsServer: &ExternalMetricsServerFeatureConfig{ + ExternalMetricsServer: &v2alpha1.ExternalMetricsServerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultExternalMetricsServerEnabled), }, - KubeStateMetricsCore: &KubeStateMetricsCoreFeatureConfig{ + KubeStateMetricsCore: &v2alpha1.KubeStateMetricsCoreFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultKubeStateMetricsCoreEnabled), }, - ClusterChecks: &ClusterChecksFeatureConfig{ + ClusterChecks: &v2alpha1.ClusterChecksFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultClusterChecksEnabled), UseClusterChecksRunners: apiutils.NewBoolPointer(defaultUseClusterChecksRunners), }, - AdmissionController: &AdmissionControllerFeatureConfig{ + AdmissionController: &v2alpha1.AdmissionControllerFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerEnabled), - Validation: &AdmissionControllerValidationConfig{ + Validation: &v2alpha1.AdmissionControllerValidationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerValidationEnabled), }, - Mutation: &AdmissionControllerMutationConfig{ + Mutation: &v2alpha1.AdmissionControllerMutationConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerMutationEnabled), }, MutateUnlabelled: apiutils.NewBoolPointer(defaultAdmissionControllerMutateUnlabelled), ServiceName: apiutils.NewStringPointer(defaultAdmissionServiceName), - CWSInstrumentation: &CWSInstrumentationConfig{ + CWSInstrumentation: &v2alpha1.CWSInstrumentationConfig{ Enabled: apiutils.NewBoolPointer(DefaultAdmissionControllerCWSInstrumentationEnabled), }, - KubernetesAdmissionEvents: &KubernetesAdmissionEventsConfig{ + KubernetesAdmissionEvents: &v2alpha1.KubernetesAdmissionEventsConfig{ Enabled: apiutils.NewBoolPointer(defaultAdmissionControllerKubernetesAdmissionEventsEnabled), }, }, - PrometheusScrape: &PrometheusScrapeFeatureConfig{ + PrometheusScrape: &v2alpha1.PrometheusScrapeFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultPrometheusScrapeEnabled), }, - HelmCheck: &HelmCheckFeatureConfig{ + HelmCheck: &v2alpha1.HelmCheckFeatureConfig{ Enabled: apiutils.NewBoolPointer(defaultHelmCheckEnabled), }, }, diff --git a/internal/controller/datadogagent/feature/admissioncontroller/feature.go b/internal/controller/datadogagent/feature/admissioncontroller/feature.go index f2720a2fe..9d72a7b33 100644 --- a/internal/controller/datadogagent/feature/admissioncontroller/feature.go +++ b/internal/controller/datadogagent/feature/admissioncontroller/feature.go @@ -16,6 +16,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/objects" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" cilium "github.com/DataDog/datadog-operator/pkg/cilium/v1" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/defaulting" corev1 "k8s.io/api/core/v1" @@ -92,7 +93,7 @@ func shouldEnablesidecarInjection(sidecarInjectionConf *v2alpha1.AgentSidecarInj func (f *admissionControllerFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.RequiredComponents) { f.owner = dda - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) ac := dda.Spec.Features.AdmissionController @@ -128,7 +129,7 @@ func (f *admissionControllerFeature) Configure(dda *v2alpha1.DatadogAgent) (reqC } // otherwise don't set to fall back to default agent setting `hostip` } - f.localServiceName = v2alpha1.GetLocalAgentServiceName(dda) + f.localServiceName = constants.GetLocalAgentServiceName(dda) reqComp = feature.RequiredComponents{ ClusterAgent: feature.RequiredComponent{IsRequired: apiutils.NewBoolPointer(true)}, } @@ -150,7 +151,7 @@ func (f *admissionControllerFeature) Configure(dda *v2alpha1.DatadogAgent) (reqC f.kubernetesAdmissionEvents = &KubernetesAdmissionEventConfig{enabled: true} } - _, f.networkPolicy = v2alpha1.IsNetworkPolicyEnabled(dda) + _, f.networkPolicy = constants.IsNetworkPolicyEnabled(dda) sidecarConfig := dda.Spec.Features.AdmissionController.AgentSidecarInjection if shouldEnablesidecarInjection(sidecarConfig) { @@ -240,7 +241,7 @@ func (f *admissionControllerFeature) ManageDependencies(managers feature.Resourc // service selector := map[string]string{ apicommon.AgentDeploymentNameLabelKey: f.owner.GetName(), - apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, } port := []corev1.ServicePort{ { diff --git a/internal/controller/datadogagent/feature/admissioncontroller/feature_test.go b/internal/controller/datadogagent/feature/admissioncontroller/feature_test.go index 9e2963b95..80eaeabd4 100644 --- a/internal/controller/datadogagent/feature/admissioncontroller/feature_test.go +++ b/internal/controller/datadogagent/feature/admissioncontroller/feature_test.go @@ -9,12 +9,12 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" defaulting "github.com/DataDog/datadog-operator/pkg/defaulting" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -25,13 +25,13 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "Admission Controller not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). Build(), WantConfigure: false, }, { Name: "Admission Controller enabled with basic setup", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). Build(), WantConfigure: true, @@ -40,7 +40,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with validation and mutation enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithAdmissionControllerValidationEnabled(true). WithAdmissionControllerMutationEnabled(true). @@ -51,7 +51,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission controller enabled, cwsInstrumentation enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithCWSInstrumentationEnabled(true). WithCWSInstrumentationMode("test-mode"). @@ -62,7 +62,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with overriding registry", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithRegistry("testRegistry"). Build(), @@ -72,7 +72,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with custom registry in global config, override with feature config", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithAdmissionControllerRegistry("featureRegistry"). WithRegistry("globalRegistry"). @@ -83,7 +83,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with apm uds", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithAPMEnabled(true). WithAPMUDSEnabled(true, "testHostPath"). @@ -94,7 +94,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with DSD uds", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithDogstatsdUnixDomainSocketConfigEnabled(true). Build(), @@ -104,7 +104,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with sidecar basic setup", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithSidecarInjectionEnabled(true). Build(), @@ -114,7 +114,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with sidecar injection adding global registry", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithSidecarInjectionEnabled(true). WithRegistry("globalRegistry"). @@ -125,7 +125,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with sidecar injection adding both sidecar and global registry", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithSidecarInjectionEnabled(true). WithRegistry("globalRegistry"). @@ -137,7 +137,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with sidecar injection adding test sidecar image and tag", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithSidecarInjectionEnabled(true). WithSidecarInjectionImageName("testAgentImage"). @@ -149,7 +149,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with sidecar injection adding global image and tag", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithSidecarInjectionEnabled(true). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ @@ -167,7 +167,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with sidecar injection adding both global and sidecar image and tag", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithSidecarInjectionEnabled(true). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ @@ -185,7 +185,7 @@ func Test_admissionControllerFeature_Configure(t *testing.T) { }, { Name: "Admission Controller enabled with sidecar injection with selector and profile", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithSidecarInjectionEnabled(true). WithSidecarInjectionSelectors("testKey", "testValue"). diff --git a/internal/controller/datadogagent/feature/apm/feature.go b/internal/controller/datadogagent/feature/apm/feature.go index 0390dbc2c..00b74d7e5 100644 --- a/internal/controller/datadogagent/feature/apm/feature.go +++ b/internal/controller/datadogagent/feature/apm/feature.go @@ -26,6 +26,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/merger" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" cilium "github.com/DataDog/datadog-operator/pkg/cilium/v1" + "github.com/DataDog/datadog-operator/pkg/constants" ) func init() { @@ -103,13 +104,13 @@ func (f *apmFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Requ f.owner = dda apm := dda.Spec.Features.APM if shouldEnableAPM(apm) { - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) - f.useHostNetwork = v2alpha1.IsHostNetworkEnabled(dda, v2alpha1.NodeAgentComponentName) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) + f.useHostNetwork = constants.IsHostNetworkEnabled(dda, v2alpha1.NodeAgentComponentName) // hostPort defaults to 'false' in the defaulting code f.hostPortEnabled = apiutils.BoolValue(apm.HostPortConfig.Enabled) f.hostPortHostPort = *apm.HostPortConfig.Port if f.hostPortEnabled { - if enabled, flavor := v2alpha1.IsNetworkPolicyEnabled(dda); enabled { + if enabled, flavor := constants.IsNetworkPolicyEnabled(dda); enabled { if flavor == v2alpha1.NetworkPolicyFlavorCilium { f.createCiliumNetworkPolicy = true } else { @@ -124,7 +125,7 @@ func (f *apmFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Requ if dda.Spec.Global.LocalService != nil { f.forceEnableLocalService = apiutils.BoolValue(dda.Spec.Global.LocalService.ForceEnableLocalService) } - f.localServiceName = v2alpha1.GetLocalAgentServiceName(dda) + f.localServiceName = constants.GetLocalAgentServiceName(dda) reqComp = feature.RequiredComponents{ Agent: feature.RequiredComponent{ @@ -177,9 +178,9 @@ func (f *apmFeature) ManageDependencies(managers feature.ResourceManagers, compo if common.ShouldCreateAgentLocalService(platformInfo.GetVersionInfo(), f.forceEnableLocalService) { apmPort := &corev1.ServicePort{ Protocol: corev1.ProtocolTCP, - TargetPort: intstr.FromInt(int(v2alpha1.DefaultApmPort)), - Port: v2alpha1.DefaultApmPort, - Name: v2alpha1.DefaultApmPortName, + TargetPort: intstr.FromInt(int(constants.DefaultApmPort)), + Port: constants.DefaultApmPort, + Name: constants.DefaultApmPortName, } if f.hostPortEnabled { apmPort.Port = f.hostPortHostPort @@ -337,13 +338,13 @@ func (f *apmFeature) manageNodeAgent(agentContainerName apicommon.AgentContainer // udp apmPort := &corev1.ContainerPort{ - Name: v2alpha1.DefaultApmPortName, - ContainerPort: v2alpha1.DefaultApmPort, + Name: constants.DefaultApmPortName, + ContainerPort: constants.DefaultApmPort, Protocol: corev1.ProtocolTCP, } if f.hostPortEnabled { apmPort.HostPort = f.hostPortHostPort - receiverPortEnvVarValue := v2alpha1.DefaultApmPort + receiverPortEnvVarValue := constants.DefaultApmPort // if using host network, host port should be set and needs to match container port if f.useHostNetwork { apmPort.ContainerPort = f.hostPortHostPort diff --git a/internal/controller/datadogagent/feature/apm/feature_test.go b/internal/controller/datadogagent/feature/apm/feature_test.go index 69b9aa0f6..a85b8629e 100644 --- a/internal/controller/datadogagent/feature/apm/feature_test.go +++ b/internal/controller/datadogagent/feature/apm/feature_test.go @@ -11,7 +11,6 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" "github.com/DataDog/datadog-operator/api/utils" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" @@ -19,6 +18,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" "github.com/DataDog/datadog-operator/pkg/kubernetes" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -78,14 +78,14 @@ func TestAPMFeature(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "apm not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(false). Build(), WantConfigure: false, }, { Name: "apm not enabled with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(false). WithSingleContainerStrategy(true). Build(), @@ -93,7 +93,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, use uds", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(false, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -103,7 +103,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, use uds with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(false, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -114,7 +114,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, use uds and host port", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -124,7 +124,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, use uds and host port with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -135,7 +135,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, use uds and custom host port", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(1234)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -145,7 +145,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, use uds and custom host port with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(1234)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -156,7 +156,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, use uds and host port enabled but no custom host port", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, nil). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -166,7 +166,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, use uds and host port enabled but no custom host port with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, nil). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -177,7 +177,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, host port enabled host network", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, nil). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ @@ -189,7 +189,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, host port enabled host network with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, nil). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ @@ -202,7 +202,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, custom host port host network", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(1234)). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ @@ -214,7 +214,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "apm enabled, custom host port host network with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(1234)). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ @@ -227,7 +227,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "basic apm single step instrumentation", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -240,7 +240,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "error apm single step instrumentation without language detection", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -264,7 +264,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "step instrumentation precedence", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(false). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -275,7 +275,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "step instrumentation w/o AC", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -289,7 +289,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "single step instrumentation namespace specific", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -301,7 +301,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "single step instrumentation with language detection enabled, process check runs in process agent", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -320,7 +320,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "single step instrumentation without language detection enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). @@ -339,7 +339,7 @@ func TestAPMFeature(t *testing.T) { }, { Name: "single step instrumentation with language detection enabled, process check runs in core agent", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)). WithAPMUDSEnabled(true, apmSocketHostPath). diff --git a/internal/controller/datadogagent/feature/asm/feature_test.go b/internal/controller/datadogagent/feature/asm/feature_test.go index f4a33c48d..fd4a3e329 100644 --- a/internal/controller/datadogagent/feature/asm/feature_test.go +++ b/internal/controller/datadogagent/feature/asm/feature_test.go @@ -9,10 +9,10 @@ import ( "testing" apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -52,7 +52,7 @@ func TestASMFeature(t *testing.T) { test.FeatureTestSuite{ { Name: "ASM not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithASMEnabled(false, false, false). Build(), @@ -60,7 +60,7 @@ func TestASMFeature(t *testing.T) { }, { Name: "ASM Threats enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithASMEnabled(true, false, false). Build(), @@ -70,7 +70,7 @@ func TestASMFeature(t *testing.T) { }, { Name: "ASM Threats enabled, admission controller not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(false). WithASMEnabled(true, false, false). Build(), @@ -79,7 +79,7 @@ func TestASMFeature(t *testing.T) { }, { Name: "ASM Threats enabled, admission controller not configured", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithASMEnabled(true, false, false). Build(), @@ -87,7 +87,7 @@ func TestASMFeature(t *testing.T) { }, { Name: "ASM SCA enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithASMEnabled(false, true, false). WithAdmissionControllerEnabled(true). Build(), @@ -97,7 +97,7 @@ func TestASMFeature(t *testing.T) { }, { Name: "ASM IAST enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithASMEnabled(false, false, true). WithAdmissionControllerEnabled(true). Build(), @@ -107,7 +107,7 @@ func TestASMFeature(t *testing.T) { }, { Name: "ASM all enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithAdmissionControllerEnabled(true). WithASMEnabled(true, true, true). Build(), diff --git a/internal/controller/datadogagent/feature/autoscaling/feature.go b/internal/controller/datadogagent/feature/autoscaling/feature.go index 56b107923..2ce02f175 100644 --- a/internal/controller/datadogagent/feature/autoscaling/feature.go +++ b/internal/controller/datadogagent/feature/autoscaling/feature.go @@ -12,6 +12,7 @@ import ( "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" componentdca "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/clusteragent" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/go-logr/logr" @@ -63,7 +64,7 @@ func (f *autoscalingFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feat admission := dda.Spec.Features.AdmissionController f.admissionControllerActivated = apiutils.BoolValue(admission.Enabled) - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) return feature.RequiredComponents{ ClusterAgent: feature.RequiredComponent{IsRequired: apiutils.NewBoolPointer(true)}, diff --git a/internal/controller/datadogagent/feature/clusterchecks/feature.go b/internal/controller/datadogagent/feature/clusterchecks/feature.go index e688aff26..fd780132e 100644 --- a/internal/controller/datadogagent/feature/clusterchecks/feature.go +++ b/internal/controller/datadogagent/feature/clusterchecks/feature.go @@ -13,6 +13,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" cilium "github.com/DataDog/datadog-operator/pkg/cilium/v1" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/go-logr/logr" @@ -60,7 +61,7 @@ func (f *clusterChecksFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp fe f.updateConfigHash(dda) f.owner = dda - if enabled, flavor := v2alpha1.IsNetworkPolicyEnabled(dda); enabled { + if enabled, flavor := constants.IsNetworkPolicyEnabled(dda); enabled { if flavor == v2alpha1.NetworkPolicyFlavorCilium { f.createCiliumNetworkPolicy = true } else { diff --git a/internal/controller/datadogagent/feature/clusterchecks/feature_test.go b/internal/controller/datadogagent/feature/clusterchecks/feature_test.go index adf2ecd6f..f1eaf1055 100644 --- a/internal/controller/datadogagent/feature/clusterchecks/feature_test.go +++ b/internal/controller/datadogagent/feature/clusterchecks/feature_test.go @@ -15,11 +15,11 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -41,7 +41,7 @@ func TestClusterChecksFeature(t *testing.T) { }, { Name: "cluster checks not enabled and runners not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(false). WithClusterChecksUseCLCEnabled(false). Build(), @@ -50,7 +50,7 @@ func TestClusterChecksFeature(t *testing.T) { }, { Name: "cluster checks not enabled and runners enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(false). WithClusterChecksUseCLCEnabled(true). Build(), @@ -59,7 +59,7 @@ func TestClusterChecksFeature(t *testing.T) { }, { Name: "cluster checks enabled and runners not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(true). WithClusterChecksUseCLCEnabled(false). Build(), @@ -69,7 +69,7 @@ func TestClusterChecksFeature(t *testing.T) { }, { Name: "cluster checks enabled and runners not enabled with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(true). WithClusterChecksUseCLCEnabled(false). WithSingleContainerStrategy(true). @@ -80,7 +80,7 @@ func TestClusterChecksFeature(t *testing.T) { }, { Name: "cluster checks enabled and runners enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(true). WithClusterChecksUseCLCEnabled(true). Build(), @@ -91,7 +91,7 @@ func TestClusterChecksFeature(t *testing.T) { }, { Name: "cluster checks enabled and runners enabled with single container strategy", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(true). WithClusterChecksUseCLCEnabled(true). WithSingleContainerStrategy(true). @@ -126,19 +126,19 @@ func TestClusterAgentChecksumsDifferentForDifferentConfig(t *testing.T) { }, }, }, - v2alpha1test.NewDatadogAgentBuilder(). + testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(false). WithClusterChecksUseCLCEnabled(false). Build(), - v2alpha1test.NewDatadogAgentBuilder(). + testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(false). WithClusterChecksUseCLCEnabled(true). Build(), - v2alpha1test.NewDatadogAgentBuilder(). + testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(true). WithClusterChecksUseCLCEnabled(false). Build(), - v2alpha1test.NewDatadogAgentBuilder(). + testutils.NewDatadogAgentBuilder(). WithClusterChecksEnabled(true). WithClusterChecksUseCLCEnabled(true). Build(), diff --git a/internal/controller/datadogagent/feature/cspm/feature.go b/internal/controller/datadogagent/feature/cspm/feature.go index 0848231cd..e97d48fb4 100644 --- a/internal/controller/datadogagent/feature/cspm/feature.go +++ b/internal/controller/datadogagent/feature/cspm/feature.go @@ -15,6 +15,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/configmap" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" @@ -71,7 +72,7 @@ func (f *cspmFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req if cspmConfig != nil && apiutils.BoolValue(cspmConfig.Enabled) { f.enable = true - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) if cspmConfig.CheckInterval != nil { f.checkInterval = strconv.FormatInt(cspmConfig.CheckInterval.Nanoseconds(), 10) @@ -88,7 +89,7 @@ func (f *cspmFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req f.customConfigAnnotationValue = hash f.customConfigAnnotationKey = object.GetChecksumAnnotationKey(feature.CSPMIDType) } - f.configMapName = v2alpha1.GetConfName(dda, f.customConfig, v2alpha1.DefaultCSPMConf) + f.configMapName = constants.GetConfName(dda, f.customConfig, v2alpha1.DefaultCSPMConf) if cspmConfig.HostBenchmarks != nil && apiutils.BoolValue(cspmConfig.HostBenchmarks.Enabled) { f.hostBenchmarksEnabled = true diff --git a/internal/controller/datadogagent/feature/cws/feature.go b/internal/controller/datadogagent/feature/cws/feature.go index aa8631069..2d05eb42f 100644 --- a/internal/controller/datadogagent/feature/cws/feature.go +++ b/internal/controller/datadogagent/feature/cws/feature.go @@ -16,6 +16,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/agent" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/configmap" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/go-logr/logr" @@ -85,7 +86,7 @@ func (f *cwsFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Requ f.customConfigAnnotationValue = hash f.customConfigAnnotationKey = object.GetChecksumAnnotationKey(feature.CWSIDType) } - f.configMapName = v2alpha1.GetConfName(dda, f.customConfig, v2alpha1.DefaultCWSConf) + f.configMapName = constants.GetConfName(dda, f.customConfig, v2alpha1.DefaultCWSConf) if cwsConfig.Network != nil { f.networkEnabled = apiutils.BoolValue(cwsConfig.Network.Enabled) diff --git a/internal/controller/datadogagent/feature/dogstatsd/feature.go b/internal/controller/datadogagent/feature/dogstatsd/feature.go index 7521270ea..cb0fd7080 100644 --- a/internal/controller/datadogagent/feature/dogstatsd/feature.go +++ b/internal/controller/datadogagent/feature/dogstatsd/feature.go @@ -21,6 +21,7 @@ import ( featureutils "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/merger" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/constants" ) func init() { @@ -80,7 +81,7 @@ func (f *dogstatsdFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp featur if dogstatsd.TagCardinality != nil { f.tagCardinality = *dogstatsd.TagCardinality } - f.useHostNetwork = v2alpha1.IsHostNetworkEnabled(dda, v2alpha1.NodeAgentComponentName) + f.useHostNetwork = constants.IsHostNetworkEnabled(dda, v2alpha1.NodeAgentComponentName) if dogstatsd.MapperProfiles != nil { f.mapperProfiles = dogstatsd.MapperProfiles } @@ -88,7 +89,7 @@ func (f *dogstatsdFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp featur if dda.Spec.Global.LocalService != nil { f.forceEnableLocalService = apiutils.BoolValue(dda.Spec.Global.LocalService.ForceEnableLocalService) } - f.localServiceName = v2alpha1.GetLocalAgentServiceName(dda) + f.localServiceName = constants.GetLocalAgentServiceName(dda) f.adpEnabled = featureutils.HasAgentDataPlaneAnnotation(dda) diff --git a/internal/controller/datadogagent/feature/dogstatsd/feature_test.go b/internal/controller/datadogagent/feature/dogstatsd/feature_test.go index 4d39aec73..c61933c4e 100644 --- a/internal/controller/datadogagent/feature/dogstatsd/feature_test.go +++ b/internal/controller/datadogagent/feature/dogstatsd/feature_test.go @@ -11,11 +11,11 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -40,7 +40,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "dogstatsd udp hostport enabled", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdHostPortEnabled(true).BuildWithDefaults(), WantConfigure: true, Agent: test.NewDefaultComponentTest().WithWantFunc( @@ -51,7 +51,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "udp host network", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdHostPortEnabled(true). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ HostNetwork: apiutils.NewBoolPointer(true), @@ -88,7 +88,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "udp host network custom host port", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdHostPortEnabled(true). WithDogstatsdHostPortConfig(1234). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ @@ -126,7 +126,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "udp custom host port", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdHostPortEnabled(true). WithDogstatsdHostPortConfig(1234).BuildWithDefaults(), WantConfigure: true, @@ -160,7 +160,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "udp host port enabled no custom host port", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdHostPortEnabled(true). BuildWithDefaults(), WantConfigure: true, @@ -194,7 +194,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "udp origin detection enabled", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdHostPortEnabled(true). WithDogstatsdOriginDetectionEnabled(true).BuildWithDefaults(), WantConfigure: true, @@ -207,7 +207,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "uds disabled", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdUnixDomainSocketConfigEnabled(false).BuildWithDefaults(), WantConfigure: true, Agent: test.NewDefaultComponentTest().WithWantFunc( @@ -218,7 +218,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "uds custom host filepath", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdUnixDomainSocketConfigPath(customPath).BuildWithDefaults(), WantConfigure: true, Agent: test.NewDefaultComponentTest().WithWantFunc( @@ -249,7 +249,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "uds origin detection", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdOriginDetectionEnabled(true).BuildWithDefaults(), WantConfigure: true, Agent: test.NewDefaultComponentTest().WithWantFunc( @@ -262,7 +262,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "mapper profiles", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdMapperProfiles(customMapperProfilesConf).BuildWithDefaults(), WantConfigure: true, Agent: test.NewDefaultComponentTest().WithWantFunc( @@ -279,7 +279,7 @@ func Test_DogstatsdFeature_Configure(t *testing.T) { }, { Name: "udp origin detection enabled, orchestrator tag cardinality", - DDA: v2alpha1test.NewDefaultDatadogAgentBuilder(). + DDA: testutils.NewDefaultDatadogAgentBuilder(). WithDogstatsdHostPortEnabled(true). WithDogstatsdTagCardinality("orchestrator").BuildWithDefaults(), WantConfigure: true, diff --git a/internal/controller/datadogagent/feature/enabledefault/feature.go b/internal/controller/datadogagent/feature/enabledefault/feature.go index 8532429f6..779033b3a 100644 --- a/internal/controller/datadogagent/feature/enabledefault/feature.go +++ b/internal/controller/datadogagent/feature/enabledefault/feature.go @@ -19,6 +19,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" featureutils "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/DataDog/datadog-operator/pkg/version" @@ -124,13 +125,13 @@ func (f *defaultFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredC trueValue := true f.owner = dda - f.clusterAgent.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) - f.agent.serviceAccountName = v2alpha1.GetAgentServiceAccount(dda) - f.clusterChecksRunner.serviceAccountName = v2alpha1.GetClusterChecksRunnerServiceAccount(dda) + f.clusterAgent.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) + f.agent.serviceAccountName = constants.GetAgentServiceAccount(dda) + f.clusterChecksRunner.serviceAccountName = constants.GetClusterChecksRunnerServiceAccount(dda) - f.clusterAgent.serviceAccountAnnotations = v2alpha1.GetClusterAgentServiceAccountAnnotations(dda) - f.agent.serviceAccountAnnotations = v2alpha1.GetAgentServiceAccountAnnotations(dda) - f.clusterChecksRunner.serviceAccountAnnotations = v2alpha1.GetClusterChecksRunnerServiceAccountAnnotations(dda) + f.clusterAgent.serviceAccountAnnotations = constants.GetClusterAgentServiceAccountAnnotations(dda) + f.agent.serviceAccountAnnotations = constants.GetAgentServiceAccountAnnotations(dda) + f.clusterChecksRunner.serviceAccountAnnotations = constants.GetClusterChecksRunnerServiceAccountAnnotations(dda) if dda.ObjectMeta.Annotations != nil { f.adpEnabled = featureutils.HasAgentDataPlaneAnnotation(dda) diff --git a/internal/controller/datadogagent/feature/enabledefault/feature_test.go b/internal/controller/datadogagent/feature/enabledefault/feature_test.go index f660d1cc0..091fc3b55 100644 --- a/internal/controller/datadogagent/feature/enabledefault/feature_test.go +++ b/internal/controller/datadogagent/feature/enabledefault/feature_test.go @@ -16,10 +16,10 @@ import ( corev1 "k8s.io/api/core/v1" apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" ) type InstallInfoData struct { @@ -71,7 +71,7 @@ func Test_defaultFeature_ManageClusterAgent(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "Manage Cluster Agent service account name env variable", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithName("datadog"). WithEventCollectionKubernetesEvents(true). Build(), diff --git a/internal/controller/datadogagent/feature/enabledefault/rbac.go b/internal/controller/datadogagent/feature/enabledefault/rbac.go index cb7872d82..0b0819f63 100644 --- a/internal/controller/datadogagent/feature/enabledefault/rbac.go +++ b/internal/controller/datadogagent/feature/enabledefault/rbac.go @@ -9,8 +9,8 @@ import ( "fmt" "strings" - "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/common" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils" "github.com/DataDog/datadog-operator/pkg/kubernetes/rbac" @@ -186,7 +186,7 @@ func getLeaderElectionPolicyRuleDCA(dda metav1.Object) []rbacv1.PolicyRule { // getCCRRbacResourcesName returns the Cluster Checks Runner RBAC resource name func getCCRRbacResourcesName(dda metav1.Object) string { - return fmt.Sprintf("%s-%s", dda.GetName(), v2alpha1.DefaultClusterChecksRunnerResourceSuffix) + return fmt.Sprintf("%s-%s", dda.GetName(), constants.DefaultClusterChecksRunnerResourceSuffix) } // getDefaultClusterChecksRunnerClusterRolePolicyRules returns the default Cluster Role Policy Rules for the Cluster Checks Runner diff --git a/internal/controller/datadogagent/feature/enabledefault/utils_test.go b/internal/controller/datadogagent/feature/enabledefault/utils_test.go index 99495cd82..e3036ec4a 100644 --- a/internal/controller/datadogagent/feature/enabledefault/utils_test.go +++ b/internal/controller/datadogagent/feature/enabledefault/utils_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/stretchr/testify/assert" ) @@ -36,7 +36,7 @@ func Test_getDaemonSetNameFromDatadogAgent(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - dda := v2alpha1test.NewDatadogAgentBuilder(). + dda := testutils.NewDatadogAgentBuilder(). WithName(tt.ddaName). WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ Name: &tt.overrideAgentName, @@ -71,7 +71,7 @@ func Test_getDeploymentNameFromDatadogAgent(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - dda := v2alpha1test.NewDatadogAgentBuilder(). + dda := testutils.NewDatadogAgentBuilder(). WithName(tt.ddaName). WithComponentOverride(v2alpha1.ClusterAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ Name: &tt.overrideClusterAgentName, diff --git a/internal/controller/datadogagent/feature/eventcollection/feature.go b/internal/controller/datadogagent/feature/eventcollection/feature.go index e6c58c207..7931ffae2 100644 --- a/internal/controller/datadogagent/feature/eventcollection/feature.go +++ b/internal/controller/datadogagent/feature/eventcollection/feature.go @@ -20,6 +20,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" @@ -69,12 +70,12 @@ func (f *eventCollectionFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp // v2alpha1 configures event collection using the cluster agent only // leader election is enabled by default if dda.Spec.Features != nil && dda.Spec.Features.EventCollection != nil && apiutils.BoolValue(dda.Spec.Features.EventCollection.CollectKubernetesEvents) { - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) f.rbacSuffix = common.ClusterAgentSuffix if apiutils.BoolValue(dda.Spec.Features.EventCollection.UnbundleEvents) { if len(dda.Spec.Features.EventCollection.CollectedEventTypes) > 0 { - f.configMapName = v2alpha1.GetConfName(dda, nil, v2alpha1.DefaultKubeAPIServerConf) + f.configMapName = constants.GetConfName(dda, nil, v2alpha1.DefaultKubeAPIServerConf) f.unbundleEvents = *dda.Spec.Features.EventCollection.UnbundleEvents f.unbundleEventTypes = dda.Spec.Features.EventCollection.CollectedEventTypes } else { diff --git a/internal/controller/datadogagent/feature/eventcollection/feature_test.go b/internal/controller/datadogagent/feature/eventcollection/feature_test.go index bbdf67eef..b5cf6aefe 100644 --- a/internal/controller/datadogagent/feature/eventcollection/feature_test.go +++ b/internal/controller/datadogagent/feature/eventcollection/feature_test.go @@ -12,13 +12,13 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" "github.com/DataDog/datadog-operator/pkg/kubernetes" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -28,14 +28,14 @@ func Test_eventCollectionFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "Event Collection not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithEventCollectionKubernetesEvents(false). Build(), WantConfigure: false, }, { Name: "Event Collection enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithName("ddaDCA"). WithEventCollectionKubernetesEvents(true). Build(), @@ -44,7 +44,7 @@ func Test_eventCollectionFeature_Configure(t *testing.T) { }, { Name: "Unbundle event enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithName("ddaDCA"). WithEventCollectionKubernetesEvents(true). WithEventCollectionUnbundleEvents(true, []v2alpha1.EventTypes{ diff --git a/internal/controller/datadogagent/feature/externalmetrics/feature.go b/internal/controller/datadogagent/feature/externalmetrics/feature.go index 7602f10e6..d73ab8f32 100644 --- a/internal/controller/datadogagent/feature/externalmetrics/feature.go +++ b/internal/controller/datadogagent/feature/externalmetrics/feature.go @@ -17,6 +17,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/objects" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" cilium "github.com/DataDog/datadog-operator/pkg/cilium/v1" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/kubernetes/rbac" "github.com/go-logr/logr" @@ -122,9 +123,9 @@ func (f *externalMetricsFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp } } - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) - if enabled, flavor := v2alpha1.IsNetworkPolicyEnabled(dda); enabled { + if enabled, flavor := constants.IsNetworkPolicyEnabled(dda); enabled { if flavor == v2alpha1.NetworkPolicyFlavorCilium { f.createCiliumNetworkPolicy = true } else { @@ -154,7 +155,7 @@ func (f *externalMetricsFeature) ManageDependencies(managers feature.ResourceMan } selector := map[string]string{ apicommon.AgentDeploymentNameLabelKey: f.owner.GetName(), - apicommon.AgentDeploymentComponentLabelKey: v2alpha1.DefaultClusterAgentResourceSuffix, + apicommon.AgentDeploymentComponentLabelKey: constants.DefaultClusterAgentResourceSuffix, } serviceName := componentdca.GetMetricsServerServiceName(f.owner) if err := managers.ServiceManager().AddService(serviceName, ns, selector, emPorts, nil); err != nil { diff --git a/internal/controller/datadogagent/feature/helmcheck/feature.go b/internal/controller/datadogagent/feature/helmcheck/feature.go index 047fb8e34..6706a36dd 100644 --- a/internal/controller/datadogagent/feature/helmcheck/feature.go +++ b/internal/controller/datadogagent/feature/helmcheck/feature.go @@ -19,6 +19,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" ) @@ -75,12 +76,12 @@ func (f *helmCheckFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp featur f.configMapName = fmt.Sprintf("%s-%s", f.owner.GetName(), v2alpha1.DefaultHelmCheckConf) f.collectEvents = apiutils.BoolValue(helmCheck.CollectEvents) f.valuesAsTags = helmCheck.ValuesAsTags - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) - if v2alpha1.IsClusterChecksEnabled(dda) && v2alpha1.IsCCREnabled(dda) { + if constants.IsClusterChecksEnabled(dda) && constants.IsCCREnabled(dda) { f.runInClusterChecksRunner = true f.rbacSuffix = common.ChecksRunnerSuffix - f.serviceAccountName = v2alpha1.GetClusterChecksRunnerServiceAccount(dda) + f.serviceAccountName = constants.GetClusterChecksRunnerServiceAccount(dda) reqComp.ClusterChecksRunner.IsRequired = apiutils.NewBoolPointer(true) } diff --git a/internal/controller/datadogagent/feature/helmcheck/feature_test.go b/internal/controller/datadogagent/feature/helmcheck/feature_test.go index a0f39abb5..093514854 100644 --- a/internal/controller/datadogagent/feature/helmcheck/feature_test.go +++ b/internal/controller/datadogagent/feature/helmcheck/feature_test.go @@ -18,7 +18,6 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" @@ -27,6 +26,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" + "github.com/DataDog/datadog-operator/pkg/testutils" ) const resourcesName = "foo" @@ -38,14 +38,14 @@ func Test_helmCheckFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "Helm check disabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithHelmCheckEnabled(false). Build(), WantConfigure: false, }, { Name: "Helm check enabled", - DDA: v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + DDA: testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithHelmCheckEnabled(true). WithHelmCheckCollectEvents(true). WithHelmCheckValuesAsTags(valuesAsTags). @@ -56,7 +56,7 @@ func Test_helmCheckFeature_Configure(t *testing.T) { }, { Name: "Helm check enabled and runs on cluster checks runner", - DDA: v2alpha1test.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). + DDA: testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName). WithHelmCheckEnabled(true). WithHelmCheckCollectEvents(true). WithHelmCheckValuesAsTags(valuesAsTags). diff --git a/internal/controller/datadogagent/feature/kubernetesstatecore/feature.go b/internal/controller/datadogagent/feature/kubernetesstatecore/feature.go index 855be7e9e..fc39c1001 100644 --- a/internal/controller/datadogagent/feature/kubernetesstatecore/feature.go +++ b/internal/controller/datadogagent/feature/kubernetesstatecore/feature.go @@ -16,6 +16,7 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/DataDog/datadog-operator/pkg/utils" @@ -83,13 +84,13 @@ func (f *ksmFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredCompo f.collectAPIServiceMetrics = true f.collectCRDMetrics = true - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) // This check will only run in the Cluster Checks Runners or Cluster Agent (not the Node Agent) if dda.Spec.Features.ClusterChecks != nil && apiutils.BoolValue(dda.Spec.Features.ClusterChecks.Enabled) && apiutils.BoolValue(dda.Spec.Features.ClusterChecks.UseClusterChecksRunners) { f.runInClusterChecksRunner = true f.rbacSuffix = common.ChecksRunnerSuffix - f.serviceAccountName = v2alpha1.GetClusterChecksRunnerServiceAccount(dda) + f.serviceAccountName = constants.GetClusterChecksRunnerServiceAccount(dda) output.ClusterChecksRunner.IsRequired = apiutils.NewBoolPointer(true) if ccrOverride, ok := dda.Spec.Override[v2alpha1.ClusterChecksRunnerComponentName]; ok { @@ -119,7 +120,7 @@ func (f *ksmFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredCompo f.customConfigAnnotationKey = object.GetChecksumAnnotationKey(feature.KubernetesStateCoreIDType) } - f.configConfigMapName = v2alpha1.GetConfName(dda, f.customConfig, v2alpha1.DefaultKubeStateMetricsCoreConf) + f.configConfigMapName = constants.GetConfName(dda, f.customConfig, v2alpha1.DefaultKubeStateMetricsCoreConf) } return output diff --git a/internal/controller/datadogagent/feature/kubernetesstatecore/feature_test.go b/internal/controller/datadogagent/feature/kubernetesstatecore/feature_test.go index 83f9e0137..6e07188f2 100644 --- a/internal/controller/datadogagent/feature/kubernetesstatecore/feature_test.go +++ b/internal/controller/datadogagent/feature/kubernetesstatecore/feature_test.go @@ -11,13 +11,13 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" mergerfake "github.com/DataDog/datadog-operator/internal/controller/datadogagent/merger/fake" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -36,14 +36,14 @@ func Test_ksmFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "ksm-core not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithKSMEnabled(false). Build(), WantConfigure: false, }, { Name: "ksm-core not enabled with single agent container", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithKSMEnabled(false). WithSingleContainerStrategy(true). Build(), @@ -51,7 +51,7 @@ func Test_ksmFeature_Configure(t *testing.T) { }, { Name: "ksm-core enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithKSMEnabled(true). Build(), WantConfigure: true, @@ -60,7 +60,7 @@ func Test_ksmFeature_Configure(t *testing.T) { }, { Name: "ksm-core enabled with single agent container", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithKSMEnabled(true). WithSingleContainerStrategy(true). Build(), @@ -70,7 +70,7 @@ func Test_ksmFeature_Configure(t *testing.T) { }, { Name: "ksm-core enabled, custom config", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithKSMEnabled(true). WithKSMCustomConf(customData). Build(), @@ -80,7 +80,7 @@ func Test_ksmFeature_Configure(t *testing.T) { }, { Name: "ksm-core enabled, custom config with single agent container", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithKSMEnabled(true). WithKSMCustomConf(customData). WithSingleContainerStrategy(true). diff --git a/internal/controller/datadogagent/feature/livecontainer/feature_test.go b/internal/controller/datadogagent/feature/livecontainer/feature_test.go index 6eb8d89b7..5a0f8aa4c 100644 --- a/internal/controller/datadogagent/feature/livecontainer/feature_test.go +++ b/internal/controller/datadogagent/feature/livecontainer/feature_test.go @@ -10,12 +10,12 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" "github.com/DataDog/datadog-operator/api/utils" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -26,7 +26,7 @@ func TestLiveContainerFeature(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "live container collection enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveContainerCollectionEnabled(true). Build(), WantConfigure: true, @@ -34,7 +34,7 @@ func TestLiveContainerFeature(t *testing.T) { }, { Name: "live container collection enabled with single container", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveContainerCollectionEnabled(true). WithSingleContainerStrategy(true). Build(), @@ -43,7 +43,7 @@ func TestLiveContainerFeature(t *testing.T) { }, { Name: "live container collection enabled on core agent via env var", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveContainerCollectionEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -58,7 +58,7 @@ func TestLiveContainerFeature(t *testing.T) { }, { Name: "live container collection enabled on core agent via spec", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveContainerCollectionEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -73,7 +73,7 @@ func TestLiveContainerFeature(t *testing.T) { }, { Name: "live container collection enabled in core agent via spec without min version", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveContainerCollectionEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -88,7 +88,7 @@ func TestLiveContainerFeature(t *testing.T) { }, { Name: "live container collection disabled on core agent via env var override", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveContainerCollectionEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, diff --git a/internal/controller/datadogagent/feature/liveprocess/feature_test.go b/internal/controller/datadogagent/feature/liveprocess/feature_test.go index 8b7efe81b..4553c84fd 100644 --- a/internal/controller/datadogagent/feature/liveprocess/feature_test.go +++ b/internal/controller/datadogagent/feature/liveprocess/feature_test.go @@ -10,12 +10,12 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" "github.com/DataDog/datadog-operator/api/utils" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -26,14 +26,14 @@ func Test_liveProcessFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "live process collection not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveProcessEnabled(false). Build(), WantConfigure: false, }, { Name: "live process collection enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveProcessEnabled(true). Build(), WantConfigure: true, @@ -41,7 +41,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) { }, { Name: "live process collection enabled with scrub and strip args", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveProcessEnabled(true). WithLiveProcessScrubStrip(true, true). Build(), @@ -50,7 +50,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) { }, { Name: "live process collection enabled in core agent via env vars", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveProcessEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -65,7 +65,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) { }, { Name: "live process collection enabled in core agent via spec", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveProcessEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -80,7 +80,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) { }, { Name: "live process collection enabled in core agent via spec without min version", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveProcessEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -95,7 +95,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) { }, { Name: "live process collection disabled in core agent via env var override", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveProcessEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -111,7 +111,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) { }, { Name: "live process collection enabled on single container", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLiveProcessEnabled(true). WithSingleContainerStrategy(true). Build(), diff --git a/internal/controller/datadogagent/feature/logcollection/feature_test.go b/internal/controller/datadogagent/feature/logcollection/feature_test.go index ed2dd1267..76caa7024 100644 --- a/internal/controller/datadogagent/feature/logcollection/feature_test.go +++ b/internal/controller/datadogagent/feature/logcollection/feature_test.go @@ -10,11 +10,11 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -25,14 +25,14 @@ func Test_LogCollectionFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "log collection not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLogCollectionEnabled(false). BuildWithDefaults(), WantConfigure: false, }, { Name: "log collection enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLogCollectionEnabled(true). BuildWithDefaults(), WantConfigure: true, @@ -45,7 +45,7 @@ func Test_LogCollectionFeature_Configure(t *testing.T) { }, { Name: "container collect all enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLogCollectionEnabled(true). WithLogCollectionCollectAll(true). BuildWithDefaults(), @@ -59,7 +59,7 @@ func Test_LogCollectionFeature_Configure(t *testing.T) { }, { Name: "container collect using files disabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLogCollectionEnabled(true). WithLogCollectionCollectAll(true). WithLogCollectionLogCollectionUsingFiles(false). @@ -74,7 +74,7 @@ func Test_LogCollectionFeature_Configure(t *testing.T) { }, { Name: "open files limit set to custom value", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLogCollectionEnabled(true). WithLogCollectionOpenFilesLimit(250). BuildWithDefaults(), @@ -92,7 +92,7 @@ func Test_LogCollectionFeature_Configure(t *testing.T) { }, { Name: "custom volumes", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithLogCollectionEnabled(true). WithLogCollectionPaths("/custom/pod/logs", "/custom/container/logs", "/custom/symlink", "/custom/temp/storage"). BuildWithDefaults(), diff --git a/internal/controller/datadogagent/feature/orchestratorexplorer/feature.go b/internal/controller/datadogagent/feature/orchestratorexplorer/feature.go index e0fd74cbb..5eabba5ec 100644 --- a/internal/controller/datadogagent/feature/orchestratorexplorer/feature.go +++ b/internal/controller/datadogagent/feature/orchestratorexplorer/feature.go @@ -13,6 +13,7 @@ import ( "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/DataDog/datadog-operator/pkg/utils" @@ -112,19 +113,19 @@ func (f *orchestratorExplorerFeature) Configure(dda *v2alpha1.DatadogAgent) (req } f.customResources = dda.Spec.Features.OrchestratorExplorer.CustomResources - f.configConfigMapName = v2alpha1.GetConfName(dda, f.customConfig, v2alpha1.DefaultOrchestratorExplorerConf) + f.configConfigMapName = constants.GetConfName(dda, f.customConfig, v2alpha1.DefaultOrchestratorExplorerConf) f.scrubContainers = apiutils.BoolValue(orchestratorExplorer.ScrubContainers) f.extraTags = orchestratorExplorer.ExtraTags if orchestratorExplorer.DDUrl != nil { f.ddURL = *orchestratorExplorer.DDUrl } - f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda) + f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda) - if v2alpha1.IsClusterChecksEnabled(dda) { - if v2alpha1.IsCCREnabled(dda) { + if constants.IsClusterChecksEnabled(dda) { + if constants.IsCCREnabled(dda) { f.runInClusterChecksRunner = true f.rbacSuffix = common.ChecksRunnerSuffix - f.serviceAccountName = v2alpha1.GetClusterChecksRunnerServiceAccount(dda) + f.serviceAccountName = constants.GetClusterChecksRunnerServiceAccount(dda) reqComp.ClusterChecksRunner.IsRequired = apiutils.NewBoolPointer(true) } } diff --git a/internal/controller/datadogagent/feature/orchestratorexplorer/feature_test.go b/internal/controller/datadogagent/feature/orchestratorexplorer/feature_test.go index f580951a2..a822abdf4 100644 --- a/internal/controller/datadogagent/feature/orchestratorexplorer/feature_test.go +++ b/internal/controller/datadogagent/feature/orchestratorexplorer/feature_test.go @@ -11,13 +11,13 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" mergerfake "github.com/DataDog/datadog-operator/internal/controller/datadogagent/merger/fake" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -54,14 +54,14 @@ func Test_orchestratorExplorerFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "orchestrator explorer not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOrchestratorExplorerEnabled(false). Build(), WantConfigure: false, }, { Name: "orchestrator explorer enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOrchestratorExplorerEnabled(true). WithOrchestratorExplorerScrubContainers(true). WithOrchestratorExplorerExtraTags([]string{"a:z", "b:y", "c:x"}). @@ -75,7 +75,7 @@ func Test_orchestratorExplorerFeature_Configure(t *testing.T) { }, { Name: "orchestrator explorer enabled and runs on cluster checks runner", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOrchestratorExplorerEnabled(true). WithOrchestratorExplorerScrubContainers(true). WithOrchestratorExplorerExtraTags([]string{"a:z", "b:y", "c:x"}). @@ -92,7 +92,7 @@ func Test_orchestratorExplorerFeature_Configure(t *testing.T) { }, { Name: "orchestrator explorer enabled on version requiring process agent", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOrchestratorExplorerEnabled(true). WithOrchestratorExplorerScrubContainers(true). WithOrchestratorExplorerExtraTags([]string{"a:z", "b:y", "c:x"}). diff --git a/internal/controller/datadogagent/feature/otelcollector/configmap_test.go b/internal/controller/datadogagent/feature/otelcollector/configmap_test.go index 3115aadcb..2a5c46aad 100644 --- a/internal/controller/datadogagent/feature/otelcollector/configmap_test.go +++ b/internal/controller/datadogagent/feature/otelcollector/configmap_test.go @@ -20,7 +20,7 @@ func Test_buildOtelCollectorConfigMap(t *testing.T) { // check config map configMapWant := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "-otel-agent-config", + Name: "-otel-agent-config", }, Data: map[string]string{ "otel-config.yaml": defaultconfig.DefaultOtelCollectorConfig, @@ -31,7 +31,7 @@ func Test_buildOtelCollectorConfigMap(t *testing.T) { assert.True(t, ok) otelCollectorFeature.owner = &metav1.ObjectMeta{ - Name: "-otel-agent-config", + Name: "-otel-agent-config", } otelCollectorFeature.configMapName = "-otel-agent-config" otelCollectorFeature.customConfig = &v2alpha1.CustomConfig{} diff --git a/internal/controller/datadogagent/feature/otelcollector/feature.go b/internal/controller/datadogagent/feature/otelcollector/feature.go index 8c091d963..69083073d 100644 --- a/internal/controller/datadogagent/feature/otelcollector/feature.go +++ b/internal/controller/datadogagent/feature/otelcollector/feature.go @@ -11,6 +11,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otelcollector/defaultconfig" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/configmap" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/kubernetes" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -55,7 +56,7 @@ func (o *otelCollectorFeature) Configure(dda *v2alpha1.DatadogAgent) feature.Req if dda.Spec.Features.OtelCollector.Conf != nil { o.customConfig = dda.Spec.Features.OtelCollector.Conf } - o.configMapName = v2alpha1.GetConfName(dda, o.customConfig, v2alpha1.DefaultOTelAgentConf) + o.configMapName = constants.GetConfName(dda, o.customConfig, v2alpha1.DefaultOTelAgentConf) if dda.Spec.Features.OtelCollector.CoreConfig != nil { o.coreAgentConfig.enabled = dda.Spec.Features.OtelCollector.CoreConfig.Enabled diff --git a/internal/controller/datadogagent/feature/otelcollector/feature_test.go b/internal/controller/datadogagent/feature/otelcollector/feature_test.go index 93843b2e6..5f8c39d62 100644 --- a/internal/controller/datadogagent/feature/otelcollector/feature_test.go +++ b/internal/controller/datadogagent/feature/otelcollector/feature_test.go @@ -6,7 +6,6 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" @@ -14,6 +13,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" "github.com/DataDog/datadog-operator/pkg/kubernetes" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -57,14 +57,14 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { // disabled { Name: "otel agent disabled without config", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(false). Build(), WantConfigure: false, }, { Name: "otel agent disabled with config", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(false). WithOTelCollectorConfig(). Build(), @@ -73,7 +73,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { // enabled { Name: "otel agent enabled with config", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). WithOTelCollectorConfig(). Build(), @@ -83,7 +83,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { }, { Name: "otel agent enabled with configMap", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). WithOTelCollectorConfigMap(). Build(), @@ -93,7 +93,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { }, { Name: "otel agent enabled without config", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). Build(), WantConfigure: true, @@ -102,7 +102,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { }, { Name: "otel agent enabled without config non default ports", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). WithOTelCollectorPorts(4444, 5555). Build(), @@ -119,7 +119,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { // coreconfig { Name: "otel agent coreconfig enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). WithOTelCollectorCoreConfigEnabled(true). Build(), @@ -129,7 +129,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { }, { Name: "otel agent coreconfig disabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). WithOTelCollectorCoreConfigEnabled(false). Build(), @@ -139,7 +139,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { }, { Name: "otel agent coreconfig extensionTimeout", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). WithOTelCollectorCoreConfigEnabled(false). WithOTelCollectorCoreConfigExtensionTimeout(13). @@ -155,7 +155,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { }, { Name: "otel agent coreconfig extensionURL", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). WithOTelCollectorCoreConfigEnabled(false). WithOTelCollectorCoreConfigExtensionURL("https://localhost:1234"). @@ -171,7 +171,7 @@ func Test_otelCollectorFeature_Configure(t *testing.T) { }, { Name: "otel agent coreconfig all env vars", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithOTelCollectorEnabled(true). WithOTelCollectorCoreConfigEnabled(true). WithOTelCollectorCoreConfigExtensionTimeout(13). diff --git a/internal/controller/datadogagent/feature/otlp/feature.go b/internal/controller/datadogagent/feature/otlp/feature.go index 9512f0aef..266b66464 100644 --- a/internal/controller/datadogagent/feature/otlp/feature.go +++ b/internal/controller/datadogagent/feature/otlp/feature.go @@ -19,6 +19,7 @@ import ( "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/pkg/cilium/v1" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/go-logr/logr" apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" @@ -111,7 +112,7 @@ func (f *otlpFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req if dda.Spec.Global.LocalService != nil { f.forceEnableLocalService = apiutils.BoolValue(dda.Spec.Global.LocalService.ForceEnableLocalService) } - f.localServiceName = v2alpha1.GetLocalAgentServiceName(dda) + f.localServiceName = constants.GetLocalAgentServiceName(dda) if f.grpcEnabled || f.httpEnabled { reqComp = feature.RequiredComponents{ @@ -128,7 +129,7 @@ func (f *otlpFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req } } if f.grpcEnabled || f.httpEnabled { - if enabled, flavor := v2alpha1.IsNetworkPolicyEnabled(dda); enabled { + if enabled, flavor := constants.IsNetworkPolicyEnabled(dda); enabled { if flavor == v2alpha1.NetworkPolicyFlavorCilium { f.createCiliumNetworkPolicy = true } else { diff --git a/internal/controller/datadogagent/feature/otlp/feature_test.go b/internal/controller/datadogagent/feature/otlp/feature_test.go index 1a5bcc549..7ef81d9bf 100644 --- a/internal/controller/datadogagent/feature/otlp/feature_test.go +++ b/internal/controller/datadogagent/feature/otlp/feature_test.go @@ -10,11 +10,11 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -392,7 +392,7 @@ type Settings struct { } func newAgent(set Settings) *v2alpha1.DatadogAgent { - return v2alpha1test.NewDatadogAgentBuilder(). + return testutils.NewDatadogAgentBuilder(). WithOTLPGRPCSettings(set.EnabledGRPC, set.EnabledGRPCHostPort, set.CustomGRPCHostPort, set.EndpointGRPC). WithOTLPHTTPSettings(set.EnabledHTTP, set.EnabledHTTPHostPort, set.CustomHTTPHostPort, set.EndpointHTTP). WithAPMEnabled(set.APM). @@ -400,7 +400,7 @@ func newAgent(set Settings) *v2alpha1.DatadogAgent { } func newAgentSingleContainer(set Settings) *v2alpha1.DatadogAgent { - return v2alpha1test.NewDatadogAgentBuilder(). + return testutils.NewDatadogAgentBuilder(). WithOTLPGRPCSettings(set.EnabledGRPC, set.EnabledGRPCHostPort, set.CustomGRPCHostPort, set.EndpointGRPC). WithOTLPHTTPSettings(set.EnabledHTTP, set.EnabledHTTPHostPort, set.CustomHTTPHostPort, set.EndpointHTTP). WithAPMEnabled(set.APM). diff --git a/internal/controller/datadogagent/feature/processdiscovery/feature_test.go b/internal/controller/datadogagent/feature/processdiscovery/feature_test.go index 5a9bcbca7..6217bd29b 100644 --- a/internal/controller/datadogagent/feature/processdiscovery/feature_test.go +++ b/internal/controller/datadogagent/feature/processdiscovery/feature_test.go @@ -10,12 +10,12 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" "github.com/DataDog/datadog-operator/api/utils" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -26,7 +26,7 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "process discovery enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithProcessDiscoveryEnabled(true). Build(), WantConfigure: true, @@ -34,21 +34,21 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) { }, { Name: "process discovery disabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithProcessDiscoveryEnabled(false). Build(), WantConfigure: false, }, { Name: "process discovery config missing", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). Build(), WantConfigure: true, Agent: testExpectedAgent(apicommon.ProcessAgentContainerName, false), }, { Name: "process discovery enabled in core agent via env vars", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithProcessDiscoveryEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -63,7 +63,7 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) { }, { Name: "process discovery enabled in core agent via spec", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithProcessDiscoveryEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -78,7 +78,7 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) { }, { Name: "process discovery enabled in core agent via spec without min version", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithProcessDiscoveryEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -93,7 +93,7 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) { }, { Name: "process discovery disabled in core agent via env var override", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithProcessDiscoveryEnabled(true). WithComponentOverride( v2alpha1.NodeAgentComponentName, @@ -109,7 +109,7 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) { }, { Name: "process discovery enabled on single container", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithProcessDiscoveryEnabled(true). WithSingleContainerStrategy(true). Build(), diff --git a/internal/controller/datadogagent/feature/prometheusscrape/feature_test.go b/internal/controller/datadogagent/feature/prometheusscrape/feature_test.go index b7e309fc8..694ba7411 100644 --- a/internal/controller/datadogagent/feature/prometheusscrape/feature_test.go +++ b/internal/controller/datadogagent/feature/prometheusscrape/feature_test.go @@ -9,11 +9,11 @@ import ( "testing" apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -39,14 +39,14 @@ func Test_prometheusScrapeFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "Prometheus scrape not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithPrometheusScrapeEnabled(false). Build(), WantConfigure: false, }, { Name: "Prometheus scrape enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithPrometheusScrapeEnabled(true). Build(), WantConfigure: true, @@ -83,7 +83,7 @@ func Test_prometheusScrapeFeature_Configure(t *testing.T) { }, { Name: "Prometheus scrape service endpoints enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithPrometheusScrapeEnabled(true). WithPrometheusScrapeServiceEndpoints(true). Build(), @@ -121,7 +121,7 @@ func Test_prometheusScrapeFeature_Configure(t *testing.T) { }, { Name: "Prometheus scrape additional configs", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithPrometheusScrapeEnabled(true). WithPrometheusScrapeAdditionalConfigs(yamlConfigs). Build(), @@ -167,7 +167,7 @@ func Test_prometheusScrapeFeature_Configure(t *testing.T) { }, { Name: "version specified", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithPrometheusScrapeEnabled(true). WithPrometheusScrapeVersion(1). Build(), diff --git a/internal/controller/datadogagent/feature/remoteconfig/feature_test.go b/internal/controller/datadogagent/feature/remoteconfig/feature_test.go index 4b0aac129..9f199aacb 100644 --- a/internal/controller/datadogagent/feature/remoteconfig/feature_test.go +++ b/internal/controller/datadogagent/feature/remoteconfig/feature_test.go @@ -11,11 +11,11 @@ import ( corev1 "k8s.io/api/core/v1" apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -25,7 +25,7 @@ func Test_rcFeature_Configure(t *testing.T) { tests := test.FeatureTestSuite{ { Name: "RC not enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithRemoteConfigEnabled(false). Build(), WantConfigure: true, @@ -34,7 +34,7 @@ func Test_rcFeature_Configure(t *testing.T) { }, { Name: "RC enabled", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). WithRemoteConfigEnabled(true). Build(), WantConfigure: true, @@ -43,7 +43,7 @@ func Test_rcFeature_Configure(t *testing.T) { }, { Name: "RC default (no datadogagent_default.go)", - DDA: v2alpha1test.NewDatadogAgentBuilder(). + DDA: testutils.NewDatadogAgentBuilder(). Build(), WantConfigure: true, Agent: rcAgentNodeWantFunc(false), diff --git a/internal/controller/datadogagent/feature/test/factory_test.go b/internal/controller/datadogagent/feature/test/factory_test.go index 0fd469644..8d0491d17 100644 --- a/internal/controller/datadogagent/feature/test/factory_test.go +++ b/internal/controller/datadogagent/feature/test/factory_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/DataDog/datadog-operator/api/datadoghq/common" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/stretchr/testify/assert" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" @@ -30,7 +30,7 @@ func TestBuilder(t *testing.T) { // This test relies on the fact that by default Live Container feature is enabled // in the default settings which enables process agent. name: "Default DDA, Core and Process agent enabled", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ common.UnprivilegedSingleAgentContainerName: false, @@ -45,7 +45,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA with single container strategy, 1 single container", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithSingleContainerStrategy(true). BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ @@ -61,7 +61,7 @@ func TestBuilder(t *testing.T) { }, { name: "APM enabled, 3 agents", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ @@ -77,7 +77,7 @@ func TestBuilder(t *testing.T) { }, { name: "APM enabled with single container strategy, 1 single container", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithSingleContainerStrategy(true). WithAPMEnabled(true). BuildWithDefaults(), @@ -94,7 +94,7 @@ func TestBuilder(t *testing.T) { }, { name: "APM, NPM enabled, 4 agents", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithNPMEnabled(true). BuildWithDefaults(), @@ -111,7 +111,7 @@ func TestBuilder(t *testing.T) { }, { name: "APM, NPM enabled with single container strategy, 4 agents", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithSingleContainerStrategy(true). WithAPMEnabled(true). WithNPMEnabled(true). @@ -129,7 +129,7 @@ func TestBuilder(t *testing.T) { }, { name: "APM, NPM, CSPM enabled, 5 agents", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAPMEnabled(true). WithNPMEnabled(true). WithCSPMEnabled(true). @@ -147,7 +147,7 @@ func TestBuilder(t *testing.T) { }, { name: "APM, NPM, CSPM enabled with single container strategy, 5 agents", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithSingleContainerStrategy(true). WithAPMEnabled(true). WithNPMEnabled(true). @@ -166,7 +166,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA, default feature Option, otel-agent-enabled annotation true", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "true"}). BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ @@ -182,7 +182,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA, default feature Option, otel-agent-enabled annotation false", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "false"}). BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ @@ -198,7 +198,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA, no otel annotation, Operator option enabled", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "false"}). BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ @@ -214,7 +214,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA, otel annotation false, otel collector feature enabled", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "false"}). WithOTelCollectorEnabled(true). BuildWithDefaults(), @@ -231,7 +231,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA, otel annotation true, otel collector feature disabled", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "true"}). WithOTelCollectorEnabled(false). BuildWithDefaults(), @@ -248,7 +248,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA, otel annotation true, otel collector feature enabled", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/otel-agent-enabled": "true"}). WithOTelCollectorEnabled(true). BuildWithDefaults(), @@ -265,7 +265,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA, default feature Option, adp-enabled annotation true", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/adp-enabled": "true"}). BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ @@ -281,7 +281,7 @@ func TestBuilder(t *testing.T) { }, { name: "Default DDA, default feature Option, adp-enabled annotation false", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithAnnotations(map[string]string{"agent.datadoghq.com/adp-enabled": "false"}). BuildWithDefaults(), wantAgentContainer: map[common.AgentContainerName]bool{ diff --git a/internal/controller/datadogagent/finalizer.go b/internal/controller/datadogagent/finalizer.go index 4b5e39370..68ed87682 100644 --- a/internal/controller/datadogagent/finalizer.go +++ b/internal/controller/datadogagent/finalizer.go @@ -10,6 +10,7 @@ import ( "fmt" datadoghqv2alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/defaults" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/override" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" @@ -68,7 +69,7 @@ func (r *Reconciler) finalizeDadV2(reqLogger logr.Logger, obj client.Object) err // We need to apply the defaults to be able to delete the resources // associated with those defaults. dda := obj.(*datadoghqv2alpha1.DatadogAgent).DeepCopy() - datadoghqv2alpha1.DefaultDatadogAgent(dda) + defaults.DefaultDatadogAgent(dda) if r.options.OperatorMetricsEnabled { r.forwarders.Unregister(dda) diff --git a/internal/controller/datadogagent/override/container.go b/internal/controller/datadogagent/override/container.go index 8a7d91e55..93b35ad7d 100644 --- a/internal/controller/datadogagent/override/container.go +++ b/internal/controller/datadogagent/override/container.go @@ -12,6 +12,7 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" + "github.com/DataDog/datadog-operator/pkg/constants" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -227,8 +228,8 @@ func overrideReadinessProbe(readinessProbeOverride *corev1.Probe) *corev1.Probe // Add default httpGet probeHandler if probeHandler is not configured in readinessProbe override if !hasProbeHandler(readinessProbeOverride) { readinessProbeOverride.HTTPGet = &corev1.HTTPGetAction{ - Path: v2alpha1.DefaultReadinessProbeHTTPPath, - Port: intstr.IntOrString{IntVal: v2alpha1.DefaultAgentHealthPort}} + Path: constants.DefaultReadinessProbeHTTPPath, + Port: intstr.IntOrString{IntVal: constants.DefaultAgentHealthPort}} } return readinessProbeOverride } @@ -237,8 +238,8 @@ func overrideLivenessProbe(livenessProbeOverride *corev1.Probe) *corev1.Probe { // Add default httpGet probeHandler if probeHandler is not configured in livenessProbe override if !hasProbeHandler(livenessProbeOverride) { livenessProbeOverride.HTTPGet = &corev1.HTTPGetAction{ - Path: v2alpha1.DefaultLivenessProbeHTTPPath, - Port: intstr.IntOrString{IntVal: v2alpha1.DefaultAgentHealthPort}} + Path: constants.DefaultLivenessProbeHTTPPath, + Port: intstr.IntOrString{IntVal: constants.DefaultAgentHealthPort}} } return livenessProbeOverride } @@ -247,8 +248,8 @@ func overrideStartupProbe(startupProbeOverride *corev1.Probe) *corev1.Probe { // Add default httpGet probeHandler if probeHandler is not configured in startupProbe override if !hasProbeHandler(startupProbeOverride) { startupProbeOverride.HTTPGet = &corev1.HTTPGetAction{ - Path: v2alpha1.DefaultStartupProbeHTTPPath, - Port: intstr.IntOrString{IntVal: v2alpha1.DefaultAgentHealthPort}} + Path: constants.DefaultStartupProbeHTTPPath, + Port: intstr.IntOrString{IntVal: constants.DefaultAgentHealthPort}} } return startupProbeOverride } diff --git a/internal/controller/datadogagent/override/fips.go b/internal/controller/datadogagent/override/fips.go index 1c56f3126..62fa6a2bc 100644 --- a/internal/controller/datadogagent/override/fips.go +++ b/internal/controller/datadogagent/override/fips.go @@ -16,6 +16,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/configmap" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/kubernetes" @@ -54,7 +55,7 @@ func applyFIPSConfig(logger logr.Logger, manager feature.PodTemplateManagers, dd // Configure FIPS container fipsContainer := getFIPSProxyContainer(fipsConfig) - image := v2alpha1.GetImage(fipsConfig.Image, globalConfig.Registry) + image := constants.GetImage(fipsConfig.Image, globalConfig.Registry) fipsContainer.Image = image if fipsConfig.Image.PullPolicy != nil { fipsContainer.ImagePullPolicy = *fipsConfig.Image.PullPolicy diff --git a/internal/controller/datadogagent/override/fips_test.go b/internal/controller/datadogagent/override/fips_test.go index b43482b7b..80f3059a5 100644 --- a/internal/controller/datadogagent/override/fips_test.go +++ b/internal/controller/datadogagent/override/fips_test.go @@ -12,12 +12,12 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/store" "github.com/DataDog/datadog-operator/pkg/kubernetes" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -72,7 +72,7 @@ defaults }{ { name: "FIPS enabled", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithFIPS(v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(true), }). @@ -101,7 +101,7 @@ defaults }, { name: "FIPS custom image", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithFIPS(v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(true), Image: &v2alpha1.AgentImageConfig{ @@ -135,7 +135,7 @@ defaults }, { name: "FIPS custom port", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithFIPS(v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(true), Port: apiutils.NewInt32Pointer(2), @@ -165,7 +165,7 @@ defaults }, { name: "FIPS custom config - config map", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithFIPS(v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(true), CustomFIPSConfig: &v2alpha1.CustomConfig{ @@ -206,7 +206,7 @@ defaults }, { name: "FIPS custom config - config data", - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithFIPS(v2alpha1.FIPSConfig{ Enabled: apiutils.NewBoolPointer(true), CustomFIPSConfig: &v2alpha1.CustomConfig{ diff --git a/internal/controller/datadogagent/override/global.go b/internal/controller/datadogagent/override/global.go index e74007f49..3a1f43734 100644 --- a/internal/controller/datadogagent/override/global.go +++ b/internal/controller/datadogagent/override/global.go @@ -18,6 +18,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/objects" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/defaulting" "github.com/DataDog/datadog-operator/pkg/kubernetes/rbac" rbacv1 "k8s.io/api/rbac/v1" @@ -115,7 +116,7 @@ func applyGlobalSettings(logger logr.Logger, manager feature.PodTemplateManagers dda, *config.Site, ddURL, - v2alpha1.IsHostNetworkEnabled(dda, v2alpha1.ClusterAgentComponentName), + constants.IsHostNetworkEnabled(dda, v2alpha1.ClusterAgentComponentName), dnsSelectorEndpoints, componentName, ), @@ -356,11 +357,11 @@ func applyGlobalSettings(logger logr.Logger, manager feature.PodTemplateManagers var componentSaName string switch componentName { case v2alpha1.ClusterAgentComponentName: - componentSaName = v2alpha1.GetClusterAgentServiceAccount(dda) + componentSaName = constants.GetClusterAgentServiceAccount(dda) case v2alpha1.NodeAgentComponentName: - componentSaName = v2alpha1.GetAgentServiceAccount(dda) + componentSaName = constants.GetAgentServiceAccount(dda) case v2alpha1.ClusterChecksRunnerComponentName: - componentSaName = v2alpha1.GetClusterChecksRunnerServiceAccount(dda) + componentSaName = constants.GetClusterChecksRunnerServiceAccount(dda) } agentName := dda.GetName() diff --git a/internal/controller/datadogagent/override/global_test.go b/internal/controller/datadogagent/override/global_test.go index 0808b2be5..7137e91fa 100644 --- a/internal/controller/datadogagent/override/global_test.go +++ b/internal/controller/datadogagent/override/global_test.go @@ -9,12 +9,13 @@ import ( "fmt" "testing" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/DataDog/datadog-operator/pkg/kubernetes/rbac" + "github.com/DataDog/datadog-operator/pkg/testutils" apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -67,7 +68,7 @@ func TestNodeAgentComponenGlobalSettings(t *testing.T) { { name: "Kubelet volume configured", singleContainerStrategyEnabled: false, - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithGlobalKubeletConfig(hostCAPath, agentCAPath, true). WithGlobalDockerSocketPath(dockerSocketPath). BuildWithDefaults(), @@ -92,7 +93,7 @@ func TestNodeAgentComponenGlobalSettings(t *testing.T) { { name: "Kubelet volume configured", singleContainerStrategyEnabled: true, - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithGlobalKubeletConfig(hostCAPath, agentCAPath, true). WithGlobalDockerSocketPath(dockerSocketPath). BuildWithDefaults(), @@ -117,7 +118,7 @@ func TestNodeAgentComponenGlobalSettings(t *testing.T) { { name: "Checks tag cardinality set to orchestrator", singleContainerStrategyEnabled: false, - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithChecksTagCardinality("orchestrator"). BuildWithDefaults(), wantEnvVars: getExpectedEnvVars(&corev1.EnvVar{ @@ -131,7 +132,7 @@ func TestNodeAgentComponenGlobalSettings(t *testing.T) { { name: "Unified origin detection activated", singleContainerStrategyEnabled: false, - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithOriginDetectionUnified(true). BuildWithDefaults(), wantEnvVars: getExpectedEnvVars(&corev1.EnvVar{ @@ -145,7 +146,7 @@ func TestNodeAgentComponenGlobalSettings(t *testing.T) { { name: "Global environment variable configured", singleContainerStrategyEnabled: false, - dda: v2alpha1test.NewDatadogAgentBuilder(). + dda: testutils.NewDatadogAgentBuilder(). WithEnvVars([]corev1.EnvVar{ { Name: "envA", @@ -177,7 +178,7 @@ func TestNodeAgentComponenGlobalSettings(t *testing.T) { dda: addNameNamespaceToDDA( ddaName, ddaNamespace, - v2alpha1test.NewDatadogAgentBuilder(). + testutils.NewDatadogAgentBuilder(). WithGlobalSecretBackendGlobalPerms(secretBackendCommand, secretBackendArgs, secretBackendTimeout). BuildWithDefaults(), ), @@ -206,7 +207,7 @@ func TestNodeAgentComponenGlobalSettings(t *testing.T) { dda: addNameNamespaceToDDA( ddaName, ddaNamespace, - v2alpha1test.NewDatadogAgentBuilder(). + testutils.NewDatadogAgentBuilder(). WithGlobalSecretBackendSpecificRoles(secretBackendCommand, secretBackendArgs, secretBackendTimeout, secretNamespace, secretNames). BuildWithDefaults(), ), @@ -369,7 +370,7 @@ func assertSecretBackendGlobalPerms(t testing.TB, resourcesManager feature.Resou expectedSubject := []rbacv1.Subject{ { Kind: "ServiceAccount", - Name: ddaName + "-" + v2alpha1.DefaultAgentResourceSuffix, + Name: ddaName + "-" + constants.DefaultAgentResourceSuffix, Namespace: ddaNamespace, }, } @@ -428,7 +429,7 @@ func assertSecretBackendSpecificPerms(t testing.TB, resourcesManager feature.Res expectedSubject := []rbacv1.Subject{ { Kind: "ServiceAccount", - Name: ddaName + "-" + v2alpha1.DefaultAgentResourceSuffix, + Name: ddaName + "-" + constants.DefaultAgentResourceSuffix, Namespace: ddaNamespace, }, } diff --git a/internal/controller/datadogagent/override/podtemplatespec.go b/internal/controller/datadogagent/override/podtemplatespec.go index 04aad9eb0..15bc929b6 100644 --- a/internal/controller/datadogagent/override/podtemplatespec.go +++ b/internal/controller/datadogagent/override/podtemplatespec.go @@ -18,6 +18,7 @@ import ( "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume" + "github.com/DataDog/datadog-operator/pkg/constants" "github.com/DataDog/datadog-operator/pkg/controller/utils/comparison" "github.com/DataDog/datadog-operator/pkg/defaulting" ) @@ -245,7 +246,7 @@ func overrideImage(currentImg string, overrideImg *v2alpha1.AgentImageConfig) st overrideImgCopy.Tag = strings.TrimSuffix(splitName[1], defaulting.JMXTagSuffix) } - return v2alpha1.GetImage(&overrideImgCopy, ®istry) + return constants.GetImage(&overrideImgCopy, ®istry) } func mergeAffinities(affinity1 *v1.Affinity, affinity2 *v1.Affinity) *v1.Affinity { diff --git a/internal/controller/testutils/agent.go b/internal/controller/testutils/agent.go index 2b10da6c1..89244d725 100644 --- a/internal/controller/testutils/agent.go +++ b/internal/controller/testutils/agent.go @@ -25,6 +25,7 @@ import ( apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/pkg/constants" ) // NewDatadogAgentWithoutFeatures returns an agent without any features enabled @@ -474,9 +475,9 @@ func NewDatadogAgentWithOverrides(namespace string, name string) v2alpha1.Datado ReadinessProbe: &v1.Probe{ ProbeHandler: v1.ProbeHandler{ HTTPGet: &v1.HTTPGetAction{ - Path: v2alpha1.DefaultLivenessProbeHTTPPath, + Path: constants.DefaultLivenessProbeHTTPPath, Port: intstr.IntOrString{ - IntVal: v2alpha1.DefaultAgentHealthPort, + IntVal: constants.DefaultAgentHealthPort, }, }, }, @@ -489,9 +490,9 @@ func NewDatadogAgentWithOverrides(namespace string, name string) v2alpha1.Datado LivenessProbe: &v1.Probe{ ProbeHandler: v1.ProbeHandler{ HTTPGet: &v1.HTTPGetAction{ - Path: v2alpha1.DefaultLivenessProbeHTTPPath, + Path: constants.DefaultLivenessProbeHTTPPath, Port: intstr.IntOrString{ - IntVal: v2alpha1.DefaultAgentHealthPort, + IntVal: constants.DefaultAgentHealthPort, }, }, }, @@ -504,9 +505,9 @@ func NewDatadogAgentWithOverrides(namespace string, name string) v2alpha1.Datado StartupProbe: &v1.Probe{ ProbeHandler: v1.ProbeHandler{ HTTPGet: &v1.HTTPGetAction{ - Path: v2alpha1.DefaultLivenessProbeHTTPPath, + Path: constants.DefaultLivenessProbeHTTPPath, Port: intstr.IntOrString{ - IntVal: v2alpha1.DefaultAgentHealthPort, + IntVal: constants.DefaultAgentHealthPort, }, }, }, diff --git a/pkg/config/config.go b/pkg/config/config.go index 8e9698764..032b20398 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -24,6 +24,7 @@ import ( "github.com/DataDog/datadog-operator/api/datadoghq/common" datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1" datadoghqv2alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" + "github.com/DataDog/datadog-operator/pkg/constants" ) // These constants are only used within pkg/config @@ -105,7 +106,7 @@ func CacheOptions(logger logr.Logger, opts WatchOptions) cache.Options { Namespaces: agentNamespaces, Label: labels.SelectorFromSet(map[string]string{ - common.AgentDeploymentComponentLabelKey: datadoghqv2alpha1.DefaultAgentResourceSuffix, + common.AgentDeploymentComponentLabelKey: constants.DefaultAgentResourceSuffix, }), Transform: func(obj interface{}) (interface{}, error) { diff --git a/pkg/constants/const.go b/pkg/constants/const.go new file mode 100644 index 000000000..2ab78928f --- /dev/null +++ b/pkg/constants/const.go @@ -0,0 +1,62 @@ +// 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 2024-present Datadog, Inc. + +package constants + +const ( + // Liveness probe default config + DefaultLivenessProbeInitialDelaySeconds int32 = 15 + DefaultLivenessProbePeriodSeconds int32 = 15 + DefaultLivenessProbeTimeoutSeconds int32 = 5 + DefaultLivenessProbeSuccessThreshold int32 = 1 + DefaultLivenessProbeFailureThreshold int32 = 6 + DefaultLivenessProbeHTTPPath = "/live" + + // Readiness probe default config + DefaultReadinessProbeInitialDelaySeconds int32 = 15 + DefaultReadinessProbePeriodSeconds int32 = 15 + DefaultReadinessProbeTimeoutSeconds int32 = 5 + DefaultReadinessProbeSuccessThreshold int32 = 1 + DefaultReadinessProbeFailureThreshold int32 = 6 + DefaultReadinessProbeHTTPPath = "/ready" + + // Startup probe default config + DefaultStartupProbeInitialDelaySeconds int32 = 15 + DefaultStartupProbePeriodSeconds int32 = 15 + DefaultStartupProbeTimeoutSeconds int32 = 5 + DefaultStartupProbeSuccessThreshold int32 = 1 + DefaultStartupProbeFailureThreshold int32 = 6 + DefaultStartupProbeHTTPPath = "/startup" + + // Agent Data plane default liveness/readiness probe configs + DefaultADPLivenessProbeInitialDelaySeconds int32 = 5 + DefaultADPLivenessProbePeriodSeconds int32 = 5 + DefaultADPLivenessProbeTimeoutSeconds int32 = 5 + DefaultADPLivenessProbeSuccessThreshold int32 = 1 + DefaultADPLivenessProbeFailureThreshold int32 = 12 + + DefaultADPReadinessProbeInitialDelaySeconds int32 = 5 + DefaultADPReadinessProbePeriodSeconds int32 = 5 + DefaultADPReadinessProbeTimeoutSeconds int32 = 5 + DefaultADPReadinessProbeSuccessThreshold int32 = 1 + DefaultADPReadinessProbeFailureThreshold int32 = 12 + + // DefaultAgentHealthPort default agent health port + DefaultAgentHealthPort int32 = 5555 + + DefaultADPHealthPort = 5100 + + // DefaultApmPort default apm port + DefaultApmPort = 8126 + // DefaultApmPortName default apm port name + DefaultApmPortName = "traceport" + + // DefaultAgentResourceSuffix use as suffix for agent resource naming + DefaultAgentResourceSuffix = "agent" + // DefaultClusterAgentResourceSuffix use as suffix for cluster-agent resource naming + DefaultClusterAgentResourceSuffix = "cluster-agent" + // DefaultClusterChecksRunnerResourceSuffix use as suffix for cluster-checks-runner resource naming + DefaultClusterChecksRunnerResourceSuffix = "cluster-checks-runner" +) diff --git a/api/datadoghq/v2alpha1/utils.go b/pkg/constants/utils.go similarity index 73% rename from api/datadoghq/v2alpha1/utils.go rename to pkg/constants/utils.go index ba3b10685..483f62349 100644 --- a/api/datadoghq/v2alpha1/utils.go +++ b/pkg/constants/utils.go @@ -3,13 +3,14 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -package v2alpha1 +package constants import ( "fmt" "github.com/DataDog/datadog-operator/pkg/defaulting" + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -17,7 +18,7 @@ import ( ) // GetConfName get the name of the Configmap for a CustomConfigSpec -func GetConfName(owner metav1.Object, conf *CustomConfig, defaultName string) string { +func GetConfName(owner metav1.Object, conf *v2alpha1.CustomConfig, defaultName string) string { // `configData` and `configMap` can't be set together. // Return the default if the conf is not overridden or if it is just overridden with the ConfigData. if conf != nil && conf.ConfigMap != nil { @@ -27,61 +28,61 @@ func GetConfName(owner metav1.Object, conf *CustomConfig, defaultName string) st } // GetClusterAgentServiceAccount return the cluster-agent serviceAccountName -func GetClusterAgentServiceAccount(dda *DatadogAgent) string { +func GetClusterAgentServiceAccount(dda *v2alpha1.DatadogAgent) string { saDefault := fmt.Sprintf("%s-%s", dda.Name, DefaultClusterAgentResourceSuffix) - if dda.Spec.Override[ClusterAgentComponentName] != nil && dda.Spec.Override[ClusterAgentComponentName].ServiceAccountName != nil { - return *dda.Spec.Override[ClusterAgentComponentName].ServiceAccountName + if dda.Spec.Override[v2alpha1.ClusterAgentComponentName] != nil && dda.Spec.Override[v2alpha1.ClusterAgentComponentName].ServiceAccountName != nil { + return *dda.Spec.Override[v2alpha1.ClusterAgentComponentName].ServiceAccountName } return saDefault } // GetAgentServiceAccount returns the agent service account name -func GetAgentServiceAccount(dda *DatadogAgent) string { +func GetAgentServiceAccount(dda *v2alpha1.DatadogAgent) string { saDefault := fmt.Sprintf("%s-%s", dda.Name, DefaultAgentResourceSuffix) - if dda.Spec.Override[NodeAgentComponentName] != nil && dda.Spec.Override[NodeAgentComponentName].ServiceAccountName != nil { - return *dda.Spec.Override[NodeAgentComponentName].ServiceAccountName + if dda.Spec.Override[v2alpha1.NodeAgentComponentName] != nil && dda.Spec.Override[v2alpha1.NodeAgentComponentName].ServiceAccountName != nil { + return *dda.Spec.Override[v2alpha1.NodeAgentComponentName].ServiceAccountName } return saDefault } // GetClusterChecksRunnerServiceAccount return the cluster-checks-runner service account name -func GetClusterChecksRunnerServiceAccount(dda *DatadogAgent) string { +func GetClusterChecksRunnerServiceAccount(dda *v2alpha1.DatadogAgent) string { saDefault := fmt.Sprintf("%s-%s", dda.Name, DefaultClusterChecksRunnerResourceSuffix) - if dda.Spec.Override[ClusterChecksRunnerComponentName] != nil && dda.Spec.Override[ClusterChecksRunnerComponentName].ServiceAccountName != nil { - return *dda.Spec.Override[ClusterChecksRunnerComponentName].ServiceAccountName + if dda.Spec.Override[v2alpha1.ClusterChecksRunnerComponentName] != nil && dda.Spec.Override[v2alpha1.ClusterChecksRunnerComponentName].ServiceAccountName != nil { + return *dda.Spec.Override[v2alpha1.ClusterChecksRunnerComponentName].ServiceAccountName } return saDefault } // GetClusterAgentServiceAccountAnnotations returns the annotations for the cluster-agent service account. -func GetClusterAgentServiceAccountAnnotations(dda *DatadogAgent) map[string]string { +func GetClusterAgentServiceAccountAnnotations(dda *v2alpha1.DatadogAgent) map[string]string { defaultAnnotations := map[string]string{} - if dda.Spec.Override[ClusterAgentComponentName] != nil && dda.Spec.Override[ClusterAgentComponentName].ServiceAccountAnnotations != nil { - return dda.Spec.Override[ClusterAgentComponentName].ServiceAccountAnnotations + if dda.Spec.Override[v2alpha1.ClusterAgentComponentName] != nil && dda.Spec.Override[v2alpha1.ClusterAgentComponentName].ServiceAccountAnnotations != nil { + return dda.Spec.Override[v2alpha1.ClusterAgentComponentName].ServiceAccountAnnotations } return defaultAnnotations } // GetAgentServiceAccountAnnotations returns the annotations for the agent service account. -func GetAgentServiceAccountAnnotations(dda *DatadogAgent) map[string]string { +func GetAgentServiceAccountAnnotations(dda *v2alpha1.DatadogAgent) map[string]string { defaultAnnotations := map[string]string{} - if dda.Spec.Override[NodeAgentComponentName] != nil && dda.Spec.Override[NodeAgentComponentName].ServiceAccountAnnotations != nil { - return dda.Spec.Override[NodeAgentComponentName].ServiceAccountAnnotations + if dda.Spec.Override[v2alpha1.NodeAgentComponentName] != nil && dda.Spec.Override[v2alpha1.NodeAgentComponentName].ServiceAccountAnnotations != nil { + return dda.Spec.Override[v2alpha1.NodeAgentComponentName].ServiceAccountAnnotations } return defaultAnnotations } // GetClusterChecksRunnerServiceAccountAnnotations returns the annotations for the cluster-checks-runner service account. -func GetClusterChecksRunnerServiceAccountAnnotations(dda *DatadogAgent) map[string]string { +func GetClusterChecksRunnerServiceAccountAnnotations(dda *v2alpha1.DatadogAgent) map[string]string { defaultAnnotations := map[string]string{} - if dda.Spec.Override[ClusterChecksRunnerComponentName] != nil && dda.Spec.Override[ClusterChecksRunnerComponentName].ServiceAccountAnnotations != nil { - return dda.Spec.Override[ClusterChecksRunnerComponentName].ServiceAccountAnnotations + if dda.Spec.Override[v2alpha1.ClusterChecksRunnerComponentName] != nil && dda.Spec.Override[v2alpha1.ClusterChecksRunnerComponentName].ServiceAccountAnnotations != nil { + return dda.Spec.Override[v2alpha1.ClusterChecksRunnerComponentName].ServiceAccountAnnotations } return defaultAnnotations } // IsHostNetworkEnabled returns whether the pod should use the host's network namespace -func IsHostNetworkEnabled(dda *DatadogAgent, component ComponentName) bool { +func IsHostNetworkEnabled(dda *v2alpha1.DatadogAgent, component v2alpha1.ComponentName) bool { if dda.Spec.Override != nil { if c, ok := dda.Spec.Override[component]; ok { return apiutils.BoolValue(c.HostNetwork) @@ -91,17 +92,17 @@ func IsHostNetworkEnabled(dda *DatadogAgent, component ComponentName) bool { } // IsClusterChecksEnabled returns whether the DDA should use cluster checks -func IsClusterChecksEnabled(dda *DatadogAgent) bool { +func IsClusterChecksEnabled(dda *v2alpha1.DatadogAgent) bool { return dda.Spec.Features.ClusterChecks != nil && apiutils.BoolValue(dda.Spec.Features.ClusterChecks.Enabled) } // IsCCREnabled returns whether the DDA should use Cluster Checks Runners -func IsCCREnabled(dda *DatadogAgent) bool { +func IsCCREnabled(dda *v2alpha1.DatadogAgent) bool { return dda.Spec.Features.ClusterChecks != nil && apiutils.BoolValue(dda.Spec.Features.ClusterChecks.UseClusterChecksRunners) } // GetLocalAgentServiceName returns the name used for the local agent service -func GetLocalAgentServiceName(dda *DatadogAgent) string { +func GetLocalAgentServiceName(dda *v2alpha1.DatadogAgent) string { if dda.Spec.Global.LocalService != nil && dda.Spec.Global.LocalService.NameOverride != nil { return *dda.Spec.Global.LocalService.NameOverride } @@ -109,12 +110,12 @@ func GetLocalAgentServiceName(dda *DatadogAgent) string { } // IsNetworkPolicyEnabled returns whether a network policy should be created and which flavor to use -func IsNetworkPolicyEnabled(dda *DatadogAgent) (bool, NetworkPolicyFlavor) { +func IsNetworkPolicyEnabled(dda *v2alpha1.DatadogAgent) (bool, v2alpha1.NetworkPolicyFlavor) { if dda.Spec.Global != nil && dda.Spec.Global.NetworkPolicy != nil && apiutils.BoolValue(dda.Spec.Global.NetworkPolicy.Create) { if dda.Spec.Global.NetworkPolicy.Flavor != "" { return true, dda.Spec.Global.NetworkPolicy.Flavor } - return true, NetworkPolicyFlavorKubernetes + return true, v2alpha1.NetworkPolicyFlavorKubernetes } return false, "" } @@ -225,7 +226,7 @@ func GetDefaultAgentDataPlaneReadinessProbe() *corev1.Probe { } // GetImage builds the image string based on ImageConfig and the registry configuration. -func GetImage(imageSpec *AgentImageConfig, registry *string) string { +func GetImage(imageSpec *v2alpha1.AgentImageConfig, registry *string) string { if defaulting.IsImageNameContainsTag(imageSpec.Name) { return imageSpec.Name } diff --git a/api/datadoghq/v2alpha1/utils_test.go b/pkg/constants/utils_test.go similarity index 69% rename from api/datadoghq/v2alpha1/utils_test.go rename to pkg/constants/utils_test.go index bcef5620b..33263d21f 100644 --- a/api/datadoghq/v2alpha1/utils_test.go +++ b/pkg/constants/utils_test.go @@ -1,9 +1,8 @@ // 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 v2alpha1 +// Copyright 2024-present Datadog, Inc. +package constants import ( "fmt" @@ -11,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" + "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/pkg/defaulting" @@ -21,13 +21,13 @@ func Test_GetImage(t *testing.T) { emptyRegistry := "" tests := []struct { name string - imageSpec *AgentImageConfig + imageSpec *v2alpha1.AgentImageConfig registry *string want string }{ { name: "backward compatible", - imageSpec: &AgentImageConfig{ + imageSpec: &v2alpha1.AgentImageConfig{ Name: defaulting.GetLatestAgentImage(), }, registry: nil, @@ -35,7 +35,7 @@ func Test_GetImage(t *testing.T) { }, { name: "nominal case", - imageSpec: &AgentImageConfig{ + imageSpec: &v2alpha1.AgentImageConfig{ Name: "agent", Tag: "7", }, @@ -44,7 +44,7 @@ func Test_GetImage(t *testing.T) { }, { name: "prioritize the full path", - imageSpec: &AgentImageConfig{ + imageSpec: &v2alpha1.AgentImageConfig{ Name: "docker.io/datadog/agent:7.28.1-rc.3", Tag: "latest", }, @@ -53,7 +53,7 @@ func Test_GetImage(t *testing.T) { }, { name: "default registry", - imageSpec: &AgentImageConfig{ + imageSpec: &v2alpha1.AgentImageConfig{ Name: "agent", Tag: "latest", }, @@ -62,7 +62,7 @@ func Test_GetImage(t *testing.T) { }, { name: "add jmx", - imageSpec: &AgentImageConfig{ + imageSpec: &v2alpha1.AgentImageConfig{ Name: "agent", Tag: defaulting.AgentLatestVersion, JMXEnabled: true, @@ -72,7 +72,7 @@ func Test_GetImage(t *testing.T) { }, { name: "cluster-agent", - imageSpec: &AgentImageConfig{ + imageSpec: &v2alpha1.AgentImageConfig{ Name: "cluster-agent", Tag: defaulting.ClusterAgentLatestVersion, JMXEnabled: false, @@ -82,7 +82,7 @@ func Test_GetImage(t *testing.T) { }, { name: "do not duplicate jmx", - imageSpec: &AgentImageConfig{ + imageSpec: &v2alpha1.AgentImageConfig{ Name: "agent", Tag: "latest-jmx", JMXEnabled: true, @@ -92,7 +92,7 @@ func Test_GetImage(t *testing.T) { }, { name: "do not add jmx", - imageSpec: &AgentImageConfig{ + imageSpec: &v2alpha1.AgentImageConfig{ Name: "agent", Tag: "latest-jmx", JMXEnabled: true, @@ -113,39 +113,39 @@ func TestServiceAccountNameOverride(t *testing.T) { ddaName := "test-dda" tests := []struct { name string - dda *DatadogAgent - want map[ComponentName]string + dda *v2alpha1.DatadogAgent + want map[v2alpha1.ComponentName]string }{ { name: "custom serviceaccount for dca and clc", - dda: &DatadogAgent{ + dda: &v2alpha1.DatadogAgent{ ObjectMeta: v1.ObjectMeta{ Name: ddaName, }, - Spec: DatadogAgentSpec{ - Override: map[ComponentName]*DatadogAgentComponentOverride{ - ClusterAgentComponentName: { + Spec: v2alpha1.DatadogAgentSpec{ + Override: map[v2alpha1.ComponentName]*v2alpha1.DatadogAgentComponentOverride{ + v2alpha1.ClusterAgentComponentName: { ServiceAccountName: &customServiceAccount, }, - ClusterChecksRunnerComponentName: { + v2alpha1.ClusterChecksRunnerComponentName: { ServiceAccountName: &customServiceAccount, }, }, }, }, - want: map[ComponentName]string{ - ClusterAgentComponentName: customServiceAccount, - NodeAgentComponentName: fmt.Sprintf("%s-%s", ddaName, DefaultAgentResourceSuffix), - ClusterChecksRunnerComponentName: customServiceAccount, + want: map[v2alpha1.ComponentName]string{ + v2alpha1.ClusterAgentComponentName: customServiceAccount, + v2alpha1.NodeAgentComponentName: fmt.Sprintf("%s-%s", ddaName, DefaultAgentResourceSuffix), + v2alpha1.ClusterChecksRunnerComponentName: customServiceAccount, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - res := map[ComponentName]string{} - res[NodeAgentComponentName] = GetAgentServiceAccount(tt.dda) - res[ClusterChecksRunnerComponentName] = GetClusterChecksRunnerServiceAccount(tt.dda) - res[ClusterAgentComponentName] = GetClusterAgentServiceAccount(tt.dda) + res := map[v2alpha1.ComponentName]string{} + res[v2alpha1.NodeAgentComponentName] = GetAgentServiceAccount(tt.dda) + res[v2alpha1.ClusterChecksRunnerComponentName] = GetClusterChecksRunnerServiceAccount(tt.dda) + res[v2alpha1.ClusterAgentComponentName] = GetClusterAgentServiceAccount(tt.dda) for name, sa := range tt.want { if res[name] != sa { t.Errorf("Service Account Override error = %v, want %v", res[name], tt.want[name]) @@ -164,40 +164,40 @@ func TestServiceAccountAnnotationOverride(t *testing.T) { ddaName := "test-dda" tests := []struct { name string - dda *DatadogAgent - want map[ComponentName]map[string]interface{} + dda *v2alpha1.DatadogAgent + want map[v2alpha1.ComponentName]map[string]interface{} }{ { name: "custom serviceaccount annotations for dda, dca and clc", - dda: &DatadogAgent{ + dda: &v2alpha1.DatadogAgent{ ObjectMeta: v1.ObjectMeta{ Name: ddaName, }, - Spec: DatadogAgentSpec{ - Override: map[ComponentName]*DatadogAgentComponentOverride{ - ClusterAgentComponentName: { + Spec: v2alpha1.DatadogAgentSpec{ + Override: map[v2alpha1.ComponentName]*v2alpha1.DatadogAgentComponentOverride{ + v2alpha1.ClusterAgentComponentName: { ServiceAccountName: &customServiceAccount, ServiceAccountAnnotations: customServiceAccountAnnotations, }, - ClusterChecksRunnerComponentName: { + v2alpha1.ClusterChecksRunnerComponentName: { ServiceAccountAnnotations: customServiceAccountAnnotations, }, - NodeAgentComponentName: { + v2alpha1.NodeAgentComponentName: { ServiceAccountAnnotations: customServiceAccountAnnotations, }, }, }, }, - want: map[ComponentName]map[string]interface{}{ - ClusterAgentComponentName: { + want: map[v2alpha1.ComponentName]map[string]interface{}{ + v2alpha1.ClusterAgentComponentName: { "name": customServiceAccount, "annotations": customServiceAccountAnnotations, }, - NodeAgentComponentName: { + v2alpha1.NodeAgentComponentName: { "name": fmt.Sprintf("%s-%s", ddaName, DefaultAgentResourceSuffix), "annotations": customServiceAccountAnnotations, }, - ClusterChecksRunnerComponentName: { + v2alpha1.ClusterChecksRunnerComponentName: { "name": fmt.Sprintf("%s-%s", ddaName, DefaultClusterChecksRunnerResourceSuffix), "annotations": customServiceAccountAnnotations, }, @@ -205,29 +205,29 @@ func TestServiceAccountAnnotationOverride(t *testing.T) { }, { name: "custom serviceaccount annotations for dca", - dda: &DatadogAgent{ + dda: &v2alpha1.DatadogAgent{ ObjectMeta: v1.ObjectMeta{ Name: ddaName, }, - Spec: DatadogAgentSpec{ - Override: map[ComponentName]*DatadogAgentComponentOverride{ - ClusterAgentComponentName: { + Spec: v2alpha1.DatadogAgentSpec{ + Override: map[v2alpha1.ComponentName]*v2alpha1.DatadogAgentComponentOverride{ + v2alpha1.ClusterAgentComponentName: { ServiceAccountName: &customServiceAccount, ServiceAccountAnnotations: customServiceAccountAnnotations, }, }, }, }, - want: map[ComponentName]map[string]interface{}{ - NodeAgentComponentName: { + want: map[v2alpha1.ComponentName]map[string]interface{}{ + v2alpha1.NodeAgentComponentName: { "name": fmt.Sprintf("%s-%s", ddaName, DefaultAgentResourceSuffix), "annotations": map[string]string{}, }, - ClusterAgentComponentName: { + v2alpha1.ClusterAgentComponentName: { "name": customServiceAccount, "annotations": customServiceAccountAnnotations, }, - ClusterChecksRunnerComponentName: { + v2alpha1.ClusterChecksRunnerComponentName: { "name": fmt.Sprintf("%s-%s", ddaName, DefaultClusterChecksRunnerResourceSuffix), "annotations": map[string]string{}, }, @@ -236,16 +236,16 @@ func TestServiceAccountAnnotationOverride(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - res := map[ComponentName]map[string]interface{}{ - NodeAgentComponentName: { + res := map[v2alpha1.ComponentName]map[string]interface{}{ + v2alpha1.NodeAgentComponentName: { "name": GetAgentServiceAccount(tt.dda), "annotations": GetAgentServiceAccountAnnotations(tt.dda), }, - ClusterChecksRunnerComponentName: { + v2alpha1.ClusterChecksRunnerComponentName: { "name": GetClusterChecksRunnerServiceAccount(tt.dda), "annotations": GetClusterChecksRunnerServiceAccountAnnotations(tt.dda), }, - ClusterAgentComponentName: { + v2alpha1.ClusterAgentComponentName: { "name": GetClusterAgentServiceAccount(tt.dda), "annotations": GetClusterAgentServiceAccountAnnotations(tt.dda), }, diff --git a/pkg/controller/utils/datadog/metrics_forwarder_test.go b/pkg/controller/utils/datadog/metrics_forwarder_test.go index cf4e7cd5d..06e17b4b4 100644 --- a/pkg/controller/utils/datadog/metrics_forwarder_test.go +++ b/pkg/controller/utils/datadog/metrics_forwarder_test.go @@ -16,11 +16,11 @@ import ( "testing" v2alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" apiutils "github.com/DataDog/datadog-operator/api/utils" "github.com/DataDog/datadog-operator/pkg/config" "github.com/DataDog/datadog-operator/pkg/kubernetes" "github.com/DataDog/datadog-operator/pkg/secrets" + "github.com/DataDog/datadog-operator/pkg/testutils" "github.com/stretchr/testify/mock" assert "github.com/stretchr/testify/require" @@ -178,7 +178,7 @@ func TestReconcileDatadogAgent_getCredentials(t *testing.T) { client: fake.NewFakeClient(), }, args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ Credentials: &v2alpha1.DatadogCredentials{ APIKey: apiutils.NewStringPointer(apiKey), }, @@ -197,7 +197,7 @@ func TestReconcileDatadogAgent_getCredentials(t *testing.T) { client: fake.NewFakeClient(), }, args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ Credentials: &v2alpha1.DatadogCredentials{ APIKey: apiutils.NewStringPointer(apiKey), }, @@ -216,7 +216,7 @@ func TestReconcileDatadogAgent_getCredentials(t *testing.T) { client: fake.NewFakeClient(), }, args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ Credentials: &v2alpha1.DatadogCredentials{ APISecret: &v2alpha1.SecretConfig{ SecretName: "datadog-creds-api", @@ -248,7 +248,7 @@ func TestReconcileDatadogAgent_getCredentials(t *testing.T) { client: fake.NewFakeClient(), }, args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ Credentials: &v2alpha1.DatadogCredentials{ APIKey: apiutils.NewStringPointer(encAPIKey), }, @@ -276,7 +276,7 @@ func TestReconcileDatadogAgent_getCredentials(t *testing.T) { client: fake.NewFakeClient(), }, args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ Credentials: &v2alpha1.DatadogCredentials{ APIKey: apiutils.NewStringPointer(encAPIKey), }, @@ -305,7 +305,7 @@ func TestReconcileDatadogAgent_getCredentials(t *testing.T) { client: fake.NewFakeClient(), }, args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{}), + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{}), loadFunc: func(m *metricsForwarder, d *secrets.DummyDecryptor) { os.Unsetenv(v2alpha1.DDAPIKey) os.Unsetenv(v2alpha1.DDAppKey) @@ -703,14 +703,14 @@ func Test_getbaseURL(t *testing.T) { { name: "Get default baseURL", args: args{ - dda: test.NewDatadogAgent("foo", "bar", nil), + dda: testutils.NewDatadogAgent("foo", "bar", nil), }, want: "https://api.datadoghq.com", }, { name: "Compute baseURL from site when passing Site", args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ Site: &euSite, }), }, @@ -719,7 +719,7 @@ func Test_getbaseURL(t *testing.T) { { name: "Compute baseURL from endpoint.URL when Site is not defined", args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ Endpoint: &v2alpha1.Endpoint{ URL: apiutils.NewStringPointer("https://test.url.com"), }, @@ -730,7 +730,7 @@ func Test_getbaseURL(t *testing.T) { { name: "Test that DDUrl takes precedence over Site", args: args{ - dda: test.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ + dda: testutils.NewDatadogAgent("foo", "bar", &v2alpha1.GlobalConfig{ Site: &euSite, Endpoint: &v2alpha1.Endpoint{ URL: apiutils.NewStringPointer("https://test.url.com"), diff --git a/api/datadoghq/v2alpha1/test/builder.go b/pkg/testutils/builder.go similarity index 99% rename from api/datadoghq/v2alpha1/test/builder.go rename to pkg/testutils/builder.go index b8d754938..28a2f4e61 100644 --- a/api/datadoghq/v2alpha1/test/builder.go +++ b/pkg/testutils/builder.go @@ -3,14 +3,14 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -package test +package testutils import ( "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" - "github.com/DataDog/datadog-operator/api/utils" apiutils "github.com/DataDog/datadog-operator/api/utils" + "github.com/DataDog/datadog-operator/internal/controller/datadogagent/defaults" "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/otelcollector/defaultconfig" - defaulting "github.com/DataDog/datadog-operator/pkg/defaulting" + "github.com/DataDog/datadog-operator/pkg/defaulting" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -39,7 +39,7 @@ func NewDatadogAgentBuilder() *DatadogAgentBuilder { // NewDefaultDatadogAgentBuilder created DatadogAgent and applies defaults func NewDefaultDatadogAgentBuilder() *DatadogAgentBuilder { dda := &v2alpha1.DatadogAgent{} - v2alpha1.DefaultDatadogAgent(dda) + defaults.DefaultDatadogAgent(dda) return &DatadogAgentBuilder{ datadogAgent: *dda, @@ -63,7 +63,7 @@ func (builder *DatadogAgentBuilder) Build() *v2alpha1.DatadogAgent { // BuildWithDefaults applies defaults to current properties and returns resulting DatadogAgent func (builder *DatadogAgentBuilder) BuildWithDefaults() *v2alpha1.DatadogAgent { - v2alpha1.DefaultDatadogAgent(&builder.datadogAgent) + defaults.DefaultDatadogAgent(&builder.datadogAgent) return &builder.datadogAgent } @@ -870,8 +870,8 @@ func (builder *DatadogAgentBuilder) WithSingleContainerStrategy(enabled bool) *D func (builder *DatadogAgentBuilder) WithCredentials(apiKey, appKey string) *DatadogAgentBuilder { builder.datadogAgent.Spec.Global.Credentials = &v2alpha1.DatadogCredentials{ - APIKey: utils.NewStringPointer(apiKey), - AppKey: utils.NewStringPointer(appKey), + APIKey: apiutils.NewStringPointer(apiKey), + AppKey: apiutils.NewStringPointer(appKey), } return builder } diff --git a/api/datadoghq/v2alpha1/test/new.go b/pkg/testutils/new.go similarity index 98% rename from api/datadoghq/v2alpha1/test/new.go rename to pkg/testutils/new.go index 97b00084b..8194719a9 100644 --- a/api/datadoghq/v2alpha1/test/new.go +++ b/pkg/testutils/new.go @@ -3,7 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -package test +package testutils import ( "fmt" From 0ca2c91c14d8283118355f60ed3796643a91eeaa Mon Sep 17 00:00:00 2001 From: Wassim Dhif Date: Fri, 27 Dec 2024 16:01:07 +0100 Subject: [PATCH 8/8] feat(admission): add delete RBAC for datadog-webhook (#1591) Signed-off-by: Wassim DHIF --- .../controller/datadogagent/feature/admissioncontroller/rbac.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/controller/datadogagent/feature/admissioncontroller/rbac.go b/internal/controller/datadogagent/feature/admissioncontroller/rbac.go index d6b938061..6a7aa6da0 100644 --- a/internal/controller/datadogagent/feature/admissioncontroller/rbac.go +++ b/internal/controller/datadogagent/feature/admissioncontroller/rbac.go @@ -31,6 +31,7 @@ func getRBACClusterPolicyRules(webhookName string, cwsInstrumentationEnabled boo rbac.ListVerb, rbac.WatchVerb, rbac.UpdateVerb, + rbac.DeleteVerb, }, }, // ExtendedDaemonsetReplicaSets