Skip to content

Commit

Permalink
feat: Add SLES subscription mounts
Browse files Browse the repository at this point in the history
Add required mounts for MOFED in case of SLES.

Signed-off-by: Fred Rolland <[email protected]>
  • Loading branch information
rollandf committed Nov 24, 2024
1 parent 59141c4 commit e06a46e
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 6 deletions.
20 changes: 18 additions & 2 deletions pkg/state/state_ofed.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ var CertConfigPathMap = map[string]string{
"ubuntu": "/etc/ssl/certs",
"rhcos": "/etc/pki/ca-trust/extracted/pem",
"rhel": "/etc/pki/ca-trust/extracted/pem",
"sles": "/etc/ssl",
}

// RepoConfigPathMap indicates standard OS specific paths for repository configuration files
var RepoConfigPathMap = map[string]string{
"ubuntu": "/etc/apt/sources.list.d",
"rhcos": "/etc/yum.repos.d",
"rhel": "/etc/yum.repos.d",
"sles": "/etc/zypp/repos.d/",
}

// MountPathToVolumeSource maps a container mount path to a VolumeSource
Expand Down Expand Up @@ -148,6 +150,20 @@ var SubscriptionPathMap = map[string]MountPathToVolumeSource{
},
},
},
"sles": {
"/etc/zypp/credentials.d": v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/etc/zypp/credentials.d",
Type: newHostPathType(v1.HostPathDirectory),
},
},
"/etc/SUSEConnect": v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/etc/SUSEConnect",
Type: newHostPathType(v1.HostPathFileOrCreate),
},
},
},
}

