Skip to content

Commit

Permalink
Add default env vars for MOFED container
Browse files Browse the repository at this point in the history
In case of older distros (kernels),
we need to explictly specify CREATE_IFNAMES_UDEV
so that netdev names are preserved.

when MOFED container loads the driver, it reports
additional information to kernel about Nvidia network
devices that affect the way the OS names netdevs.

On newer distros (kernels) this is not needed as
inbox driver already reports this information.

Instruct MOFED container to install the
"name preserving udev" on the following OSes:

rhel < 9.0
ocp < 4.13
ubuntu < 22.04

Signed-off-by: adrianc <adrianc@nvidia.com>
  • Loading branch information
adrianchiris committed Jul 18, 2023
1 parent 668f978 commit c4c1d45
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
71 changes: 69 additions & 2 deletions pkg/state/state_ofed.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func (s *stateOFED) getManifestObjects(
nodeinfo.AttrTypeCPUArch, nodeinfo.AttrTypeOSName, nodeinfo.AttrTypeOSVer); err != nil {
return nil, err
}
nodeAttr := attrs[0].Attributes

if cr.Spec.OFEDDriver.StartupProbe == nil {
cr.Spec.OFEDDriver.StartupProbe = &mellanoxv1alpha1.PodProbeSpec{
Expand All @@ -394,8 +395,11 @@ func (s *stateOFED) getManifestObjects(
}
}

// Update MOFED Env variables with defaults for the cluster
cr.Spec.OFEDDriver.Env = s.mergeWithDefaultEnvs(cr.Spec.OFEDDriver.Env, nodeAttr)

additionalVolMounts := additionalVolumeMounts{}
osname := attrs[0].Attributes[nodeinfo.AttrTypeOSName]
osname := nodeAttr[nodeinfo.AttrTypeOSName]
// set any custom ssl key/certificate configuration provided
if cr.Spec.OFEDDriver.CertConfig != nil && cr.Spec.OFEDDriver.CertConfig.Name != "" {
destinationDir, err := getCertConfigPath(osname)
Expand All @@ -422,7 +426,6 @@ func (s *stateOFED) getManifestObjects(
}
}

nodeAttr := attrs[0].Attributes
renderData := &ofedManifestRenderData{
CrSpec: cr.Spec.OFEDDriver,
RuntimeSpec: &ofedRuntimeSpec{
Expand Down Expand Up @@ -590,3 +593,67 @@ func (s *stateOFED) setEnvFromClusterWideProxy(cr *mellanoxv1alpha1.NicClusterPo
)
}
}

// mergeWithDefaultEnvs returns env variables provided in currentEnvs merged with default
// env variables for MOFED container
func (s *stateOFED) mergeWithDefaultEnvs(
currentEnvs []v1.EnvVar, nodeAttrs map[nodeinfo.AttributeType]string) []v1.EnvVar {
if envVarsWithGet(currentEnvs).Get("CREATE_IFNAMES_UDEV") != nil {
// already exists dont overwrite
return currentEnvs
}

// CREATE_IFNAMES_UDEV: should be set to true for ubuntu < 22.04 , RHEL < 9, OCP < 4.13 if not provided
osName := nodeAttrs[nodeinfo.AttrTypeOSName]
osVer := nodeAttrs[nodeinfo.AttrTypeOSVer]
createIfnameUdevEnv := v1.EnvVar{Name: "CREATE_IFNAMES_UDEV", Value: "true"}

currVer, err := semver.NewVersion(osVer)
if err != nil {
return currentEnvs
}

ubuntuVer, err := semver.NewVersion("22.04")
if err != nil {
return currentEnvs
}

rhelVer, err := semver.NewVersion("9.0")
if err != nil {
return currentEnvs
}

rhcosVer, err := semver.NewVersion("4.13")
if err != nil {
return currentEnvs
}

switch osName {
case "ubuntu":
if currVer.LessThan(ubuntuVer) {
currentEnvs = append(currentEnvs, createIfnameUdevEnv)
}
case "rhel":
if currVer.LessThan(rhelVer) {
currentEnvs = append(currentEnvs, createIfnameUdevEnv)
}
case "rhcos":
if currVer.LessThan(rhcosVer) {
currentEnvs = append(currentEnvs, createIfnameUdevEnv)
}
}

return currentEnvs
}

type envVarsWithGet []v1.EnvVar

func (e envVarsWithGet) Get(name string) *v1.EnvVar {
for i := range e {
if e[i].Name == name {
return &e[i]
}
}

return nil
}
30 changes: 30 additions & 0 deletions pkg/state/state_ofed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,34 @@ var _ = Describe("MOFED state test", func() {
))
})
})

