Skip to content

Commit f9ef68a

Browse files
committed
Make kargs.sh work with systemd service and for Ubuntu
Signed-off-by: Ivan Kolodiazhnyi <[email protected]>
1 parent b416aa4 commit f9ef68a

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

bindata/manifests/daemon/daemonset.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ spec:
125125
mkdir -p /host/var/lib/sriov/
126126
cp /usr/bin/sriov-network-config-daemon /host/var/lib/sriov/sriov-network-config-daemon
127127
chcon -t bin_t /host/var/lib/sriov/sriov-network-config-daemon || true # Allow systemd to run the file, use pipe true to not failed if the system doesn't have selinux or apparmor enabled
128+
cp /bindata/scripts/kargs.sh /host/var/lib/sriov/kargs.sh
129+
chcon -t bin_t /host/var/lib/sriov/kargs.sh || true # Allow systemd to run the file, use pipe true to not failed if the system doesn't have selinux or apparmor enabled
128130
securityContext:
129131
privileged: true
130132
resources:

bindata/scripts/kargs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ else
6060
done
6161
fi
6262

63-
echo $ret
63+
echo $ret

pkg/daemon/daemon_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var (
4747
)
4848

4949
const (
50-
waitTime = 30 * time.Minute
50+
waitTime = 2 * time.Minute
5151
retryTime = 5 * time.Second
5252
)
5353

@@ -112,6 +112,7 @@ var _ = Describe("Daemon Controller", Ordered, func() {
112112
// general
113113
hostHelper.EXPECT().Chroot(gomock.Any()).Return(func() error { return nil }, nil).AnyTimes()
114114
hostHelper.EXPECT().RunCommand("/bin/sh", gomock.Any(), gomock.Any(), gomock.Any()).Return("", "", nil).AnyTimes()
115+
hostHelper.EXPECT().RunCommand("/bin/bash", gomock.Any(), gomock.Any(), gomock.Any()).Return("", "", nil).AnyTimes()
115116

116117
})
117118

pkg/plugins/generic/generic_plugin.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package generic
33
import (
44
"errors"
55
"fmt"
6+
"os"
67
"syscall"
78

89
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -80,7 +81,8 @@ type genericPluginOptions struct {
8081
skipBridgeConfiguration bool
8182
}
8283

83-
const scriptsPath = "bindata/scripts/kargs.sh"
84+
const daemonScriptsPath = "/bindata/scripts/kargs.sh"
85+
const systemdScriptsPath = "/var/lib/sriov/kargs.sh"
8486

8587
// Initialize our plugin and set up initial values
8688
func NewGenericPlugin(helpers helper.HostHelpersInterface, options ...Option) (plugin.VendorPlugin, error) {
@@ -269,7 +271,11 @@ func needDriverCheckVdpaType(state *sriovnetworkv1.SriovNetworkNodeState, driver
269271
// editKernelArg Tries to add the kernel args via ostree or grubby.
270272
func editKernelArg(helper helper.HostHelpersInterface, mode, karg string) error {
271273
log.Log.Info("generic plugin editKernelArg()", "mode", mode, "karg", karg)
272-
_, _, err := helper.RunCommand("/bin/sh", scriptsPath, mode, karg)
274+
script := daemonScriptsPath
275+
if _, err := os.Stat(consts.Host); errors.Is(err, os.ErrNotExist) {
276+
script = systemdScriptsPath
277+
}
278+
_, _, err := helper.RunCommand("/bin/bash", script, mode, karg)
273279
if err != nil {
274280
// if grubby is not there log and assume kernel args are set correctly.
275281
if utils.IsCommandNotFound(err) {

0 commit comments

Comments
 (0)