Skip to content

Commit

Permalink
Remove /usr/lib references at DaemonSet (#50) (kubernetes-sigs#150)
Browse files Browse the repository at this point in the history
In most cases shared libraries directory /lib is a dynamic link to
 /usr/lib but in some other cases as Ubuntu 18.04 LTS or Debian 11,
those directories have completely different content. In any case
in-tree modules can be found on /lib/modules/KERNEL_VERSION/ so in
order to avoid compatibility issues depending which OS Kubernetes
nodes are running we should stick to /lib as a mount point for
DaemonSet. Also nodeLibModulesPath has been restricted to
/lib/modules/KERNEL_VERSION/.

Upstream-Commit: f7499fe

Co-authored-by: Enrique Belarte Luque <[email protected]>
  • Loading branch information
qbarrand and enriquebelarte authored Nov 28, 2022
1 parent 96c5be7 commit ddb65df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
19 changes: 2 additions & 17 deletions internal/daemonset/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import (
const (
kubeletDevicePluginsVolumeName = "kubelet-device-plugins"
kubeletDevicePluginsPath = "/var/lib/kubelet/device-plugins"
nodeLibModulesPath = "/lib/modules"
nodeLibModulesVolumeName = "node-lib-modules"
nodeUsrLibModulesPath = "/usr/lib/modules"
nodeUsrLibModulesVolumeName = "node-usr-lib-modules"
nodeVarLibFirmwarePath = "/var/lib/firmware"
nodeVarLibFirmwareVolumeName = "node-var-lib-firmware"
devicePluginKernelVersion = ""
Expand Down Expand Up @@ -118,6 +115,8 @@ func (dc *daemonSetGenerator) SetDriverContainerAsDesired(ctx context.Context, d
nodeSelector := CopyMapStringString(mod.Spec.Selector)
nodeSelector[dc.kernelLabel] = kernelVersion

nodeLibModulesPath := "/lib/modules/" + kernelVersion

hostPathDirectory := v1.HostPathDirectory
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate

Expand Down Expand Up @@ -154,11 +153,6 @@ func (dc *daemonSetGenerator) SetDriverContainerAsDesired(ctx context.Context, d
ReadOnly: true,
MountPath: nodeLibModulesPath,
},
{
Name: nodeUsrLibModulesVolumeName,
ReadOnly: true,
MountPath: nodeUsrLibModulesPath,
},
},
}

Expand All @@ -172,15 +166,6 @@ func (dc *daemonSetGenerator) SetDriverContainerAsDesired(ctx context.Context, d
},
},
},
{
Name: nodeUsrLibModulesVolumeName,
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: nodeUsrLibModulesPath,
Type: &hostPathDirectory,
},
},
},
}

if fw := mod.Spec.ModuleLoader.Container.Modprobe.FirmwarePath; fw != "" {
Expand Down
30 changes: 8 additions & 22 deletions internal/daemonset/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var _ = Describe("SetDriverContainerAsDesired", func() {
err := dg.SetDriverContainerAsDesired(context.Background(), &ds, "test-image", mod, kernelVersion)
Expect(err).NotTo(HaveOccurred())
Expect(ds.Spec.Template.Spec.Containers).To(HaveLen(1))
Expect(ds.Spec.Template.Spec.Volumes).To(HaveLen(2))
Expect(ds.Spec.Template.Spec.Volumes).To(HaveLen(1))
})

It("should add the volume and volume mount for firmware if FirmwarePath is set", func() {
Expand Down Expand Up @@ -116,10 +116,10 @@ var _ = Describe("SetDriverContainerAsDesired", func() {

err := dg.SetDriverContainerAsDesired(context.Background(), &ds, "test-image", mod, kernelVersion)
Expect(err).NotTo(HaveOccurred())
Expect(ds.Spec.Template.Spec.Volumes).To(HaveLen(3))
Expect(ds.Spec.Template.Spec.Volumes[2]).To(Equal(vol))
Expect(ds.Spec.Template.Spec.Containers[0].VolumeMounts).To(HaveLen(3))
Expect(ds.Spec.Template.Spec.Containers[0].VolumeMounts[2]).To(Equal(volm))
Expect(ds.Spec.Template.Spec.Volumes).To(HaveLen(2))
Expect(ds.Spec.Template.Spec.Volumes[1]).To(Equal(vol))
Expect(ds.Spec.Template.Spec.Containers[0].VolumeMounts).To(HaveLen(2))
Expect(ds.Spec.Template.Spec.Containers[0].VolumeMounts[1]).To(Equal(volm))
})

It("should add the default ServiceAccount to the module loader if it is not set in the spec", func() {
Expand All @@ -143,7 +143,7 @@ var _ = Describe("SetDriverContainerAsDesired", func() {
imageRepoSecretName = "image-repo-secret"
serviceAccountName = "driver-service-account"
)

fullModulesPath := "/lib/modules/" + kernelVersion
mod := kmmv1beta1.Module{
TypeMeta: metav1.TypeMeta{
APIVersion: kmmv1beta1.GroupVersion.String(),
Expand Down Expand Up @@ -227,12 +227,7 @@ var _ = Describe("SetDriverContainerAsDesired", func() {
{
Name: "node-lib-modules",
ReadOnly: true,
MountPath: "/lib/modules",
},
{
Name: "node-usr-lib-modules",
ReadOnly: true,
MountPath: "/usr/lib/modules",
MountPath: fullModulesPath,
},
},
SecurityContext: &v1.SecurityContext{
Expand Down Expand Up @@ -261,16 +256,7 @@ var _ = Describe("SetDriverContainerAsDesired", func() {
Name: "node-lib-modules",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/lib/modules",
Type: &directory,
},
},
},
{
Name: "node-usr-lib-modules",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/usr/lib/modules",
Path: fullModulesPath,
Type: &directory,
},
},
Expand Down

0 comments on commit ddb65df

Please sign in to comment.