DescribeTable("mergeWithDefaultEnvs",
func(osName string, osVer string, currEnvs []v1.EnvVar, expectedEnvs []v1.EnvVar) {
nodeAttr := make(map[nodeinfo.AttributeType]string)
nodeAttr[nodeinfo.AttrTypeOSName] = osName
nodeAttr[nodeinfo.AttrTypeOSVer] = osVer

mergedEnvs := stateOfed.mergeWithDefaultEnvs(currEnvs, nodeAttr)
Expect(mergedEnvs).To(BeEquivalentTo(expectedEnvs))
},
Entry("RHEL 8.6", "rhel", "8.6", []v1.EnvVar{{Name: "Foo", Value: "Bar"}},
[]v1.EnvVar{{Name: "Foo", Value: "Bar"}, {Name: "CREATE_IFNAMES_UDEV", Value: "true"}}),
Entry("RHEL 9.0", "rhel", "9.0", []v1.EnvVar{{Name: "Foo", Value: "Bar"}},
[]v1.EnvVar{{Name: "Foo", Value: "Bar"}}),
Entry("RHEL 9.2", "rhel", "9.2", []v1.EnvVar{}, []v1.EnvVar{}),
Entry("RHEL 10.0", "rhel", "10.0", []v1.EnvVar{}, []v1.EnvVar{}),
Entry("OCP 4.10", "rhcos", "4.10", []v1.EnvVar{}, []v1.EnvVar{{Name: "CREATE_IFNAMES_UDEV", Value: "true"}}),
Entry("OCP 4.11", "rhcos", "4.11", []v1.EnvVar{}, []v1.EnvVar{{Name: "CREATE_IFNAMES_UDEV", Value: "true"}}),
Entry("OCP 4.12", "rhcos", "4.12", []v1.EnvVar{{Name: "Foo", Value: "Bar"}},
[]v1.EnvVar{{Name: "Foo", Value: "Bar"}, {Name: "CREATE_IFNAMES_UDEV", Value: "true"}}),
Entry("OCP 4.13", "rhcos", "4.13", []v1.EnvVar{{Name: "Foo", Value: "Bar"}},
[]v1.EnvVar{{Name: "Foo", Value: "Bar"}}),
Entry("OCP 4.14", "rhcos", "4.13", []v1.EnvVar{}, []v1.EnvVar{}),
Entry("OCP 5.0", "rhcos", "5.0", []v1.EnvVar{}, []v1.EnvVar{}),
Entry("Ubuntu 20.04", "rhel", "8.6", []v1.EnvVar{{Name: "Foo", Value: "Bar"}},
[]v1.EnvVar{{Name: "Foo", Value: "Bar"}, {Name: "CREATE_IFNAMES_UDEV", Value: "true"}}),
Entry("Ubuntu 22.04", "ubuntu", "22.04", []v1.EnvVar{{Name: "Foo", Value: "Bar"}},
[]v1.EnvVar{{Name: "Foo", Value: "Bar"}}),
Entry("Ubuntu 23.04", "ubuntu", "23.04", []v1.EnvVar{}, []v1.EnvVar{}),
)
})

0 comments on commit c4c1d45

Please sign in to comment.