Skip to content

Commit

Permalink
Do not enable the cri check when running on a docker setup (#51)
Browse files Browse the repository at this point in the history
* Do not enable the `cri` check when running on a `docker` setup

Co-authored-by: Cedric Lamoriniere <cedric.lamoriniere@datadoghq.com>
  • Loading branch information
L3n41c and clamoriniere committed Jul 1, 2020
1 parent 1b1d6ae commit fe7eb70
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 60 deletions.
6 changes: 3 additions & 3 deletions deploy/crds/datadoghq.com_datadogagents_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ spec:
description: Path to the container runtime socket (if different
from Docker) This is supported starting from agent 6.6.0
type: string
useCriSocketVolume:
description: Enable container runtime socket volume mounting
type: boolean
dockerSocketPath:
description: Path to the docker runtime socket
type: string
type: object
ddUrl:
description: The host of the Datadog intake server to send Agent
Expand Down
18 changes: 6 additions & 12 deletions pkg/apis/datadoghq/v1alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const (
defaultAgentImage string = "datadog/agent:latest"
defaultCollectEvents bool = false
defaultLeaderElection bool = false
defaultUseCriSocketVolume bool = true
defaultCriSocketPath string = "/var/run/docker.sock"
defaultDockerSocketPath string = "/var/run/docker.sock"
defaultDogstatsdOriginDetection bool = false
defaultUseDogStatsDSocketVolume bool = false
defaultApmEnabled bool = false
Expand Down Expand Up @@ -175,14 +174,6 @@ func IsDefaultedDatadogAgentSpecAgentConfig(config *NodeAgentConfig) bool {
return false
}

if config.CriSocket.UseCriSocketVolume == nil {
return false
}

if config.CriSocket.CriSocketPath == nil {
return false
}

if config.Dogstatsd == nil {
return false
}
Expand Down Expand Up @@ -420,11 +411,14 @@ func DefaultDatadogAgentSpecAgentConfig(config *NodeAgentConfig) *NodeAgentConfi

if config.CriSocket == nil {
config.CriSocket = &CRISocketConfig{
UseCriSocketVolume: NewBoolPointer(defaultUseCriSocketVolume),
CriSocketPath: NewStringPointer(defaultCriSocketPath),
DockerSocketPath: NewStringPointer(defaultDockerSocketPath),
}
}

if config.CriSocket.DockerSocketPath == nil {
config.CriSocket.DockerSocketPath = NewStringPointer(defaultDockerSocketPath)
}

if config.Dogstatsd == nil {
config.Dogstatsd = &DogstatsdConfig{
DogstatsdOriginDetection: NewBoolPointer(defaultDogstatsdOriginDetection),
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/datadoghq/v1alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,9 @@ type NodeAgentConfig struct {
// CRISocketConfig contains the CRI socket configuration parameters
// +k8s:openapi-gen=true
type CRISocketConfig struct {
// Enable container runtime socket volume mounting
UseCriSocketVolume *bool `json:"useCriSocketVolume,omitempty"`
// Path to the docker runtime socket
// +optional
DockerSocketPath *string `json:"dockerSocketPath,omitempty"`

// Path to the container runtime socket (if different from Docker)
// This is supported starting from agent 6.6.0
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/datadoghq/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 3 additions & 3 deletions pkg/apis/datadoghq/v1alpha1/zz_generated.openapi.go

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

4 changes: 0 additions & 4 deletions pkg/controller/datadogagent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ func defaultEnvVars() []corev1.EnvVar {
Name: "DD_API_KEY",
ValueFrom: apiKeyValue(),
},
{
Name: "DD_CRI_SOCKET_PATH",
Value: "/host/var/run/docker.sock",
},
{
Name: "DOCKER_HOST",
Value: "unix:///host/var/run/docker.sock",
Expand Down
81 changes: 50 additions & 31 deletions pkg/controller/datadogagent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"math/rand"
"path/filepath"
"strconv"
"strings"
"time"

datadoghqv1alpha1 "github.com/DataDog/datadog-operator/pkg/apis/datadoghq/v1alpha1"
Expand Down Expand Up @@ -473,16 +472,16 @@ func getEnvVarsCommon(dda *datadoghqv1alpha1.DatadogAgent, needAPIKey bool) ([]c
})
}

if dda.Spec.Agent.Config.CriSocket != nil && dda.Spec.Agent.Config.CriSocket.CriSocketPath != nil {
envVars = append(envVars, corev1.EnvVar{
Name: datadoghqv1alpha1.DDCriSocketPath,
Value: filepath.Join(datadoghqv1alpha1.HostCriSocketPathPrefix, *dda.Spec.Agent.Config.CriSocket.CriSocketPath),
})

if strings.HasSuffix(*dda.Spec.Agent.Config.CriSocket.CriSocketPath, "docker.sock") {
if dda.Spec.Agent.Config.CriSocket != nil {
if dda.Spec.Agent.Config.CriSocket.CriSocketPath != nil {
envVars = append(envVars, corev1.EnvVar{
Name: datadoghqv1alpha1.DDCriSocketPath,
Value: filepath.Join(datadoghqv1alpha1.HostCriSocketPathPrefix, *dda.Spec.Agent.Config.CriSocket.CriSocketPath),
})
} else if dda.Spec.Agent.Config.CriSocket.DockerSocketPath != nil {
envVars = append(envVars, corev1.EnvVar{
Name: datadoghqv1alpha1.DockerHost,
Value: "unix://" + filepath.Join(datadoghqv1alpha1.HostCriSocketPathPrefix, *dda.Spec.Agent.Config.CriSocket.CriSocketPath),
Value: "unix://" + filepath.Join(datadoghqv1alpha1.HostCriSocketPathPrefix, *dda.Spec.Agent.Config.CriSocket.DockerSocketPath),
})
}
}
Expand Down Expand Up @@ -652,20 +651,24 @@ func getVolumesForAgent(dda *datadoghqv1alpha1.DatadogAgent) []corev1.Volume {
volumes = append(volumes, volume)
}

if dda.Spec.Agent.Config.CriSocket != nil && dda.Spec.Agent.Config.CriSocket.UseCriSocketVolume != nil && *dda.Spec.Agent.Config.CriSocket.UseCriSocketVolume {
path := "/var/run/docker.sock"
if dda.Spec.Agent.Config.CriSocket.CriSocketPath != nil {
if dda.Spec.Agent.Config.CriSocket != nil {
path := ""
if dda.Spec.Agent.Config.CriSocket.DockerSocketPath != nil {
path = *dda.Spec.Agent.Config.CriSocket.DockerSocketPath
} else if dda.Spec.Agent.Config.CriSocket.CriSocketPath != nil {
path = *dda.Spec.Agent.Config.CriSocket.CriSocketPath
}
criVolume := corev1.Volume{
Name: datadoghqv1alpha1.CriSocketVolumeName,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: filepath.Dir(path),
if path != "" {
criVolume := corev1.Volume{
Name: datadoghqv1alpha1.CriSocketVolumeName,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: filepath.Dir(path),
},
},
},
}
volumes = append(volumes, criVolume)
}
volumes = append(volumes, criVolume)
}
if datadoghqv1alpha1.BoolValue(dda.Spec.Agent.Process.Enabled) {
passwdVolume := corev1.Volume{
Expand Down Expand Up @@ -854,12 +857,20 @@ func getVolumeMountsForAgent(spec *datadoghqv1alpha1.DatadogAgentSpec) []corev1.
}

// Cri socket volume
if *spec.Agent.Config.CriSocket.UseCriSocketVolume {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: datadoghqv1alpha1.CriSocketVolumeName,
MountPath: filepath.Join(datadoghqv1alpha1.HostCriSocketPathPrefix, filepath.Dir(*spec.Agent.Config.CriSocket.CriSocketPath)),
ReadOnly: true,
})
if spec.Agent.Config.CriSocket != nil {
path := ""
if spec.Agent.Config.CriSocket.DockerSocketPath != nil {
path = *spec.Agent.Config.CriSocket.DockerSocketPath
} else if spec.Agent.Config.CriSocket.CriSocketPath != nil {
path = *spec.Agent.Config.CriSocket.CriSocketPath
}
if path != "" {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: datadoghqv1alpha1.CriSocketVolumeName,
MountPath: filepath.Join(datadoghqv1alpha1.HostCriSocketPathPrefix, filepath.Dir(path)),
ReadOnly: true,
})
}
}

// Dogstatsd volume
Expand Down Expand Up @@ -918,12 +929,20 @@ func getVolumeMountsForProcessAgent(spec *datadoghqv1alpha1.DatadogAgentSpec) []
}

// Cri socket volume
if *spec.Agent.Config.CriSocket.UseCriSocketVolume {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: datadoghqv1alpha1.CriSocketVolumeName,
MountPath: filepath.Join(datadoghqv1alpha1.HostCriSocketPathPrefix, filepath.Dir(*spec.Agent.Config.CriSocket.CriSocketPath)),
ReadOnly: true,
})
if spec.Agent.Config.CriSocket != nil {
path := ""
if spec.Agent.Config.CriSocket.DockerSocketPath != nil {
path = *spec.Agent.Config.CriSocket.DockerSocketPath
} else if spec.Agent.Config.CriSocket.CriSocketPath != nil {
path = *spec.Agent.Config.CriSocket.CriSocketPath
}
if path != "" {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: datadoghqv1alpha1.CriSocketVolumeName,
MountPath: filepath.Join(datadoghqv1alpha1.HostCriSocketPathPrefix, filepath.Dir(path)),
ReadOnly: true,
})
}
}

if datadoghqv1alpha1.BoolValue(spec.Agent.SystemProbe.Enabled) {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/utils/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func NewDatadogAgent(ns, name, image string, options *NewDatadogAgentOptions) *d
},
},
CriSocket: &datadoghqv1alpha1.CRISocketConfig{
CriSocketPath: datadoghqv1alpha1.NewStringPointer("/var/run/containerd/containerd.sock"),
UseCriSocketVolume: datadoghqv1alpha1.NewBoolPointer(true),
CriSocketPath: datadoghqv1alpha1.NewStringPointer("/var/run/containerd/containerd.sock"),
},
Env: []v1.EnvVar{
{
Expand Down

0 comments on commit fe7eb70

Please sign in to comment.