diff --git a/api/datadoghq/common/envvar.go b/api/datadoghq/common/envvar.go index a2e062c71..94c26e8a7 100644 --- a/api/datadoghq/common/envvar.go +++ b/api/datadoghq/common/envvar.go @@ -65,6 +65,7 @@ const ( DDContainerCollectionEnabled = "DD_PROCESS_CONFIG_CONTAINER_COLLECTION_ENABLED" DDCriSocketPath = "DD_CRI_SOCKET_PATH" DDddURL = "DD_DD_URL" + DDURL = "DD_URL" DDDogstatsdEnabled = "DD_USE_DOGSTATSD" DDDogstatsdMapperProfiles = "DD_DOGSTATSD_MAPPER_PROFILES" DDDogstatsdNonLocalTraffic = "DD_DOGSTATSD_NON_LOCAL_TRAFFIC" diff --git a/pkg/config/config.go b/pkg/config/config.go index 571956e20..f2041e210 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -26,6 +26,7 @@ import ( datadoghqv2alpha1 "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" ) +// These constants are only used within pkg/config const ( // AgentWatchNamespaceEnvVar is a comma-separated list of namespaces watched by the DatadogAgent controller. agentWatchNamespaceEnvVar = "DD_AGENT_WATCH_NAMESPACE" @@ -38,16 +39,6 @@ const ( // WatchNamespaceEnvVar is a comma-separated list of namespaces watched by all controllers, unless a controller-specific configuration is provided. // An empty value means the operator is running with cluster scope. watchNamespaceEnvVar = "WATCH_NAMESPACE" - // DDAPIKeyEnvVar is the constant for the env variable DD_API_KEY which is the fallback - // API key to use if a resource does not have it defined in its spec. - DDAPIKeyEnvVar = "DD_API_KEY" - // DDAppKeyEnvVar is the constant for the env variable DD_APP_KEY which is the fallback - // App key to use if a resource does not have it defined in its spec. - DDAppKeyEnvVar = "DD_APP_KEY" - // DDURLEnvVar is the constant for the env variable DD_URL which is the - // host of the Datadog intake server to send data to. - DDURLEnvVar = "DD_URL" - // TODO consider moving DDSite here as well ) var ( diff --git a/pkg/config/creds.go b/pkg/config/creds.go index 0d954d8b7..7e2e16696 100644 --- a/pkg/config/creds.go +++ b/pkg/config/creds.go @@ -11,6 +11,7 @@ import ( "sync" "time" + apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" "github.com/DataDog/datadog-operator/pkg/secrets" "k8s.io/apimachinery/pkg/util/wait" @@ -53,8 +54,8 @@ func (cm *CredentialManager) GetCredentials() (Creds, error) { return creds, nil } - apiKey := os.Getenv(DDAPIKeyEnvVar) - appKey := os.Getenv(DDAppKeyEnvVar) + apiKey := os.Getenv(apicommon.DDAPIKey) + appKey := os.Getenv(apicommon.DDAppKey) if apiKey == "" || appKey == "" { return Creds{}, errors.New("empty API key and/or App key") diff --git a/pkg/datadogclient/client.go b/pkg/datadogclient/client.go index 7aae22a6b..2db5c7c28 100644 --- a/pkg/datadogclient/client.go +++ b/pkg/datadogclient/client.go @@ -111,8 +111,10 @@ func setupAuth(logger logr.Logger, creds config.Creds) (context.Context, error) ) apiURL := "" - if os.Getenv(config.DDURLEnvVar) != "" { - apiURL = os.Getenv(config.DDURLEnvVar) + if os.Getenv(apicommon.DDddURL) != "" { + apiURL = os.Getenv(apicommon.DDddURL) + } else if os.Getenv(apicommon.DDURL) != "" { + apiURL = os.Getenv(apicommon.DDURL) } else if site := os.Getenv(apicommon.DDSite); site != "" { apiURL = prefix + strings.TrimSpace(site) }