Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config-daemon: fix NM udev path #369

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,8 @@ func tryCreateSwitchdevUdevRule(nodeState *sriovnetworkv1.SriovNetworkNodeState)

func tryCreateNMUdevRule() error {
glog.V(2).Infof("tryCreateNMUdevRule()")
dirPath := path.Join(filesystemRoot, "/host/etc/udev/rules.d/")
filePath := dirPath + "10-nm-unmanaged.rules"
dirPath := path.Join(filesystemRoot, "/host/etc/udev/rules.d")
filePath := path.Join(dirPath, "10-nm-unmanaged.rules")

newContent := fmt.Sprintf("ACTION==\"add|change|move\", ATTRS{device}==\"%s\", ENV{NM_UNMANAGED}=\"1\"\n", strings.Join(sriovnetworkv1.GetSupportedVfIds(), "|"))

Expand Down
28 changes: 27 additions & 1 deletion pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package daemon
import (
"context"
"flag"
"io/ioutil"
"path"
"testing"

sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
Expand All @@ -27,7 +29,10 @@ var FakeSupportedNicIDs corev1.ConfigMap = corev1.ConfigMap{
Name: sriovnetworkv1.SupportedNicIDConfigmap,
Namespace: namespace,
},
Data: map[string]string{},
Data: map[string]string{
"Intel_i40e_XXV710": "8086 158a 154c",
"Nvidia_mlx5_ConnectX-4": "15b3 1013 1014",
},
}

var SriovDevicePluginPod corev1.Pod = corev1.Pod{
Expand Down Expand Up @@ -97,6 +102,9 @@ var _ = Describe("Config Daemon", func() {
client := fakesnclientset.NewSimpleClientset()
mcClient := fakemcclientset.NewSimpleClientset()

err = sriovnetworkv1.InitNicIDMap(kubeClient, namespace)
Expect(err).ToNot(HaveOccurred())

sut = New("test-node",
client,
kubeClient,
Expand Down Expand Up @@ -225,6 +233,17 @@ var _ = Describe("Config Daemon", func() {

Expect(sut.nodeState.GetGeneration()).To(BeNumerically("==", 777))
})

It("configure udev rules on host", func() {

networkManagerUdevRulePath := path.Join(filesystemRoot, "host/etc/udev/rules.d/10-nm-unmanaged.rules")

expectedContents := `ACTION=="add|change|move", ATTRS{device}=="0x1014|0x154c", ENV{NM_UNMANAGED}="1"
SUBSYSTEM=="net", ACTION=="add|move", ATTRS{phys_switch_id}!="", ATTR{phys_port_name}=="pf*vf*", ENV{NM_UNMANAGED}="1"
`
// No need to trigger any action on config-daemon, as it checks the file in the main loop
assertFileContents(networkManagerUdevRulePath, expectedContents)
})
})
})

Expand All @@ -241,3 +260,10 @@ func updateSriovNetworkNodeState(c snclientset.Interface, nodeState *sriovnetwor
Update(context.Background(), nodeState, metav1.UpdateOptions{})
return err
}

func assertFileContents(path, contents string) {
Eventually(func() (string, error) {
ret, err := ioutil.ReadFile(path)
return string(ret), err
}, "10s").WithOffset(1).Should(Equal(contents))
}