Skip to content

Commit

Permalink
Support global registry configuration (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-mez committed Jun 3, 2021
1 parent 959b205 commit f95658e
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 113 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,9 @@ const (
ClusterRoleKind = "ClusterRole"
RoleKind = "Role"
ServiceAccountKind = "ServiceAccount"

// Container Registries

DefaultImageRegistry = "gcr.io/datadoghq"
JMXTagSuffix = "-jmx"
)
72 changes: 19 additions & 53 deletions api/v1alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import (
// default values
const (
DefaultLogLevel string = "INFO"
defaultAgentImage string = "gcr.io/datadoghq/agent:latest"
defaultAgentImageTag string = "7.28.0"
defaultClusterAgentImageTag string = "1.12.0"
defaultAgentImageName string = "agent"
defaultClusterAgentImageName string = "cluster-agent"
defaultCollectEvents bool = false
defaultLeaderElection bool = false
defaultDockerSocketPath string = "/var/run/docker.sock"
Expand Down Expand Up @@ -54,7 +57,6 @@ const (
defaultClusterAgentReplicas int32 = 1
defaultAgentCanaryReplicas int32 = 1
defaultClusterChecksRunnerReplicas int32 = 1
defaultClusterAgentImage string = "gcr.io/datadoghq/cluster-agent:latest"
defaultRollingUpdateMaxUnavailable = "10%"
defaultUpdateStrategy = appsv1.RollingUpdateDaemonSetStrategyType
defaultRollingUpdateMaxPodSchedulerFailure = "10%"
Expand Down Expand Up @@ -178,6 +180,10 @@ func IsDefaultedImageConfig(imageConfig *ImageConfig) bool {
return false
}

if imageConfig.Tag == "" {
return false
}

if imageConfig.PullPolicy == nil {
return false
}
Expand Down Expand Up @@ -501,7 +507,7 @@ func DefaultDatadogAgentSpecAgent(agent *DatadogAgentSpecAgentSpec) *DatadogAgen
agent.UseExtendedDaemonset = NewBoolPointer(false)
}

DefaultDatadogAgentSpecAgentImage(&agent.Image)
DefaultDatadogImage(&agent.Image, defaultAgentImageName, defaultAgentImageTag)
DefaultDatadogAgentSpecAgentConfig(agent)
DefaultDatadogAgentSpecRbacConfig(&agent.Rbac)
agent.DeploymentStrategy = DefaultDatadogAgentSpecDatadogAgentStrategy(agent.DeploymentStrategy)
Expand All @@ -512,15 +518,19 @@ func DefaultDatadogAgentSpecAgent(agent *DatadogAgentSpecAgentSpec) *DatadogAgen
return agent
}

// DefaultDatadogAgentSpecAgentImage used to default a ImageConfig
// return the defaulted ImageConfig
func DefaultDatadogAgentSpecAgentImage(image *ImageConfig) *ImageConfig {
// DefaultDatadogImage used to default a ImageConfig for the Agent, Cluster Agent and the Cluster Check Runner.
// Returns the defaulted ImageConfig.
func DefaultDatadogImage(image *ImageConfig, name, tag string) *ImageConfig {
if image == nil {
image = &ImageConfig{}
}

if image.Name == "" {
image.Name = defaultAgentImage
image.Name = name
}

if image.Tag == "" {
image.Tag = tag
}

if image.PullPolicy == nil {
Expand Down Expand Up @@ -858,7 +868,7 @@ func DefaultDatadogFeaturePrometheusScrape(prom *PrometheusScrapeConfig) *Promet
// DefaultDatadogAgentSpecClusterAgent used to default an DatadogAgentSpecClusterAgentSpec
// return the defaulted DatadogAgentSpecClusterAgentSpec
func DefaultDatadogAgentSpecClusterAgent(clusterAgent *DatadogAgentSpecClusterAgentSpec) *DatadogAgentSpecClusterAgentSpec {
DefaultDatadogAgentSpecClusterAgentImage(&clusterAgent.Image)
DefaultDatadogImage(&clusterAgent.Image, defaultClusterAgentImageName, defaultClusterAgentImageTag)
DefaultDatadogAgentSpecClusterAgentConfig(&clusterAgent.Config)
DefaultDatadogAgentSpecRbacConfig(&clusterAgent.Rbac)
DefaultNetworkPolicy(&clusterAgent.NetworkPolicy)
Expand Down Expand Up @@ -914,32 +924,10 @@ func GetKubeStateMetricsConfName(dcaConf *DatadogAgent) string {
return fmt.Sprintf("%s-%s", dcaConf.Name, DefaultKubeStateMetricsCoreConf)
}

// DefaultDatadogAgentSpecClusterAgentImage used to default ImageConfig for the Datadog Cluster Agent
// return the defaulted ImageConfig
func DefaultDatadogAgentSpecClusterAgentImage(image *ImageConfig) *ImageConfig {
if image == nil {
image = &ImageConfig{}
}

if image.Name == "" {
image.Name = defaultClusterAgentImage
}

if image.PullPolicy == nil {
image.PullPolicy = &defaultImagePullPolicy
}

if image.PullSecrets == nil {
image.PullSecrets = &[]corev1.LocalObjectReference{}
}

return image
}

// DefaultDatadogAgentSpecClusterChecksRunner used to default an DatadogAgentSpecClusterChecksRunnerSpec
// return the defaulted DatadogAgentSpecClusterChecksRunnerSpec
func DefaultDatadogAgentSpecClusterChecksRunner(clusterChecksRunner *DatadogAgentSpecClusterChecksRunnerSpec) *DatadogAgentSpecClusterChecksRunnerSpec {
DefaultDatadogAgentSpecClusterChecksRunnerImage(&clusterChecksRunner.Image)
DefaultDatadogImage(&clusterChecksRunner.Image, defaultAgentImageName, defaultAgentImageTag)
DefaultDatadogAgentSpecClusterChecksRunnerConfig(&clusterChecksRunner.Config)
DefaultDatadogAgentSpecRbacConfig(&clusterChecksRunner.Rbac)
DefaultNetworkPolicy(&clusterChecksRunner.NetworkPolicy)
Expand All @@ -961,28 +949,6 @@ func DefaultDatadogAgentSpecClusterChecksRunnerConfig(config *ClusterChecksRunne
return config
}

// DefaultDatadogAgentSpecClusterChecksRunnerImage used to default ImageConfig for the Datadog Cluster Agent
// return the defaulted ImageConfig
func DefaultDatadogAgentSpecClusterChecksRunnerImage(image *ImageConfig) *ImageConfig {
if image == nil {
image = &ImageConfig{}
}

if image.Name == "" {
image.Name = defaultAgentImage
}

if image.PullPolicy == nil {
image.PullPolicy = &defaultImagePullPolicy
}

if image.PullSecrets == nil {
image.PullSecrets = &[]corev1.LocalObjectReference{}
}

return image
}

// DefaultNetworkPolicy is used to default NetworkPolicy. Returns the defaulted
// ImageConfig
func DefaultNetworkPolicy(policy *NetworkPolicySpec) *NetworkPolicySpec {
Expand Down
21 changes: 19 additions & 2 deletions api/v1alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ type DatadogAgentSpec struct {
// Set to 'datadoghq.eu' to send data to the EU site.
// +optional
Site string `json:"site,omitempty"`

// Registry to use for all Agent images (default gcr.io/datadoghq).
// Use public.ecr.aws/datadog for AWS
// Use docker.io/datadog for DockerHub
// +optional
Registry *string `json:"registry,omitempty"`
}

// DatadogCredentials is a generic structure that holds credentials to access Datadog.
Expand Down Expand Up @@ -1151,10 +1157,21 @@ type DatadogAgentSpecClusterChecksRunnerSpec struct {
// +k8s:openapi-gen=true
type ImageConfig struct {
// Define the image to use:
// Use "gcr.io/datadoghq/agent:latest" for Datadog Agent 6
// Use "gcr.io/datadoghq/agent:latest" for Datadog Agent 7
// Use "datadog/dogstatsd:latest" for Standalone Datadog Agent DogStatsD6
// Use "gcr.io/datadoghq/cluster-agent:latest" for Datadog Cluster Agent
Name string `json:"name"`
// Use "agent" with the registry and tag configurations for <registry>/agent:<tag>
// Use "cluster-agent" with the registry and tag configurations for <registry>/cluster-agent:<tag>
Name string `json:"name,omitempty"`

// Define the image version to use:
// To be used if the Name field does not correspond to a full image string.
// +optional
Tag string `json:"tag,omitempty"`

// Define whether the Agent image should support JMX.
// +optional
JmxEnabled bool `json:"jmxEnabled,omitempty"`

// The Kubernetes pull policy:
// Use Always, Never or IfNotPresent.
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions api/v1alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 40 additions & 12 deletions config/crd/bases/v1/datadoghq.com_datadogagents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2857,11 +2857,17 @@ spec:
image:
description: The container image of the Datadog Agent.
properties:
jmxEnabled:
description: Define whether the Agent image should support
JMX.
type: boolean
name:
description: 'Define the image to use: Use "gcr.io/datadoghq/agent:latest"
for Datadog Agent 6 Use "datadog/dogstatsd:latest" for Standalone
for Datadog Agent 7 Use "datadog/dogstatsd:latest" for Standalone
Datadog Agent DogStatsD6 Use "gcr.io/datadoghq/cluster-agent:latest"
for Datadog Cluster Agent'
for Datadog Cluster Agent Use "agent" with the registry
and tag configurations for <registry>/agent:<tag> Use "cluster-agent"
with the registry and tag configurations for <registry>/cluster-agent:<tag>'
type: string
pullPolicy:
description: 'The Kubernetes pull policy: Use Always, Never
Expand All @@ -2881,8 +2887,10 @@ spec:
type: string
type: object
type: array
required:
- name
tag:
description: 'Define the image version to use: To be used
if the Name field does not correspond to a full image string.'
type: string
type: object
keepAnnotations:
description: KeepAnnotations allows the specification of annotations
Expand Down Expand Up @@ -6378,11 +6386,17 @@ spec:
image:
description: The container image of the Datadog Cluster Agent.
properties:
jmxEnabled:
description: Define whether the Agent image should support
JMX.
type: boolean
name:
description: 'Define the image to use: Use "gcr.io/datadoghq/agent:latest"
for Datadog Agent 6 Use "datadog/dogstatsd:latest" for Standalone
for Datadog Agent 7 Use "datadog/dogstatsd:latest" for Standalone
Datadog Agent DogStatsD6 Use "gcr.io/datadoghq/cluster-agent:latest"
for Datadog Cluster Agent'
for Datadog Cluster Agent Use "agent" with the registry
and tag configurations for <registry>/agent:<tag> Use "cluster-agent"
with the registry and tag configurations for <registry>/cluster-agent:<tag>'
type: string
pullPolicy:
description: 'The Kubernetes pull policy: Use Always, Never
Expand All @@ -6402,8 +6416,10 @@ spec:
type: string
type: object
type: array
required:
- name
tag:
description: 'Define the image version to use: To be used
if the Name field does not correspond to a full image string.'
type: string
type: object
keepAnnotations:
description: KeepAnnotations allows the specification of annotations
Expand Down Expand Up @@ -8936,11 +8952,17 @@ spec:
description: The container image of the Datadog Cluster Checks
Runner.
properties:
jmxEnabled:
description: Define whether the Agent image should support
JMX.
type: boolean
name:
description: 'Define the image to use: Use "gcr.io/datadoghq/agent:latest"
for Datadog Agent 6 Use "datadog/dogstatsd:latest" for Standalone
for Datadog Agent 7 Use "datadog/dogstatsd:latest" for Standalone
Datadog Agent DogStatsD6 Use "gcr.io/datadoghq/cluster-agent:latest"
for Datadog Cluster Agent'
for Datadog Cluster Agent Use "agent" with the registry
and tag configurations for <registry>/agent:<tag> Use "cluster-agent"
with the registry and tag configurations for <registry>/cluster-agent:<tag>'
type: string
pullPolicy:
description: 'The Kubernetes pull policy: Use Always, Never
Expand All @@ -8960,8 +8982,10 @@ spec:
type: string
type: object
type: array
required:
- name
tag:
description: 'Define the image version to use: To be used
if the Name field does not correspond to a full image string.'
type: string
type: object
networkPolicy:
description: Provide Cluster Checks Runner Network Policy configuration.
Expand Down Expand Up @@ -9247,6 +9271,10 @@ spec:
type: boolean
type: object
type: object
registry:
description: Registry to use for all Agent images (default gcr.io/datadoghq).
Use public.ecr.aws/datadog for AWS Use docker.io/datadog for DockerHub
type: string
site:
description: The site of the Datadog intake to send Agent data to.
Set to 'datadoghq.eu' to send data to the EU site.
Expand Down

0 comments on commit f95658e

Please sign in to comment.