Skip to content

Commit 5ab8f47

Browse files
committed
Make kargs.sh work with systemd service and for Ubuntu
1 parent 9ddf872 commit 5ab8f47

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

bindata/manifests/daemon/daemonset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ spec:
116116
command:
117117
- /bin/bash
118118
- -c
119-
- mkdir -p /host/var/lib/sriov/ && cp /usr/bin/sriov-network-config-daemon /host/var/lib/sriov/sriov-network-config-daemon && 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
119+
- mkdir -p /host/var/lib/sriov/ && cp /usr/bin/sriov-network-config-daemon /host/var/lib/sriov/sriov-network-config-daemon && chcon -t bin_t /host/var/lib/sriov/sriov-network-config-daemon | true && cp /bindata/scripts/kargs.sh /host/usr/bin/kargs.sh && chcon -t bin_t /host/usr/bin/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
120120
securityContext:
121121
privileged: true
122122
resources:

bindata/scripts/kargs.sh

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,81 @@ command=$1
55
shift
66
declare -a kargs=( "$@" )
77
ret=0
8-
args=$(chroot /host/ cat /proc/cmdline)
98

10-
IS_OS_UBUNTU=true; [[ "$(chroot /host/ grep -i ubuntu /etc/os-release -c)" == "0" ]] && IS_OS_UBUNTU=false
9+
if [[ -d "/bindata/scripts" ]];then
10+
chroot_path="/host/"
11+
else
12+
chroot_path="/"
13+
fi
14+
15+
args=$(chroot "$chroot_path" cat /proc/cmdline)
16+
17+
IS_OS_UBUNTU=true; [[ "$(chroot "$chroot_path" grep -i ubuntu /etc/os-release -c)" == "0" ]] && IS_OS_UBUNTU=false
1118

1219
# Kernel args configuration isn't supported for Ubuntu now, so we shouldn't do anything here
1320
if ${IS_OS_UBUNTU} ; then
21+
grab_config="/etc/default/grub"
22+
grub_cmdline=$(chroot "$chroot_path" grep GRUB_CMDLINE_LINUX_DEFAULT $grab_config | awk -F'=' '{gsub(/"/, "", $2); print $2}')
23+
24+
for t in "${kargs[@]}";do
25+
if [[ $command == "add" ]];then
26+
if [[ $args != *${t}* ]];then
27+
grub_cmdline="$grub_cmdline $t"
28+
let ret++
29+
fi
30+
fi
31+
if [[ $command == "remove" ]];then
32+
if [[ $grub_cmdline == *${t}* ]];then
33+
grub_cmdline=$(echo $grub_cmdline | sed "s/\b$t\b//g" | sed 's/ */ /g')
34+
let ret++
35+
fi
36+
fi
37+
done
38+
39+
sed -i "/LICENSE_SN_FILE = \"sn\"/c\LICENSE_SN_FILE = '$@'" $grab_config
40+
1441
echo $ret
1542
exit 0
1643
fi
1744

18-
if chroot /host/ test -f /run/ostree-booted ; then
45+
if chroot "$chroot_path" test -f /run/ostree-booted ; then
1946
for t in "${kargs[@]}";do
2047
if [[ $command == "add" ]];then
2148
if [[ $args != *${t}* ]];then
22-
if chroot /host/ rpm-ostree kargs | grep -vq ${t}; then
23-
chroot /host/ rpm-ostree kargs --append ${t} > /dev/null 2>&1
49+
if chroot "$chroot_path" rpm-ostree kargs | grep -vq ${t}; then
50+
chroot "$chroot_path" rpm-ostree kargs --append ${t} > /dev/null 2>&1
2451
fi
2552
let ret++
2653
fi
2754
fi
2855
if [[ $command == "remove" ]];then
2956
if [[ $args == *${t}* ]];then
30-
if chroot /host/ rpm-ostree kargs | grep -q ${t}; then
31-
chroot /host/ rpm-ostree kargs --delete ${t} > /dev/null 2>&1
57+
if chroot "$chroot_path" rpm-ostree kargs | grep -q ${t}; then
58+
chroot "$chroot_path" rpm-ostree kargs --delete ${t} > /dev/null 2>&1
3259
fi
3360
let ret++
3461
fi
3562
fi
3663
done
3764
else
38-
chroot /host/ which grubby > /dev/null 2>&1
65+
chroot "$chroot_path" which grubby > /dev/null 2>&1
3966
# if grubby is not there, let's tell it
4067
if [ $? -ne 0 ]; then
4168
exit 127
4269
fi
4370
for t in "${kargs[@]}";do
4471
if [[ $command == "add" ]];then
4572
if [[ $args != *${t}* ]];then
46-
if chroot /host/ grubby --info=DEFAULT | grep args | grep -vq ${t}; then
47-
chroot /host/ grubby --update-kernel=DEFAULT --args=${t} > /dev/null 2>&1
73+
if chroot "$chroot_path" grubby --info=DEFAULT | grep args | grep -vq ${t}; then
74+
chroot "$chroot_path" grubby --update-kernel=DEFAULT --args=${t} > /dev/null 2>&1
4875
fi
4976
let ret++
5077
fi
5178
fi
5279
if [[ $command == "remove" ]];then
5380
if [[ $args == *${t}* ]];then
54-
if chroot /host/ grubby --info=DEFAULT | grep args | grep -q ${t}; then
55-
chroot /host/ grubby --update-kernel=DEFAULT --remove-args=${t} > /dev/null 2>&1
81+
if chroot "$chroot_path" grubby --info=DEFAULT | grep args | grep -q ${t}; then
82+
chroot "$chroot_path" grubby --update-kernel=DEFAULT --remove-args=${t} > /dev/null 2>&1
5683
fi
5784
let ret++
5885
fi

pkg/plugins/generic/generic_plugin.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ type genericPluginOptions struct {
8181
skipBridgeConfiguration bool
8282
}
8383

84-
const scriptsPath = "bindata/scripts/kargs.sh"
84+
const daemonScriptsPath = "bindata/scripts/kargs.sh"
85+
const systemdScriptsPath = "/usr/bin/kargs.sh"
8586

8687
// Initialize our plugin and set up initial values
8788
func NewGenericPlugin(helpers helper.HostHelpersInterface, options ...Option) (plugin.VendorPlugin, error) {
@@ -277,7 +278,11 @@ func needDriverCheckVdpaType(state *sriovnetworkv1.SriovNetworkNodeState, driver
277278
// editKernelArg Tries to add the kernel args via ostree or grubby.
278279
func editKernelArg(helper helper.HostHelpersInterface, mode, karg string) error {
279280
log.Log.Info("generic plugin editKernelArg()", "mode", mode, "karg", karg)
280-
_, _, err := helper.RunCommand("/bin/sh", scriptsPath, mode, karg)
281+
script := daemonScriptsPath
282+
if vars.UsingSystemdMode {
283+
script = systemdScriptsPath
284+
}
285+
_, _, err := helper.RunCommand("/bin/sh", script, mode, karg)
281286
if err != nil {
282287
// if grubby is not there log and assume kernel args are set correctly.
283288
if utils.IsCommandNotFound(err) {

0 commit comments

Comments
 (0)