func newHostPathType(pathType v1.HostPathType) *v1.HostPathType {
Expand Down Expand Up @@ -829,8 +845,8 @@ func (s *stateOFED) handleCertConfig(
func (s *stateOFED) handleSubscriptionVolumes(
ctx context.Context, osname string, runtime string, mounts *additionalVolumeMounts) error {
reqLogger := log.FromContext(ctx)
if osname == "rhel" && runtime != nodeinfo.CRIO {
reqLogger.V(consts.LogLevelDebug).Info("Setting subscription mounts for RHEL with non CRIO container runtime")
if osname == "rhel" && runtime != nodeinfo.CRIO || osname == "sles" {
reqLogger.V(consts.LogLevelDebug).Info("Setting subscription mounts for OS:%s, runtime:%s", osname, runtime)
pathToVolumeSource, ok := SubscriptionPathMap[osname]
if !ok {
return fmt.Errorf("failed to find subscription volumes definition for os: %v", osname)
Expand Down
118 changes: 114 additions & 4 deletions pkg/state/state_ofed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,63 @@ var _ = Describe("MOFED state test", func() {
ds := appsv1.DaemonSet{}
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &ds)
Expect(err).NotTo(HaveOccurred())
verifySubscriptionMounts(ds.Spec.Template.Spec.Containers[0].VolumeMounts)
verifySubscriptionVolumes(ds.Spec.Template.Spec.Volumes)
verifySubscriptionMountsRhel(ds.Spec.Template.Spec.Containers[0].VolumeMounts)
verifySubscriptionVolumesRhel(ds.Spec.Template.Spec.Volumes)
}
})
})
It("Should Render subscription mounts for SLES", func() {
client := mocks.ControllerRuntimeClient{}
manifestBaseDir := "../../manifests/state-ofed-driver"

files, err := utils.GetFilesWithSuffix(manifestBaseDir, render.ManifestFileSuffix...)
Expect(err).NotTo(HaveOccurred())
renderer := render.NewRenderer(files)

ofedState := stateOFED{
stateSkel: stateSkel{
name: stateOFEDName,
description: stateOFEDDescription,
client: &client,
renderer: renderer,
},
}
cr := &v1alpha1.NicClusterPolicy{}
cr.Name = "nic-cluster-policy"
cr.Spec.OFEDDriver = &v1alpha1.OFEDDriverSpec{
ImageSpec: v1alpha1.ImageSpec{
Image: "mofed",
Repository: "nvcr.io/mellanox",
Version: "23.10-0.5.5.0",
},
}

By("Creating NodeProvider with 1 Nodes, SLES")
node := getNode("node1", kernelFull1)
node.Labels[nodeinfo.NodeLabelOSName] = "sles"
infoProvider := nodeinfo.NewProvider([]*v1.Node{
node,
})
catalog := NewInfoCatalog()
catalog.Add(InfoTypeClusterType, &dummyProvider{})
catalog.Add(InfoTypeNodeInfo, infoProvider)
catalog.Add(InfoTypeDocaDriverImage, &dummyOfedImageProvider{tagExists: false})
objs, err := ofedState.GetManifestObjects(ctx, cr, catalog, testLogger)
Expect(err).NotTo(HaveOccurred())
// Expect 5 objects: 1 DS per pool, Service Account, Role, RoleBinding
Expect(len(objs)).To(Equal(4))
By("Verify Subscription mounts")
for _, obj := range objs {
if obj.GetKind() != "DaemonSet" {
continue
}
ds := appsv1.DaemonSet{}
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &ds)
Expect(err).NotTo(HaveOccurred())
verifySubscriptionMountsSles(ds.Spec.Template.Spec.Containers[0].VolumeMounts)
verifySubscriptionVolumesSles(ds.Spec.Template.Spec.Volumes)
}
})
Context("Render Manifests DTK", func() {
It("Should Render DaemonSet with DTK and additional mounts", func() {
dtkImageName := "quay.io/openshift-release-dev/ocp-v4.0-art-dev:414"
Expand Down Expand Up @@ -637,7 +689,7 @@ func verifyPodAntiInfinity(affinity *v1.Affinity) {
Expect(*affinity).To(BeEquivalentTo(expected))
}

func verifySubscriptionMounts(mounts []v1.VolumeMount) {
func verifySubscriptionMountsRhel(mounts []v1.VolumeMount) {
By("Verify Subscription Mounts")
sub0 := v1.VolumeMount{
Name: "subscription-config-0",
Expand Down Expand Up @@ -668,7 +720,7 @@ func verifySubscriptionMounts(mounts []v1.VolumeMount) {
Expect(slices.Contains(mounts, sub2)).To(BeTrue())
}

func verifySubscriptionVolumes(volumes []v1.Volume) {
func verifySubscriptionVolumesRhel(volumes []v1.Volume) {
By("Verify Subscription Volumes")
sub0 := v1.Volume{
Name: "subscription-config-0",
Expand Down Expand Up @@ -719,6 +771,64 @@ func verifySubscriptionVolumes(volumes []v1.Volume) {
Expect(foundSub2).To(BeTrue())
}

func verifySubscriptionMountsSles(mounts []v1.VolumeMount) {
By("Verify Subscription Mounts")
sub0 := v1.VolumeMount{
Name: "subscription-config-0",
ReadOnly: true,
MountPath: "/etc/SUSEConnect",
SubPath: "",
MountPropagation: nil,
SubPathExpr: "",
}
Expect(slices.Contains(mounts, sub0)).To(BeTrue())
sub1 := v1.VolumeMount{
Name: "subscription-config-1",
ReadOnly: true,
MountPath: "/etc/zypp/credentials.d",
SubPath: "",
MountPropagation: nil,
SubPathExpr: "",
}
Expect(slices.Contains(mounts, sub1)).To(BeTrue())
}

func verifySubscriptionVolumesSles(volumes []v1.Volume) {
By("Verify Subscription Volumes")
sub0 := v1.Volume{
Name: "subscription-config-0",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/etc/SUSEConnect",
Type: newHostPathType(v1.HostPathFileOrCreate),
},
},
}
sub1 := v1.Volume{
Name: "subscription-config-1",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/etc/zypp/credentials.d",
Type: newHostPathType(v1.HostPathDirectory),
},
},
}
foundSub0 := false
foundSub1 := false
for i := range volumes {
if volumes[i].Name == "subscription-config-0" {
Expect(volumes[i]).To(BeEquivalentTo(sub0))
foundSub0 = true
}
if volumes[i].Name == "subscription-config-1" {
Expect(volumes[i]).To(BeEquivalentTo(sub1))
foundSub1 = true
}
}
Expect(foundSub0).To(BeTrue())
Expect(foundSub1).To(BeTrue())
}

func verifyAdditionalMounts(mounts []v1.VolumeMount) {
By("Verify Additional Mounts")
repo := v1.VolumeMount{
Expand Down

0 comments on commit e06a46e

Please sign in to comment.