Skip to content

Commit fbce8f3

Browse files
committed
feat: Add SLES subscription mounts
Add required mounts for MOFED in case of SLES. Signed-off-by: Fred Rolland <[email protected]>
1 parent 59141c4 commit fbce8f3

File tree

2 files changed

+132
-6
lines changed

2 files changed

+132
-6
lines changed

pkg/state/state_ofed.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ var CertConfigPathMap = map[string]string{
111111
"ubuntu": "/etc/ssl/certs",
112112
"rhcos": "/etc/pki/ca-trust/extracted/pem",
113113
"rhel": "/etc/pki/ca-trust/extracted/pem",
114+
"sles": "/etc/ssl",
114115
}
115116

116117
// RepoConfigPathMap indicates standard OS specific paths for repository configuration files
117118
var RepoConfigPathMap = map[string]string{
118119
"ubuntu": "/etc/apt/sources.list.d",
119120
"rhcos": "/etc/yum.repos.d",
120121
"rhel": "/etc/yum.repos.d",
122+
"sles": "/etc/zypp/repos.d",
121123
}
122124

123125
// MountPathToVolumeSource maps a container mount path to a VolumeSource
@@ -148,6 +150,20 @@ var SubscriptionPathMap = map[string]MountPathToVolumeSource{
148150
},
149151
},
150152
},
153+
"sles": {
154+
"/etc/zypp/credentials.d": v1.VolumeSource{
155+
HostPath: &v1.HostPathVolumeSource{
156+
Path: "/etc/zypp/credentials.d",
157+
Type: newHostPathType(v1.HostPathDirectory),
158+
},
159+
},
160+
"/etc/SUSEConnect": v1.VolumeSource{
161+
HostPath: &v1.HostPathVolumeSource{
162+
Path: "/etc/SUSEConnect",
163+
Type: newHostPathType(v1.HostPathFileOrCreate),
164+
},
165+
},
166+
},
151167
}
152168

