Skip to content

Commit

Permalink
[cleanup] shuffle constants in pkg/config (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
celenechang authored Sep 23, 2024
1 parent e9fa9ce commit 3c38ef2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions api/datadoghq/common/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 1 addition & 10 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions pkg/datadogclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 3c38ef2

Please sign in to comment.