Skip to content

Commit

Permalink
Fix CRI vs Docker socket path priority in VolumeMounts (fix changes f…
Browse files Browse the repository at this point in the history
…rom #320) (#321)
  • Loading branch information
vboulineau committed Jun 10, 2021
1 parent 78737f2 commit 60c6bf4
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions controllers/datadogagent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,20 +1001,14 @@ func getVolumesForAgent(dda *datadoghqv1alpha1.DatadogAgent) []corev1.Volume {
},
}

var userCriPath string
if dda.Spec.Agent.Config.CriSocket != nil {
if dda.Spec.Agent.Config.CriSocket.CriSocketPath != nil {
userCriPath = *dda.Spec.Agent.Config.CriSocket.CriSocketPath
runtimeVolume.VolumeSource.HostPath.Path = filepath.Dir(*dda.Spec.Agent.Config.CriSocket.CriSocketPath)
} else if dda.Spec.Agent.Config.CriSocket.DockerSocketPath != nil {
userCriPath = *dda.Spec.Agent.Config.CriSocket.DockerSocketPath
runtimeVolume.VolumeSource.HostPath.Path = filepath.Dir(*dda.Spec.Agent.Config.CriSocket.DockerSocketPath)
}
}

// Always use default mount (/var/run) except if user path is not under the same path
if userCriPath != "" && !strings.HasPrefix(userCriPath, defaultRuntimeDir) {
runtimeVolume.VolumeSource.HostPath.Path = userCriPath
}

volumes = append(volumes, runtimeVolume)

if shouldAddProcessContainer(dda) || isComplianceEnabled(&dda.Spec) {
Expand Down Expand Up @@ -1463,10 +1457,10 @@ func getVolumeMountForChecksd() corev1.VolumeMount {
func getVolumeMountForRuntimeSockets(criSocket *datadoghqv1alpha1.CRISocketConfig) corev1.VolumeMount {
var socketPath string
if criSocket != nil {
if criSocket.DockerSocketPath != nil {
socketPath = *criSocket.DockerSocketPath
} else if criSocket.CriSocketPath != nil {
if criSocket.CriSocketPath != nil {
socketPath = *criSocket.CriSocketPath
} else if criSocket.DockerSocketPath != nil {
socketPath = *criSocket.DockerSocketPath
}
}

Expand Down

0 comments on commit 60c6bf4

Please sign in to comment.