Skip to content

Commit

Permalink
Support changing Eswitch mode of SR-IOV NICs for kubernetes deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Mamduh Alassi <[email protected]>
  • Loading branch information
Mmduh-483 committed Feb 4, 2021
1 parent 9d14395 commit 5c07954
Show file tree
Hide file tree
Showing 19 changed files with 719 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ _build-%:
_plugin-%: vet
@hack/build-plugins.sh $*

plugins: _plugin-intel _plugin-mellanox _plugin-generic _plugin-virtual _plugin-mco
plugins: _plugin-intel _plugin-mellanox _plugin-generic _plugin-virtual _plugin-mco _plugin-k8s

clean:
@rm -rf $(TARGET_DIR)
Expand Down
4 changes: 4 additions & 0 deletions bindata/manifests/daemon/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ spec:
volumeMounts:
- name: host
mountPath: /host
lifecycle:
preStop:
exec:
command: ["/bindata/scripts/clean-k8s-services.sh"]
volumes:
- name: host
hostPath:
Expand Down
30 changes: 30 additions & 0 deletions bindata/scripts/clean-k8s-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

chroot_path="/host"

function clean_services() {
# Remove switchdev service files
rm -f $chroot_path/etc/systemd/system/switchdev-configuration.service
rm -f $chroot_path/usr/local/bin/configure-switchdev.sh
rm -f $chroot_path/etc/switchdev.conf

# clean NetworkManager and ovs-vswitchd services
network_manager_service=$chroot_path/usr/lib/systemd/system/NetworkManager.service
ovs_service=$chroot_path/usr/lib/systemd/system/ovs-vswitchd.service

if [ -f $network_manager_service ]; then
sed -i.bak '/switchdev-configuration.service/d' $network_manager_service
fi

if [ -f $ovs_service ]; then
sed -i.bak '/hw-offload/d' $ovs_service
fi
}

clean_services
# Reload host services
chroot $chroot_path /bin/bash -c systemctl daemon-reload >/dev/null 2>&1 || true

# Restart system services
chroot $chroot_path /bin/bash -c systemctl restart NetworkManager.service >/dev/null 2>&1 || true
chroot $chroot_path /bin/bash -c systemctl restart ovs-vswitchd.service >/dev/null 2>&1 || true
4 changes: 2 additions & 2 deletions controllers/sriovoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,11 @@ func (r *SriovOperatorConfigReconciler) syncOffloadMachineConfig(dc *sriovnetwor
data.Data["HwOffloadNodeLabel"] = HwOffloadNodeLabel
mcName := "00-" + HwOffloadNodeLabel
mcpName := HwOffloadNodeLabel
mc, err := render.GenerateMachineConfig("bindata/manifests/machine-config", mcName, HwOffloadNodeLabel, dc.Spec.EnableOvsOffload, &data)
mc, err := render.GenerateMachineConfig("bindata/manifests/switchdev-config", mcName, HwOffloadNodeLabel, dc.Spec.EnableOvsOffload, &data)
if err != nil {
return err
}
mcpRaw, err := render.RenderTemplate("bindata/manifests/machine-config/machineconfigpool.yaml", &data)
mcpRaw, err := render.RenderTemplate("bindata/manifests/switchdev-config/machineconfigpool.yaml", &data)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/blang/semver v3.5.0+incompatible
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-systemd/v22 v22.0.0
github.com/fsnotify/fsnotify v1.4.9
github.com/go-logr/logr v0.2.1
github.com/go-logr/zapr v0.2.0 // indirect
Expand All @@ -29,6 +30,7 @@ require (
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
google.golang.org/genproto v0.0.0-20200610104632-a5b850bcf112 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.19.0
k8s.io/apimachinery v0.19.0
k8s.io/client-go v0.19.0
Expand Down
2 changes: 2 additions & 0 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ func (dn *Daemon) loadVendorPlugins(ns *sriovnetworkv1.SriovNetworkNodeState) er
pl = registerPlugins(ns)
if utils.ClusterType == utils.ClusterTypeOpenshift {
pl = append(pl, McoPlugin)
} else {
pl = append(pl, K8sPlugin)
}
pl = append(pl, GenericPlugin)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/daemon/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
GenericPlugin = "generic_plugin"
VirtualPlugin = "virtual_plugin"
McoPlugin = "mco_plugin"
K8sPlugin = "k8s_plugin"
)

// loadPlugin loads a single plugin from a file path
Expand Down
Loading

0 comments on commit 5c07954

Please sign in to comment.