Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cleanup] shuffle constants in pkg/config #1426

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading