Skip to content

Commit 64f16c3

Browse files
authored
Merge pull request #109 from rollandf/updates-26.1.x
Cherry-pick downstream PRs into 26.1.x
2 parents dc3f591 + fa75e49 commit 64f16c3

File tree

13 files changed

+86
-44
lines changed

13 files changed

+86
-44
lines changed

bindata/manifests/daemon/daemonset.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ spec:
141141
mkdir -p /host/var/lib/sriov/
142142
cp /usr/bin/sriov-network-config-daemon /host/var/lib/sriov/sriov-network-config-daemon
143143
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
144+
cp /bindata/scripts/kargs.sh /host/var/lib/sriov/kargs.sh
145+
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
144146
securityContext:
145147
privileged: true
146148
resources:

bindata/scripts/kargs.sh

100755100644
Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@ command=$1
2121
shift
2222
declare -a kargs=( "$@" )
2323
ret=0
24-
args=$(chroot /host/ cat /proc/cmdline)
2524

26-
IS_OS_UBUNTU=true; [[ "$(chroot /host/ grep -i ubuntu /etc/os-release -c)" == "0" ]] && IS_OS_UBUNTU=false
25+
if [[ -d "/bindata/scripts" ]];then
26+
chroot_path="/host/"
27+
else
28+
chroot_path="/"
29+
fi
30+
31+
args=$(chroot "$chroot_path" cat /proc/cmdline)
32+
33+
IS_OS_UBUNTU=true; [[ "$(chroot "$chroot_path" grep -i ubuntu /etc/os-release -c)" == "0" ]] && IS_OS_UBUNTU=false
2734

2835
if ${IS_OS_UBUNTU} ; then
2936
grub_config="/etc/default/grub"
3037
# Operate on the copy of the file
31-
cp /host/${grub_config} /tmp/grub
38+
cp ${chroot_path}/${grub_config} /tmp/grub
3239

3340
for t in "${kargs[@]}";do
3441
if [[ $command == "add" ]];then
@@ -51,8 +58,8 @@ if ${IS_OS_UBUNTU} ; then
5158

5259
if [ $found == false ];then
5360
# Append to the end of the line
54-
t="${arr[@]} ${t}"
55-
sed -i "s/\(^\s*GRUB_CMDLINE_LINUX_DEFAULT=\"\)\(.*\)\"/\1${t}\"/" /tmp/grub
61+
new_param="${arr[@]} ${t}"
62+
sed -i "s/\(^\s*$g\"\)\(.*\)\"/\1${new_param}\"/" /tmp/grub
5663
let ret++
5764
fi
5865
fi
@@ -64,7 +71,6 @@ if ${IS_OS_UBUNTU} ; then
6471
while read line;do
6572
if [[ "$line" =~ GRUB_CMDLINE_LINUX ]];then
6673
IFS='"' read g param q <<< "$line"
67-
6874
arr=($param)
6975
new_param=""
7076

@@ -82,52 +88,52 @@ if ${IS_OS_UBUNTU} ; then
8288

8389
if [ $ret -ne 0 ];then
8490
# Update grub only if there were changes
85-
cp /tmp/grub /host/${grub_config}
86-
chroot "/host" update-grub
91+
cp /tmp/grub ${chroot_path}/${grub_config}
92+
chroot "$chroot_path" update-grub
8793
fi
8894

8995
echo $ret
9096
exit 0
9197
fi
9298

93-
if chroot /host/ test -f /run/ostree-booted ; then
99+
if chroot "$chroot_path" test -f /run/ostree-booted ; then
94100
for t in "${kargs[@]}";do
95101
if [[ $command == "add" ]];then
96102
if [[ $args != *${t}* ]];then
97-
if chroot /host/ rpm-ostree kargs | grep -vq ${t}; then
98-
chroot /host/ rpm-ostree kargs --append ${t} > /dev/null 2>&1
103+
if chroot "$chroot_path" rpm-ostree kargs | grep -vq ${t}; then
104+
chroot "$chroot_path" rpm-ostree kargs --append ${t} > /dev/null 2>&1
99105
fi
100106
let ret++
101107
fi
102108
fi
103109
if [[ $command == "remove" ]];then
104110
if [[ $args == *${t}* ]];then
105-
if chroot /host/ rpm-ostree kargs | grep -q ${t}; then
106-
chroot /host/ rpm-ostree kargs --delete ${t} > /dev/null 2>&1
111+
if chroot "$chroot_path" rpm-ostree kargs | grep -q ${t}; then
112+
chroot "$chroot_path" rpm-ostree kargs --delete ${t} > /dev/null 2>&1
107113
fi
108114
let ret++
109115
fi
110116
fi
111117
done
112118
else
113-
chroot /host/ which grubby > /dev/null 2>&1
119+
chroot "$chroot_path" which grubby > /dev/null 2>&1
114120
# if grubby is not there, let's tell it
115121
if [ $? -ne 0 ]; then
116122
exit 127
117123
fi
118124
for t in "${kargs[@]}";do
119125
if [[ $command == "add" ]];then
120126
if [[ $args != *${t}* ]];then
121-
if chroot /host/ grubby --info=DEFAULT | grep args | grep -vq ${t}; then
122-
chroot /host/ grubby --update-kernel=DEFAULT --args=${t} > /dev/null 2>&1
127+
if chroot "$chroot_path" grubby --info=DEFAULT | grep args | grep -vq ${t}; then
128+
chroot "$chroot_path" grubby --update-kernel=DEFAULT --args=${t} > /dev/null 2>&1
123129
fi
124130
let ret++
125131
fi
126132
fi
127133
if [[ $command == "remove" ]];then
128134
if [[ $args == *${t}* ]];then
129-
if chroot /host/ grubby --info=DEFAULT | grep args | grep -q ${t}; then
130-
chroot /host/ grubby --update-kernel=DEFAULT --remove-args=${t} > /dev/null 2>&1
135+
if chroot "$chroot_path" grubby --info=DEFAULT | grep args | grep -q ${t}; then
136+
chroot "$chroot_path" grubby --update-kernel=DEFAULT --remove-args=${t} > /dev/null 2>&1
131137
fi
132138
let ret++
133139
fi

deployment/sriov-network-operator-chart/templates/operator.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ spec:
5050
requests:
5151
cpu: 100m
5252
memory: 100Mi
53+
securityContext:
54+
capabilities:
55+
drop:
56+
- ALL
57+
runAsNonRoot: true
58+
allowPrivilegeEscalation: false
59+
seccompProfile:
60+
type: RuntimeDefault
5361
env:
5462
- name: WATCH_NAMESPACE
5563
valueFrom:

deployment/sriov-network-operator-chart/templates/pre-delete-webooks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ spec:
2323
containers:
2424
- name: cleanup
2525
image: {{ .Values.images.operator }}
26+
securityContext:
27+
capabilities:
28+
drop:
29+
- ALL
30+
runAsNonRoot: true
31+
allowPrivilegeEscalation: false
32+
seccompProfile:
33+
type: RuntimeDefault
2634
command:
2735
- sriov-network-operator-config-cleanup
2836
args:

pkg/daemon/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ func (dn *NodeReconciler) checkSystemdStatus() (*hosttypes.SriovResult, bool, er
341341

342342
// check if the service exist
343343
if serviceEnabled && postNetworkServiceEnabled {
344-
exist = true
345344
sriovResult, err = dn.hostHelpers.ReadSriovResult()
346345
if err != nil {
347346
funcLog.Error(err, "failed to load sriov result file from host")
348347
return nil, false, err
349348
}
349+
exist = sriovResult != nil
350350
}
351351
return sriovResult, exist, nil
352352
}

pkg/daemon/daemon_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var (
6868
)
6969

7070
const (
71-
waitTime = 30 * time.Minute
71+
waitTime = 2 * time.Minute
7272
retryTime = 5 * time.Second
7373
nodeName = "node1"
7474
)
@@ -137,6 +137,7 @@ var _ = Describe("Daemon Controller", Ordered, func() {
137137
// general
138138
hostHelper.EXPECT().Chroot(gomock.Any()).Return(func() error { return nil }, nil).AnyTimes()
139139
hostHelper.EXPECT().RunCommand("/bin/sh", gomock.Any(), gomock.Any(), gomock.Any()).Return("", "", nil).AnyTimes()
140+
hostHelper.EXPECT().RunCommand("/bin/bash", gomock.Any(), gomock.Any(), gomock.Any()).Return("", "", nil).AnyTimes()
140141

141142
discoverSriovReturn.Store(&[]sriovnetworkv1.InterfaceExt{})
142143

pkg/daemon/plugin_test.go

Whitespace-only changes.

pkg/host/internal/network/network.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ func (n *network) DiscoverRDMASubsystem() (string, error) {
458458
func (n *network) SetRDMASubsystem(mode string) error {
459459
log.Log.Info("SetRDMASubsystem(): Updating RDMA subsystem mode", "mode", mode)
460460
path := filepath.Join(vars.FilesystemRoot, consts.Host, "etc", "modprobe.d", "sriov_network_operator_modules_config.conf")
461+
if _, err := os.Stat(filepath.Join(vars.FilesystemRoot, consts.Host)); errors.Is(err, os.ErrNotExist) {
462+
path = filepath.Join(vars.FilesystemRoot, "/etc", "modprobe.d", "sriov_network_operator_modules_config.conf")
463+
}
461464

462465
if mode == "" {
463466
err := os.Remove(path)

pkg/platforms/openshift/openshift_test.go

Whitespace-only changes.

pkg/platforms/platforms.go

Whitespace-only changes.

0 commit comments

Comments
 (0)