153169
func newHostPathType(pathType v1.HostPathType) *v1.HostPathType {
@@ -829,8 +845,8 @@ func (s *stateOFED) handleCertConfig(
829845
func (s *stateOFED) handleSubscriptionVolumes(
830846
ctx context.Context, osname string, runtime string, mounts *additionalVolumeMounts) error {
831847
reqLogger := log.FromContext(ctx)
832-
if osname == "rhel" && runtime != nodeinfo.CRIO {
833-
reqLogger.V(consts.LogLevelDebug).Info("Setting subscription mounts for RHEL with non CRIO container runtime")
848+
if osname == "rhel" && runtime != nodeinfo.CRIO || osname == "sles" {
849+
reqLogger.V(consts.LogLevelDebug).Info("Setting subscription mounts for OS:%s, runtime:%s", osname, runtime)
834850
pathToVolumeSource, ok := SubscriptionPathMap[osname]
835851
if !ok {
836852
return fmt.Errorf("failed to find subscription volumes definition for os: %v", osname)

pkg/state/state_ofed_test.go

Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,63 @@ var _ = Describe("MOFED state test", func() {
375375
ds := appsv1.DaemonSet{}
376376
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &ds)
377377
Expect(err).NotTo(HaveOccurred())
378-
verifySubscriptionMounts(ds.Spec.Template.Spec.Containers[0].VolumeMounts)
379-
verifySubscriptionVolumes(ds.Spec.Template.Spec.Volumes)
378+
verifySubscriptionMountsRhel(ds.Spec.Template.Spec.Containers[0].VolumeMounts)
379+
verifySubscriptionVolumesRhel(ds.Spec.Template.Spec.Volumes)
380380
}
381381
})
382382
})
383+
It("Should Render subscription mounts for SLES", func() {
384+
client := mocks.ControllerRuntimeClient{}
385+
manifestBaseDir := "../../manifests/state-ofed-driver"
386+
387+
files, err := utils.GetFilesWithSuffix(manifestBaseDir, render.ManifestFileSuffix...)
388+
Expect(err).NotTo(HaveOccurred())
389+
renderer := render.NewRenderer(files)
390+
391+
ofedState := stateOFED{
392+
stateSkel: stateSkel{
393+
name: stateOFEDName,
394+
description: stateOFEDDescription,
395+
client: &client,
396+
renderer: renderer,
397+
},
398+
}
399+
cr := &v1alpha1.NicClusterPolicy{}
400+
cr.Name = "nic-cluster-policy"
401+
cr.Spec.OFEDDriver = &v1alpha1.OFEDDriverSpec{
402+
ImageSpec: v1alpha1.ImageSpec{
403+
Image: "mofed",
404+
Repository: "nvcr.io/mellanox",
405+
Version: "23.10-0.5.5.0",
406+
},
407+
}
408+
409+
By("Creating NodeProvider with 1 Nodes, SLES")
410+
node := getNode("node1", kernelFull1)
411+
node.Labels[nodeinfo.NodeLabelOSName] = "sles"
412+
infoProvider := nodeinfo.NewProvider([]*v1.Node{
413+
node,
414+
})
415+
catalog := NewInfoCatalog()
416+
catalog.Add(InfoTypeClusterType, &dummyProvider{})
417+
catalog.Add(InfoTypeNodeInfo, infoProvider)
418+
catalog.Add(InfoTypeDocaDriverImage, &dummyOfedImageProvider{tagExists: false})
419+
objs, err := ofedState.GetManifestObjects(ctx, cr, catalog, testLogger)
420+
Expect(err).NotTo(HaveOccurred())
421+
// Expect 5 objects: 1 DS per pool, Service Account, Role, RoleBinding
422+
Expect(len(objs)).To(Equal(4))
423+
By("Verify Subscription mounts")
424+
for _, obj := range objs {
425+
if obj.GetKind() != "DaemonSet" {
426+
continue
427+
}
428+
ds := appsv1.DaemonSet{}
429+
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &ds)
430+
Expect(err).NotTo(HaveOccurred())
431+
verifySubscriptionMountsSles(ds.Spec.Template.Spec.Containers[0].VolumeMounts)
432+
verifySubscriptionVolumesSles(ds.Spec.Template.Spec.Volumes)
433+
}
434+
})
383435
Context("Render Manifests DTK", func() {
384436
It("Should Render DaemonSet with DTK and additional mounts", func() {
385437
dtkImageName := "quay.io/openshift-release-dev/ocp-v4.0-art-dev:414"
@@ -637,7 +689,7 @@ func verifyPodAntiInfinity(affinity *v1.Affinity) {
637689
Expect(*affinity).To(BeEquivalentTo(expected))
638690
}
639691

640-
func verifySubscriptionMounts(mounts []v1.VolumeMount) {
692+
func verifySubscriptionMountsRhel(mounts []v1.VolumeMount) {
641693
By("Verify Subscription Mounts")
642694
sub0 := v1.VolumeMount{
643695
Name: "subscription-config-0",
@@ -668,7 +720,7 @@ func verifySubscriptionMounts(mounts []v1.VolumeMount) {
668720
Expect(slices.Contains(mounts, sub2)).To(BeTrue())
669721
}
670722

671-
func verifySubscriptionVolumes(volumes []v1.Volume) {
723+
func verifySubscriptionVolumesRhel(volumes []v1.Volume) {
672724
By("Verify Subscription Volumes")
673725
sub0 := v1.Volume{
674726
Name: "subscription-config-0",
@@ -719,6 +771,64 @@ func verifySubscriptionVolumes(volumes []v1.Volume) {
719771
Expect(foundSub2).To(BeTrue())
720772
}
721773

774+
func verifySubscriptionMountsSles(mounts []v1.VolumeMount) {
775+
By("Verify Subscription Mounts")
776+
sub0 := v1.VolumeMount{
777+
Name: "subscription-config-0",
778+
ReadOnly: true,
779+
MountPath: "/etc/SUSEConnect",
780+
SubPath: "",
781+
MountPropagation: nil,
782+
SubPathExpr: "",
783+
}
784+
Expect(slices.Contains(mounts, sub0)).To(BeTrue())
785+
sub1 := v1.VolumeMount{
786+
Name: "subscription-config-1",
787+
ReadOnly: true,
788+
MountPath: "/etc/zypp/credentials.d",
789+
SubPath: "",
790+
MountPropagation: nil,
791+
SubPathExpr: "",
792+
}
793+
Expect(slices.Contains(mounts, sub1)).To(BeTrue())
794+
}
795+
796+
func verifySubscriptionVolumesSles(volumes []v1.Volume) {
797+
By("Verify Subscription Volumes")
798+
sub0 := v1.Volume{
799+
Name: "subscription-config-0",
800+
VolumeSource: v1.VolumeSource{
801+
HostPath: &v1.HostPathVolumeSource{
802+
Path: "/etc/SUSEConnect",
803+
Type: newHostPathType(v1.HostPathFileOrCreate),
804+
},
805+
},
806+
}
807+
sub1 := v1.Volume{
808+
Name: "subscription-config-1",
809+
VolumeSource: v1.VolumeSource{
810+
HostPath: &v1.HostPathVolumeSource{
811+
Path: "/etc/zypp/credentials.d",
812+
Type: newHostPathType(v1.HostPathDirectory),
813+
},
814+
},
815+
}
816+
foundSub0 := false
817+
foundSub1 := false
818+
for i := range volumes {
819+
if volumes[i].Name == "subscription-config-0" {
820+
Expect(volumes[i]).To(BeEquivalentTo(sub0))
821+
foundSub0 = true
822+
}
823+
if volumes[i].Name == "subscription-config-1" {
824+
Expect(volumes[i]).To(BeEquivalentTo(sub1))
825+
foundSub1 = true
826+
}
827+
}
828+
Expect(foundSub0).To(BeTrue())
829+
Expect(foundSub1).To(BeTrue())
830+
}
831+
722832
func verifyAdditionalMounts(mounts []v1.VolumeMount) {
723833
By("Verify Additional Mounts")
724834
repo := v1.VolumeMount{

0 commit comments

Comments
 (0)