Skip to content

Commit

Permalink
Merge pull request #1062 from swordqiu/hotfix/qj-simplify-telegraf-mo…
Browse files Browse the repository at this point in the history
…unts

fix: simplify mounts of telegraf container
  • Loading branch information
swordqiu authored Apr 7, 2024
2 parents ce9b17f + 3d0c9c3 commit 7bba3e0
Showing 1 changed file with 18 additions and 84 deletions.
102 changes: 18 additions & 84 deletions pkg/manager/component/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ func (m *telegrafManager) newTelegrafDaemonSet(
Name: "HOST_SYS",
Value: path.Join(hostRoot, "/sys"),
},
{
Name: "HOST_VAR",
Value: path.Join(hostRoot, "/var"),
},
{
Name: "HOST_RUN",
Value: path.Join(hostRoot, "/run"),
},
{
Name: "HOST_MOUNT_PREFIX",
Value: hostRoot,
Expand Down Expand Up @@ -159,52 +167,23 @@ func NewTelegrafVolume(
volumes: make([]corev1.Volume, 0),
volumeMounts: make([]corev1.VolumeMount, 0),
}
var bidirectional = corev1.MountPropagationBidirectional
h.volumeMounts = append(h.volumeMounts, []corev1.VolumeMount{
{
h.volumeMounts = append(h.volumeMounts,
corev1.VolumeMount{
Name: "etc-telegraf",
ReadOnly: false,
MountPath: "/etc/telegraf",
},
{
Name: "proc",
ReadOnly: true,
MountPath: path.Join(hostRoot, "/proc"),
},
{
Name: "sys",
corev1.VolumeMount{
Name: "root",
ReadOnly: true,
MountPath: path.Join(hostRoot, "/sys"),
},
{
Name: "root",
ReadOnly: true,
MountPath: hostRoot,
MountPropagation: &bidirectional,
},
{
Name: "run",
ReadOnly: false,
MountPath: "/var/run",
MountPropagation: &bidirectional,
},
{
Name: "dev",
ReadOnly: false,
MountPath: "/dev",
},
{
Name: "cloud",
ReadOnly: false,
MountPath: "/opt/cloud",
MountPropagation: &bidirectional,
MountPath: hostRoot,
},
}...)
)

var volSrcType = corev1.HostPathDirectoryOrCreate
var hostPathDirectory = corev1.HostPathDirectory
h.volumes = append(h.volumes, []corev1.Volume{
{
h.volumes = append(h.volumes,
corev1.Volume{
Name: "etc-telegraf",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Expand All @@ -213,34 +192,7 @@ func NewTelegrafVolume(
},
},
},
{
Name: "proc",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/proc",
Type: &hostPathDirectory,
},
},
},
{
Name: "run",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/var/run",
Type: &hostPathDirectory,
},
},
},
{
Name: "sys",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/sys",
Type: &hostPathDirectory,
},
},
},
{
corev1.Volume{
Name: "root",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Expand All @@ -249,24 +201,6 @@ func NewTelegrafVolume(
},
},
},
{
Name: "dev",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/dev",
Type: &hostPathDirectory,
},
},
},
{
Name: "cloud",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/opt/cloud",
Type: &hostPathDirectory,
},
},
},
}...)
)
return h
}

0 comments on commit 7bba3e0

Please sign in to comment.