diff --git a/bindata/manifests/switchdev-config/files/switchdev-configuration-after-nm.sh.yaml b/bindata/manifests/switchdev-config/files/switchdev-configuration-after-nm.sh.yaml deleted file mode 100644 index 00a4019b4..000000000 --- a/bindata/manifests/switchdev-config/files/switchdev-configuration-after-nm.sh.yaml +++ /dev/null @@ -1,76 +0,0 @@ -mode: 0755 -overwrite: true -path: "/usr/local/bin/switchdev-configuration-after-nm.sh" -contents: - inline: | - #!/bin/bash - set -eux - input="/etc/sriov-operator/sriov_config.json" - - minId=-1 - maxId=-1 - - extract_min_max_ids() { - range=$(jq -c '.vfRange' -r <<< $group) - ids=(${range//-/ }) - length=${#ids[@]} - minId=-1 - maxId=-1 - if [[ length -eq 2 ]]; then - minId=${ids[0]} - maxId=${ids[1]} - elif [[ length -eq 1 ]]; then - minId=${ids[0]} - maxId=$minId - fi - } - - if [ ! -f $input ]; then - echo "File /etc/sriov-operator/sriov_config.json not exist." - exit - fi - - # Required for NetworkManager configuration(e.g. bond) to settle down - sleep 3 - - jq -c '.interfaces[]' $input | while read iface; - do - eswitch_mode=$(echo $iface | jq '.eSwitchMode' -r) - if [[ "$eswitch_mode" == "switchdev" ]]; then - pci_addr=$(echo $iface | jq '.pciAddress' -r) - name=$(echo $iface | jq '.name' -r) - - echo "load VF driver for $pci_addr" - VfDirs=$(ls /sys/bus/pci/devices/${pci_addr} | grep virtfn) - - # load VF driver and configure vdpa if needed - for VfDir in $VfDirs - do - VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )") - echo $VfPciAddr > /sys/bus/pci/drivers_probe - - # extract VF id from a path like '/sys/bus/pci/devices/0000:65:00.0/virtfn1' - # the VF id is the 7th character after 'virtfn' - vfid=${VfDir:6} - - # check if vfid in VF group range - jq -c '.vfGroups[]' <<< "$iface" | while read group; - do - extract_min_max_ids - vdpaType=$(jq -c '.vdpaType' -r <<< $group) - if [ $vfid -le $maxId ] && [ $vfid -ge $minId ] && ([ $vdpaType == "virtio" ] || [ $vdpaType == "vhost" ]); then - vdpa_name=vdpa:${VfPciAddr} - vdpa_cmd="vdpa dev add name "${vdpa_name}" mgmtdev pci/"${VfPciAddr}" max_vqp 32" - eval $vdpa_cmd - # set the driver_override. When the specified driver will be loaded in the kernel - # it will be automatically bound to the vdpa device - driver_override=virtio_vdpa - if [ $vdpaType == "vhost" ]; then - driver_override=vhost_vdpa - fi - echo $driver_override > /sys/bus/vdpa/devices/$vdpa_name/driver_override - fi - done - done - fi - done diff --git a/bindata/manifests/switchdev-config/files/switchdev-configuration-before-nm.sh.yaml b/bindata/manifests/switchdev-config/files/switchdev-configuration-before-nm.sh.yaml deleted file mode 100644 index 6455716f8..000000000 --- a/bindata/manifests/switchdev-config/files/switchdev-configuration-before-nm.sh.yaml +++ /dev/null @@ -1,78 +0,0 @@ -mode: 0755 -overwrite: true -path: "/usr/local/bin/switchdev-configuration-before-nm.sh" -contents: - inline: | - #!/bin/bash - set -eux - input="/etc/sriov-operator/sriov_config.json" - UDEV_RULE_FILE='/etc/udev/rules.d/10-persistent-net.rules' - - if [ ! -f $input ]; then - echo "File /etc/sriov-operator/sriov_config.json not exist." - exit - fi - - which jq - - append_to_file(){ - content="$1" - file_name="$2" - if ! test -f "$file_name" - then - echo "$content" > "$file_name" - else - if ! grep -Fxq "$content" "$file_name" - then - echo "$content" >> "$file_name" - fi - fi - } - - add_udev_rule_for_sriov_pf(){ - pf_pci=$(grep PCI_SLOT_NAME /sys/class/net/$1/device/uevent | cut -d'=' -f2) - udev_data_line="SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", KERNELS==\"$pf_pci\", NAME=\"$1\"" - append_to_file "$udev_data_line" "$UDEV_RULE_FILE" - } - - jq -c '.interfaces[]' ${input} | while read iface;do - num_vfs=$(echo $iface | jq '.numVfs' -r) - pci_addr=$(echo $iface | jq '.pciAddress' -r) - echo "Set $num_vfs VFs on device $pci_addr" - - # create VFs - echo $num_vfs > /sys/bus/pci/devices/${pci_addr}/sriov_numvfs - done - # wait for vfs to be ready - sleep 5 - - jq -c '.interfaces[]' $input | while read iface; - do - eswitch_mode=$(echo $iface | jq '.eSwitchMode' -r) - if [[ "$eswitch_mode" == "switchdev" ]]; then - pci_addr=$(echo $iface | jq '.pciAddress' -r) - name=$(echo $iface | jq '.name' -r) - - # Create udev rule to save PF name - add_udev_rule_for_sriov_pf $name - - echo "Unload VF driver for $pci_addr" - VfDirs=$(ls /sys/bus/pci/devices/${pci_addr} | grep virtfn) - for VfDir in $VfDirs - do - VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )") - echo $VfPciAddr > /sys/bus/pci/drivers/mlx5_core/unbind || true - done - # set flow steering mode before entering switchdev mode - echo "Set flow steering mode to smfs" - devlink dev param set pci/${pci_addr} name flow_steering_mode value smfs cmode runtime - - # set PF to switchdev mode - echo "Set eswitch mode to switchdev" - devlink dev eswitch set pci/${pci_addr} mode switchdev - ip link set ${name} up - - # turn hw-tc-offload on - /usr/sbin/ethtool -K ${name} hw-tc-offload on - fi - done diff --git a/bindata/manifests/switchdev-config/files/switchdev-vf-link-name.sh.yaml b/bindata/manifests/switchdev-config/files/switchdev-vf-link-name.sh.yaml deleted file mode 100644 index 7b0568e51..000000000 --- a/bindata/manifests/switchdev-config/files/switchdev-vf-link-name.sh.yaml +++ /dev/null @@ -1,9 +0,0 @@ -mode: 0755 -overwrite: true -path: "/etc/udev/switchdev-vf-link-name.sh" -contents: - inline: | - #!/bin/bash - set -x - PORT="$1" - echo "NUMBER=${PORT##pf*vf}" diff --git a/bindata/manifests/switchdev-config/machineconfigpool.yaml b/bindata/manifests/switchdev-config/machineconfigpool.yaml deleted file mode 100644 index 23e3a2399..000000000 --- a/bindata/manifests/switchdev-config/machineconfigpool.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -apiVersion: machineconfiguration.openshift.io/v1 -kind: MachineConfigPool -metadata: - name: {{.HwOffloadNodeLabel}} -spec: - machineConfigSelector: - matchExpressions: - - {key: machineconfiguration.openshift.io/role, operator: In, values: [worker,{{.HwOffloadNodeLabel}}]} - nodeSelector: - matchLabels: - node-role.kubernetes.io/{{.HwOffloadNodeLabel}}: "" diff --git a/bindata/manifests/switchdev-config/switchdev-units/NetworkManager.service.yaml b/bindata/manifests/switchdev-config/switchdev-units/NetworkManager.service.yaml deleted file mode 100644 index 4765e88d9..000000000 --- a/bindata/manifests/switchdev-config/switchdev-units/NetworkManager.service.yaml +++ /dev/null @@ -1,9 +0,0 @@ -name: NetworkManager.service -dropins: -- name: 10-switchdev.conf - contents: | - [Unit] - Wants=switchdev-configuration-before-nm.service - Wants=switchdev-configuration-after-nm.service - After=switchdev-configuration-before-nm.service - Before=switchdev-configuration-after-nm.service diff --git a/bindata/manifests/switchdev-config/switchdev-units/switchdev-configuration-after-nm.yaml b/bindata/manifests/switchdev-config/switchdev-units/switchdev-configuration-after-nm.yaml deleted file mode 100644 index 59aba324a..000000000 --- a/bindata/manifests/switchdev-config/switchdev-units/switchdev-configuration-after-nm.yaml +++ /dev/null @@ -1,19 +0,0 @@ -contents: | - [Unit] - Description=Binds SRIOV VFs to switchdev driver - # Removal of this file signals firstboot completion - ConditionPathExists=!/etc/ignition-machine-config-encapsulated.json - # This service is used to rebind SR-IOV netdev driver after switchdev and NetworkManager configurations - Wants=NetworkManager.service - After=NetworkManager.service - - [Service] - Type=oneshot - ExecStart=/usr/local/bin/switchdev-configuration-after-nm.sh - StandardOutput=journal+console - StandardError=journal+console - - [Install] - WantedBy=network-online.target -enabled: true -name: switchdev-configuration-after-nm.service diff --git a/bindata/manifests/switchdev-config/switchdev-units/switchdev-configuration-before-nm.yaml b/bindata/manifests/switchdev-config/switchdev-units/switchdev-configuration-before-nm.yaml deleted file mode 100644 index 7500a5e76..000000000 --- a/bindata/manifests/switchdev-config/switchdev-units/switchdev-configuration-before-nm.yaml +++ /dev/null @@ -1,19 +0,0 @@ -contents: | - [Unit] - Description=Configures SRIOV NIC to switchdev mode - # Removal of this file signals firstboot completion - ConditionPathExists=!/etc/ignition-machine-config-encapsulated.json - # This service is used to move a SRIOV NIC to switchdev mode - Wants=network-pre.target - Before=network-pre.target - - [Service] - Type=oneshot - ExecStart=/usr/local/bin/switchdev-configuration-before-nm.sh - StandardOutput=journal+console - StandardError=journal+console - - [Install] - WantedBy=network-online.target -enabled: true -name: switchdev-configuration-before-nm.service diff --git a/bindata/scripts/clean-k8s-services.sh b/bindata/scripts/clean-k8s-services.sh index 59cbc5fd7..86726b663 100755 --- a/bindata/scripts/clean-k8s-services.sh +++ b/bindata/scripts/clean-k8s-services.sh @@ -7,36 +7,12 @@ fi chroot_path="/host" -function clean_services() { - # Remove switchdev service files - rm -f $chroot_path/etc/systemd/system/switchdev-configuration-after-nm.service - rm -f $chroot_path/etc/systemd/system/switchdev-configuration-before-nm.service - rm -f $chroot_path/usr/local/bin/switchdev-configuration-after-nm.sh - rm -f $chroot_path/usr/local/bin/switchdev-configuration-before-nm.sh - rm -f $chroot_path/etc/switchdev.conf - rm -f $chroot_path/etc/udev/switchdev-vf-link-name.sh - # The following files are no longer created by config daemon - # Remove them in case of leftovers from earlier SR-IOV network operator - rm -f $chroot_path/usr/local/bin/configure-switchdev.sh - rm -f $chroot_path/etc/systemd/system/switchdev-configuration.service - # 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 +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 +if [ -f $ovs_service ]; then + if grep -q hw-offload $ovs_service; then sed -i.bak '/hw-offload/d' $ovs_service + chroot $chroot_path /bin/bash -c systemctl daemon-reload >/dev/null 2>&1 || true 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 +fi diff --git a/pkg/helper/mock/mock_helper.go b/pkg/helper/mock/mock_helper.go index 643c93c82..1ca13545e 100644 --- a/pkg/helper/mock/mock_helper.go +++ b/pkg/helper/mock/mock_helper.go @@ -7,7 +7,6 @@ package mock_helper import ( reflect "reflect" - unit "github.com/coreos/go-systemd/v22/unit" gomock "github.com/golang/mock/gomock" ghw "github.com/jaypipes/ghw" v1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" @@ -786,21 +785,6 @@ func (mr *MockHostHelpersInterfaceMockRecorder) RdmaIsLoaded() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RdmaIsLoaded", reflect.TypeOf((*MockHostHelpersInterface)(nil).RdmaIsLoaded)) } -// ReadScriptManifestFile mocks base method. -func (m *MockHostHelpersInterface) ReadScriptManifestFile(path string) (*types.ScriptManifestFile, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ReadScriptManifestFile", path) - ret0, _ := ret[0].(*types.ScriptManifestFile) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ReadScriptManifestFile indicates an expected call of ReadScriptManifestFile. -func (mr *MockHostHelpersInterfaceMockRecorder) ReadScriptManifestFile(path interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadScriptManifestFile", reflect.TypeOf((*MockHostHelpersInterface)(nil).ReadScriptManifestFile), path) -} - // ReadService mocks base method. func (m *MockHostHelpersInterface) ReadService(servicePath string) (*types.Service, error) { m.ctrl.T.Helper() @@ -874,26 +858,6 @@ func (mr *MockHostHelpersInterfaceMockRecorder) ReloadDriver(driver interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReloadDriver", reflect.TypeOf((*MockHostHelpersInterface)(nil).ReloadDriver), driver) } -// RemoveFromService mocks base method. -func (m *MockHostHelpersInterface) RemoveFromService(service *types.Service, options ...*unit.UnitOption) (*types.Service, error) { - m.ctrl.T.Helper() - varargs := []interface{}{service} - for _, a := range options { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "RemoveFromService", varargs...) - ret0, _ := ret[0].(*types.Service) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// RemoveFromService indicates an expected call of RemoveFromService. -func (mr *MockHostHelpersInterfaceMockRecorder) RemoveFromService(service interface{}, options ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{service}, options...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveFromService", reflect.TypeOf((*MockHostHelpersInterface)(nil).RemoveFromService), varargs...) -} - // RemoveUdevRule mocks base method. func (m *MockHostHelpersInterface) RemoveUdevRule(pfPciAddress string) error { m.ctrl.T.Helper() diff --git a/pkg/host/internal/service/service.go b/pkg/host/internal/service/service.go index 4ecec5b5f..f1574526f 100644 --- a/pkg/host/internal/service/service.go +++ b/pkg/host/internal/service/service.go @@ -102,7 +102,7 @@ func (s *service) EnableService(service *types.Service) error { return err } -// CompareServices compare 2 service and return true if serviceA has all the fields of serviceB +// CompareServices returns true if serviceA needs update(doesn't contain all fields from service B) func (s *service) CompareServices(serviceA, serviceB *types.Service) (bool, error) { optsA, err := unit.Deserialize(strings.NewReader(serviceA.Content)) if err != nil { @@ -127,37 +127,6 @@ OUTER: return false, nil } -// RemoveFromService removes given fields from service -func (s *service) RemoveFromService(service *types.Service, options ...*unit.UnitOption) (*types.Service, error) { - opts, err := unit.Deserialize(strings.NewReader(service.Content)) - if err != nil { - return nil, err - } - - var newServiceOptions []*unit.UnitOption -OUTER: - for _, opt := range opts { - for _, optRemove := range options { - if opt.Match(optRemove) { - continue OUTER - } - } - - newServiceOptions = append(newServiceOptions, opt) - } - - data, err := io.ReadAll(unit.Serialize(newServiceOptions)) - if err != nil { - return nil, err - } - - return &types.Service{ - Name: service.Name, - Path: service.Path, - Content: string(data), - }, nil -} - // ReadServiceInjectionManifestFile reads service injection file func (s *service) ReadServiceInjectionManifestFile(path string) (*types.Service, error) { data, err := os.ReadFile(path) @@ -196,21 +165,6 @@ func (s *service) ReadServiceManifestFile(path string) (*types.Service, error) { }, nil } -// ReadScriptManifestFile reads script file -func (s *service) ReadScriptManifestFile(path string) (*types.ScriptManifestFile, error) { - data, err := os.ReadFile(path) - if err != nil { - return nil, err - } - - var scriptFile *types.ScriptManifestFile - if err := yaml.Unmarshal(data, &scriptFile); err != nil { - return nil, err - } - - return scriptFile, nil -} - func (s *service) UpdateSystemService(serviceObj *types.Service) error { systemService, err := s.ReadService(serviceObj.Path) if err != nil { diff --git a/pkg/host/mock/mock_host.go b/pkg/host/mock/mock_host.go index e3df6a71d..2ccad377e 100644 --- a/pkg/host/mock/mock_host.go +++ b/pkg/host/mock/mock_host.go @@ -7,7 +7,6 @@ package mock_host import ( reflect "reflect" - unit "github.com/coreos/go-systemd/v22/unit" gomock "github.com/golang/mock/gomock" ghw "github.com/jaypipes/ghw" v1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" @@ -664,21 +663,6 @@ func (mr *MockHostManagerInterfaceMockRecorder) RdmaIsLoaded() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RdmaIsLoaded", reflect.TypeOf((*MockHostManagerInterface)(nil).RdmaIsLoaded)) } -// ReadScriptManifestFile mocks base method. -func (m *MockHostManagerInterface) ReadScriptManifestFile(path string) (*types.ScriptManifestFile, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ReadScriptManifestFile", path) - ret0, _ := ret[0].(*types.ScriptManifestFile) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ReadScriptManifestFile indicates an expected call of ReadScriptManifestFile. -func (mr *MockHostManagerInterfaceMockRecorder) ReadScriptManifestFile(path interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadScriptManifestFile", reflect.TypeOf((*MockHostManagerInterface)(nil).ReadScriptManifestFile), path) -} - // ReadService mocks base method. func (m *MockHostManagerInterface) ReadService(servicePath string) (*types.Service, error) { m.ctrl.T.Helper() @@ -752,26 +736,6 @@ func (mr *MockHostManagerInterfaceMockRecorder) ReloadDriver(driver interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReloadDriver", reflect.TypeOf((*MockHostManagerInterface)(nil).ReloadDriver), driver) } -// RemoveFromService mocks base method. -func (m *MockHostManagerInterface) RemoveFromService(service *types.Service, options ...*unit.UnitOption) (*types.Service, error) { - m.ctrl.T.Helper() - varargs := []interface{}{service} - for _, a := range options { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "RemoveFromService", varargs...) - ret0, _ := ret[0].(*types.Service) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// RemoveFromService indicates an expected call of RemoveFromService. -func (mr *MockHostManagerInterfaceMockRecorder) RemoveFromService(service interface{}, options ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{service}, options...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveFromService", reflect.TypeOf((*MockHostManagerInterface)(nil).RemoveFromService), varargs...) -} - // RemoveUdevRule mocks base method. func (m *MockHostManagerInterface) RemoveUdevRule(pfPciAddress string) error { m.ctrl.T.Helper() diff --git a/pkg/host/types/interfaces.go b/pkg/host/types/interfaces.go index 92004fb84..9e8e0d3d6 100644 --- a/pkg/host/types/interfaces.go +++ b/pkg/host/types/interfaces.go @@ -1,7 +1,6 @@ package types import ( - "github.com/coreos/go-systemd/v22/unit" "github.com/jaypipes/ghw" "github.com/vishvananda/netlink" @@ -119,13 +118,9 @@ type ServiceInterface interface { EnableService(service *Service) error // ReadServiceManifestFile reads the systemd manifest for a specific service ReadServiceManifestFile(path string) (*Service, error) - // RemoveFromService removes a systemd service from the host - RemoveFromService(service *Service, options ...*unit.UnitOption) (*Service, error) - // ReadScriptManifestFile reads the script manifest from a systemd service - ReadScriptManifestFile(path string) (*ScriptManifestFile, error) // ReadServiceInjectionManifestFile reads the injection manifest file for the systemd service ReadServiceInjectionManifestFile(path string) (*Service, error) - // CompareServices compare two servers and return true if they are equal + // CompareServices returns true if serviceA needs update(doesn't contain all fields from service B) CompareServices(serviceA, serviceB *Service) (bool, error) // UpdateSystemService updates a system service on the host UpdateSystemService(serviceObj *Service) error diff --git a/pkg/host/types/types.go b/pkg/host/types/types.go index 935a34bfd..248163670 100644 --- a/pkg/host/types/types.go +++ b/pkg/host/types/types.go @@ -1,9 +1,5 @@ package types -import ( - "github.com/coreos/go-systemd/v22/unit" -) - // Service contains info about systemd service type Service struct { Name string @@ -32,12 +28,3 @@ type ScriptManifestFile struct { Inline string } } - -var ( - // Remove run condition form the service - ConditionOpt = &unit.UnitOption{ - Section: "Unit", - Name: "ConditionPathExists", - Value: "!/etc/ignition-machine-config-encapsulated.json", - } -) diff --git a/pkg/plugins/k8s/k8s_plugin.go b/pkg/plugins/k8s/k8s_plugin.go index c5079473e..118073ee5 100644 --- a/pkg/plugins/k8s/k8s_plugin.go +++ b/pkg/plugins/k8s/k8s_plugin.go @@ -1,9 +1,6 @@ package k8s import ( - "fmt" - "os" - "path" "strings" "sigs.k8s.io/controller-runtime/pkg/log" @@ -19,96 +16,80 @@ import ( var PluginName = "k8s" type K8sPlugin struct { - PluginName string - SpecVersion string - switchdevBeforeNMRunScript *hostTypes.ScriptManifestFile - switchdevAfterNMRunScript *hostTypes.ScriptManifestFile - switchdevUdevScript *hostTypes.ScriptManifestFile - switchdevBeforeNMService *hostTypes.Service - switchdevAfterNMService *hostTypes.Service - openVSwitchService *hostTypes.Service - networkManagerService *hostTypes.Service - sriovService *hostTypes.Service - sriovPostNetworkService *hostTypes.Service - updateTarget *k8sUpdateTarget - hostHelper helper.HostHelpersInterface + PluginName string + SpecVersion string + hostHelper helper.HostHelpersInterface + + openVSwitchService *hostTypes.Service + sriovService *hostTypes.Service + sriovPostNetworkService *hostTypes.Service + + updateTarget *k8sUpdateTarget +} +type updateTargetReq struct { + update bool + reboot bool } -type k8sUpdateTarget struct { - switchdevBeforeNMService bool - switchdevAfterNMService bool - switchdevBeforeNMRunScript bool - switchdevAfterNMRunScript bool - switchdevUdevScript bool - sriovScript bool - sriovPostNetworkScript bool - systemServices []*hostTypes.Service +// set need update flag for updateTargetReq +func (u *updateTargetReq) SetNeedUpdate() { + u.update = true } -func (u *k8sUpdateTarget) needUpdate() bool { - return u.switchdevBeforeNMService || - u.switchdevAfterNMService || - u.switchdevBeforeNMRunScript || - u.switchdevAfterNMRunScript || - u.switchdevUdevScript || - u.sriovScript || - u.sriovPostNetworkScript || - len(u.systemServices) > 0 +// set need update and reboot flags for updateTargetReq +func (u *updateTargetReq) SetNeedReboot() { + u.update = true + u.reboot = true } -func (u *k8sUpdateTarget) needReboot() bool { - return u.switchdevBeforeNMService || - u.switchdevAfterNMService || - u.switchdevBeforeNMRunScript || - u.switchdevAfterNMRunScript || - u.switchdevUdevScript || - u.sriovScript || - u.sriovPostNetworkScript +// returns state of the update flag +func (u *updateTargetReq) NeedUpdate() bool { + return u.update } -func (u *k8sUpdateTarget) reset() { - u.switchdevBeforeNMService = false - u.switchdevAfterNMService = false - u.switchdevBeforeNMRunScript = false - u.switchdevAfterNMRunScript = false - u.switchdevUdevScript = false - u.sriovScript = false - u.sriovPostNetworkScript = false - u.systemServices = []*hostTypes.Service{} +// returns state of the reboot flag +func (u *updateTargetReq) NeedReboot() bool { + return u.reboot +} + +type k8sUpdateTarget struct { + sriovScript updateTargetReq + sriovPostNetworkScript updateTargetReq + openVSwitch updateTargetReq } func (u *k8sUpdateTarget) String() string { var updateList []string - if u.switchdevBeforeNMService || u.switchdevAfterNMService { - updateList = append(updateList, "SwitchdevService") + if u.sriovScript.NeedReboot() { + updateList = append(updateList, "sriov-config.service") } - if u.switchdevBeforeNMRunScript || u.switchdevAfterNMRunScript { - updateList = append(updateList, "SwitchdevRunScript") + if u.sriovPostNetworkScript.NeedReboot() { + updateList = append(updateList, "sriov-config-post-network.service") } - if u.switchdevUdevScript { - updateList = append(updateList, "SwitchdevUdevScript") + if u.openVSwitch.NeedReboot() { + updateList = append(updateList, "ovs-vswitchd.service") } - for _, s := range u.systemServices { - updateList = append(updateList, s.Name) - } - return strings.Join(updateList, ",") } +func (u *k8sUpdateTarget) needReboot() bool { + return u.sriovScript.NeedReboot() || u.sriovPostNetworkScript.NeedReboot() || u.openVSwitch.NeedReboot() +} + +func (u *k8sUpdateTarget) reset() { + u.sriovScript = updateTargetReq{} + u.sriovPostNetworkScript = updateTargetReq{} + u.openVSwitch = updateTargetReq{} +} + const ( - bindataManifestPath = "bindata/manifests/" - switchdevManifestPath = bindataManifestPath + "switchdev-config/" - switchdevUnits = switchdevManifestPath + "switchdev-units/" - sriovUnits = bindataManifestPath + "sriov-config-service/kubernetes/" - sriovUnitFile = sriovUnits + "sriov-config-service.yaml" - sriovPostNetworkUnitFile = sriovUnits + "sriov-config-post-network-service.yaml" - switchdevBeforeNMUnitFile = switchdevUnits + "switchdev-configuration-before-nm.yaml" - switchdevAfterNMUnitFile = switchdevUnits + "switchdev-configuration-after-nm.yaml" - networkManagerUnitFile = switchdevUnits + "NetworkManager.service.yaml" - ovsUnitFile = switchdevManifestPath + "ovs-units/ovs-vswitchd.service.yaml" - configuresSwitchdevBeforeNMScript = switchdevManifestPath + "files/switchdev-configuration-before-nm.sh.yaml" - configuresSwitchdevAfterNMScript = switchdevManifestPath + "files/switchdev-configuration-after-nm.sh.yaml" - switchdevRenamingUdevScript = switchdevManifestPath + "files/switchdev-vf-link-name.sh.yaml" + bindataManifestPath = "bindata/manifests/" + switchdevManifestPath = bindataManifestPath + "switchdev-config/" + switchdevUnits = switchdevManifestPath + "switchdev-units/" + sriovUnits = bindataManifestPath + "sriov-config-service/kubernetes/" + sriovUnitFile = sriovUnits + "sriov-config-service.yaml" + sriovPostNetworkUnitFile = sriovUnits + "sriov-config-post-network-service.yaml" + ovsUnitFile = switchdevManifestPath + "ovs-units/ovs-vswitchd.service.yaml" ) // Initialize our plugin and set up initial values @@ -148,7 +129,7 @@ func (p *K8sPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) if sriovnetworkv1.IsSwitchdevModeSpec(new.Spec) { // Check services - err = p.switchDevServicesStateUpdate() + err = p.ovsServiceStateUpdate() if err != nil { log.Log.Error(err, "k8s plugin OnNodeStateChange(): failed") return @@ -164,14 +145,10 @@ func (p *K8sPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) } } - if p.updateTarget.needUpdate() { + if p.updateTarget.needReboot() { needDrain = true - if p.updateTarget.needReboot() { - needReboot = true - log.Log.Info("k8s plugin OnNodeStateChange(): needReboot to update", "target", p.updateTarget) - } else { - log.Log.Info("k8s plugin OnNodeStateChange(): needDrain to update", "target", p.updateTarget) - } + needReboot = true + log.Log.Info("k8s plugin OnNodeStateChange(): needReboot to update", "target", p.updateTarget) } return @@ -180,77 +157,12 @@ func (p *K8sPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) // Apply config change func (p *K8sPlugin) Apply() error { log.Log.Info("k8s plugin Apply()") - if err := p.updateSwitchdevService(); err != nil { - return err - } - if vars.UsingSystemdMode { if err := p.updateSriovServices(); err != nil { return err } } - - for _, systemService := range p.updateTarget.systemServices { - if err := p.hostHelper.UpdateSystemService(systemService); err != nil { - return err - } - } - - return nil -} - -func (p *K8sPlugin) readSwitchdevManifest() error { - // Read switchdev service - switchdevBeforeNMService, err := p.hostHelper.ReadServiceManifestFile(switchdevBeforeNMUnitFile) - if err != nil { - return err - } - switchdevAfterNMService, err := p.hostHelper.ReadServiceManifestFile(switchdevAfterNMUnitFile) - if err != nil { - return err - } - - switchdevBeforeNMService, err = p.hostHelper.RemoveFromService(switchdevBeforeNMService, hostTypes.ConditionOpt) - if err != nil { - return err - } - switchdevAfterNMService, err = p.hostHelper.RemoveFromService(switchdevAfterNMService, hostTypes.ConditionOpt) - if err != nil { - return err - } - p.switchdevBeforeNMService = switchdevBeforeNMService - p.switchdevAfterNMService = switchdevAfterNMService - - // Read switchdev run script - switchdevBeforeNMRunScript, err := p.hostHelper.ReadScriptManifestFile(configuresSwitchdevBeforeNMScript) - if err != nil { - return err - } - switchdevAfterNMRunScript, err := p.hostHelper.ReadScriptManifestFile(configuresSwitchdevAfterNMScript) - if err != nil { - return err - } - p.switchdevBeforeNMRunScript = switchdevBeforeNMRunScript - p.switchdevAfterNMRunScript = switchdevAfterNMRunScript - - // Read switchdev udev script - switchdevUdevScript, err := p.hostHelper.ReadScriptManifestFile(switchdevRenamingUdevScript) - if err != nil { - return err - } - p.switchdevUdevScript = switchdevUdevScript - - return nil -} - -func (p *K8sPlugin) readNetworkManagerManifest() error { - networkManagerService, err := p.hostHelper.ReadServiceInjectionManifestFile(networkManagerUnitFile) - if err != nil { - return err - } - - p.networkManagerService = networkManagerService - return nil + return p.updateOVSService() } func (p *K8sPlugin) readOpenVSwitchdManifest() error { @@ -258,7 +170,6 @@ func (p *K8sPlugin) readOpenVSwitchdManifest() error { if err != nil { return err } - p.openVSwitchService = openVSwitchService return nil } @@ -268,7 +179,6 @@ func (p *K8sPlugin) readSriovServiceManifest() error { if err != nil { return err } - p.sriovService = sriovService return nil } @@ -278,76 +188,27 @@ func (p *K8sPlugin) readSriovPostNetworkServiceManifest() error { if err != nil { return err } - p.sriovPostNetworkService = sriovService return nil } func (p *K8sPlugin) readManifestFiles() error { - if err := p.readSwitchdevManifest(); err != nil { - return err - } - - if err := p.readNetworkManagerManifest(); err != nil { - return err - } - if err := p.readOpenVSwitchdManifest(); err != nil { return err } - if err := p.readSriovServiceManifest(); err != nil { return err } - if err := p.readSriovPostNetworkServiceManifest(); err != nil { return err } - - return nil -} - -func (p *K8sPlugin) switchdevServiceStateUpdate() error { - // Check switchdev service - needUpdate, err := p.isSwitchdevServiceNeedUpdate(p.switchdevBeforeNMService) - if err != nil { - return err - } - p.updateTarget.switchdevBeforeNMService = needUpdate - needUpdate, err = p.isSwitchdevServiceNeedUpdate(p.switchdevAfterNMService) - if err != nil { - return err - } - p.updateTarget.switchdevAfterNMService = needUpdate - - // Check switchdev run script - needUpdate, err = p.isSwitchdevScriptNeedUpdate(p.switchdevBeforeNMRunScript) - if err != nil { - return err - } - p.updateTarget.switchdevBeforeNMRunScript = needUpdate - needUpdate, err = p.isSwitchdevScriptNeedUpdate(p.switchdevAfterNMRunScript) - if err != nil { - return err - } - p.updateTarget.switchdevAfterNMRunScript = needUpdate - - // Check switchdev udev script - needUpdate, err = p.isSwitchdevScriptNeedUpdate(p.switchdevUdevScript) - if err != nil { - return err - } - p.updateTarget.switchdevUdevScript = needUpdate - return nil } func (p *K8sPlugin) sriovServicesStateUpdate() error { - log.Log.Info("sriovServicesStateUpdate()") - for _, s := range []struct { srv *hostTypes.Service - update *bool + update *updateTargetReq }{ {srv: p.sriovService, update: &p.updateTarget.sriovScript}, {srv: p.sriovPostNetworkService, update: &p.updateTarget.sriovPostNetworkScript}, @@ -358,164 +219,101 @@ func (p *K8sPlugin) sriovServicesStateUpdate() error { } // create and enable the service if it doesn't exist or is not enabled if !isServiceEnabled { - *s.update = true + s.update.SetNeedReboot() } else { - *s.update = p.isSystemServiceNeedUpdate(s.srv) - } - if *s.update { - p.updateTarget.systemServices = append(p.updateTarget.systemServices, s.srv) + if p.isSystemDServiceNeedUpdate(s.srv) { + s.update.SetNeedReboot() + } } } - return nil } -func (p *K8sPlugin) getSwitchDevSystemServices() []*hostTypes.Service { - return []*hostTypes.Service{p.networkManagerService, p.openVSwitchService} -} - -func (p *K8sPlugin) isSwitchdevScriptNeedUpdate(scriptObj *hostTypes.ScriptManifestFile) (needUpdate bool, err error) { - data, err := os.ReadFile(path.Join(consts.Host, scriptObj.Path)) - if err != nil { - if !os.IsNotExist(err) { - return false, err +func (p *K8sPlugin) updateSriovServices() error { + for _, s := range []struct { + srv *hostTypes.Service + update *updateTargetReq + }{ + {srv: p.sriovService, update: &p.updateTarget.sriovScript}, + {srv: p.sriovPostNetworkService, update: &p.updateTarget.sriovPostNetworkScript}, + } { + if s.update.NeedUpdate() { + err := p.hostHelper.EnableService(s.srv) + if err != nil { + return err + } } - return true, nil - } else if string(data) != scriptObj.Contents.Inline { - return true, nil } - return false, nil + return nil } -func (p *K8sPlugin) isSwitchdevServiceNeedUpdate(serviceObj *hostTypes.Service) (needUpdate bool, err error) { - swdService, err := p.hostHelper.ReadService(serviceObj.Path) +func (p *K8sPlugin) ovsServiceStateUpdate() error { + exist, err := p.hostHelper.IsServiceExist(p.openVSwitchService.Path) if err != nil { - if !os.IsNotExist(err) { - return false, err - } - // service not exists - return true, nil + return err + } + if !exist { + log.Log.Info("k8s plugin systemServicesStateUpdate(): WARNING! openvswitch system service not found, skip update", + "service", p.openVSwitchService.Name) + return nil + } + if !p.isSystemDServiceNeedUpdate(p.openVSwitchService) { + // service is up to date + return nil + } + if p.isOVSHwOffloadingEnabled() { + p.updateTarget.openVSwitch.SetNeedUpdate() } else { - needChange, err := p.hostHelper.CompareServices(swdService, serviceObj) - if err != nil { - return false, err - } - return needChange, nil + p.updateTarget.openVSwitch.SetNeedReboot() + } + return nil +} + +func (p *K8sPlugin) updateOVSService() error { + if p.updateTarget.openVSwitch.NeedUpdate() { + return p.hostHelper.UpdateSystemService(p.openVSwitchService) } + return nil } -func (p *K8sPlugin) isSystemServiceNeedUpdate(serviceObj *hostTypes.Service) bool { - log.Log.Info("isSystemServiceNeedUpdate()") +func (p *K8sPlugin) isSystemDServiceNeedUpdate(serviceObj *hostTypes.Service) bool { systemService, err := p.hostHelper.ReadService(serviceObj.Path) if err != nil { - log.Log.Error(err, "k8s plugin isSystemServiceNeedUpdate(): failed to read sriov-config service file, ignoring", + log.Log.Error(err, "k8s plugin isSystemDServiceNeedUpdate(): failed to read service file, ignoring", "path", serviceObj.Path) return false } if systemService != nil { needChange, err := p.hostHelper.CompareServices(systemService, serviceObj) if err != nil { - log.Log.Error(err, "k8s plugin isSystemServiceNeedUpdate(): failed to compare sriov-config service, ignoring") + log.Log.Error(err, "k8s plugin isSystemDServiceNeedUpdate(): failed to compare service, ignoring") return false } return needChange } - return false } -func (p *K8sPlugin) systemServicesStateUpdate() error { - var services []*hostTypes.Service - for _, systemService := range p.getSwitchDevSystemServices() { - exist, err := p.hostHelper.IsServiceExist(systemService.Path) - if err != nil { - return err - } - if !exist { - return fmt.Errorf("k8s plugin systemServicesStateUpdate(): %q not found", systemService.Name) - } - if p.isSystemServiceNeedUpdate(systemService) { - services = append(services, systemService) - } - } - - p.updateTarget.systemServices = services - return nil -} - -func (p *K8sPlugin) switchDevServicesStateUpdate() error { - // Check switchdev - err := p.switchdevServiceStateUpdate() +// try to check if OVS HW offloading is already enabled +// required to avoid unneeded reboots in case if HW offloading is already enabled by different entity +// TODO move to the right package and avoid ovs-vsctl binary call +// the function should be revisited when support for software bridge configuration +// is implemented +func (p *K8sPlugin) isOVSHwOffloadingEnabled() bool { + log.Log.V(2).Info("isOVSHwOffloadingEnabled()") + exit, err := p.hostHelper.Chroot(consts.Chroot) if err != nil { - return err + return false } - - // Check system services - err = p.systemServicesStateUpdate() + defer exit() + out, _, err := p.hostHelper.RunCommand("ovs-vsctl", "get", "Open_vSwitch", ".", "other_config:hw-offload") if err != nil { - return err - } - - return nil -} - -func (p *K8sPlugin) updateSriovServices() error { - for _, s := range []struct { - srv *hostTypes.Service - update bool - }{ - {srv: p.sriovService, update: p.updateTarget.sriovScript}, - {srv: p.sriovPostNetworkService, update: p.updateTarget.sriovPostNetworkScript}, - } { - if s.update { - err := p.hostHelper.EnableService(s.srv) - if err != nil { - return err - } - } - } - - return nil -} - -func (p *K8sPlugin) updateSwitchdevService() error { - if p.updateTarget.switchdevBeforeNMService { - err := p.hostHelper.EnableService(p.switchdevBeforeNMService) - if err != nil { - return err - } - } - - if p.updateTarget.switchdevAfterNMService { - err := p.hostHelper.EnableService(p.switchdevAfterNMService) - if err != nil { - return err - } - } - - if p.updateTarget.switchdevBeforeNMRunScript { - err := os.WriteFile(path.Join(consts.Host, p.switchdevBeforeNMRunScript.Path), - []byte(p.switchdevBeforeNMRunScript.Contents.Inline), 0755) - if err != nil { - return err - } - } - - if p.updateTarget.switchdevAfterNMRunScript { - err := os.WriteFile(path.Join(consts.Host, p.switchdevAfterNMRunScript.Path), - []byte(p.switchdevAfterNMRunScript.Contents.Inline), 0755) - if err != nil { - return err - } + log.Log.V(2).Info("isOVSHwOffloadingEnabled() check failed, assume offloading is disabled", "error", err.Error()) + return false } - - if p.updateTarget.switchdevUdevScript { - err := os.WriteFile(path.Join(consts.Host, p.switchdevUdevScript.Path), - []byte(p.switchdevUdevScript.Contents.Inline), 0755) - if err != nil { - return err - } + if strings.Trim(out, "\n") == `"true"` { + log.Log.V(2).Info("isOVSHwOffloadingEnabled() offloading is already enabled") + return true } - - return nil + return false } diff --git a/pkg/plugins/k8s/k8s_plugin_test.go b/pkg/plugins/k8s/k8s_plugin_test.go index c3a64725b..28a2e85c1 100644 --- a/pkg/plugins/k8s/k8s_plugin_test.go +++ b/pkg/plugins/k8s/k8s_plugin_test.go @@ -1,6 +1,7 @@ package k8s import ( + "fmt" "os" "testing" @@ -35,7 +36,7 @@ func registerCall(m *gomock.Call, realF interface{}) *gomock.Call { os.Chdir("../../..") }).DoAndReturn(realF).Do(func(_ ...interface{}) { os.Chdir(cur) - }).AnyTimes() + }) } func setIsSystemdMode(val bool) { @@ -82,28 +83,12 @@ var _ = Describe("K8s plugin", func() { // proxy some functions to real host manager to simplify testing and to additionally validate manifests for _, f := range []string{ - "bindata/manifests/switchdev-config/files/switchdev-configuration-before-nm.sh.yaml", - "bindata/manifests/switchdev-config/files/switchdev-configuration-after-nm.sh.yaml", - "bindata/manifests/switchdev-config/files/switchdev-vf-link-name.sh.yaml", - } { - registerCall(hostHelper.EXPECT().ReadScriptManifestFile(f), realHostMgr.ReadScriptManifestFile) - } - for _, f := range []string{ - "bindata/manifests/switchdev-config/switchdev-units/switchdev-configuration-before-nm.yaml", - "bindata/manifests/switchdev-config/switchdev-units/switchdev-configuration-after-nm.yaml", "bindata/manifests/sriov-config-service/kubernetes/sriov-config-service.yaml", "bindata/manifests/sriov-config-service/kubernetes/sriov-config-post-network-service.yaml", } { registerCall(hostHelper.EXPECT().ReadServiceManifestFile(f), realHostMgr.ReadServiceManifestFile) } for _, s := range []string{ - "switchdev-configuration-before-nm.service", - "switchdev-configuration-after-nm.service", - } { - registerCall(hostHelper.EXPECT().RemoveFromService(newServiceNameMatcher(s), gomock.Any()), realHostMgr.RemoveFromService) - } - for _, s := range []string{ - "bindata/manifests/switchdev-config/switchdev-units/NetworkManager.service.yaml", "bindata/manifests/switchdev-config/ovs-units/ovs-vswitchd.service.yaml", } { registerCall(hostHelper.EXPECT().ReadServiceInjectionManifestFile(s), realHostMgr.ReadServiceInjectionManifestFile) @@ -132,8 +117,6 @@ var _ = Describe("K8s plugin", func() { hostHelper.EXPECT().IsServiceEnabled("/etc/systemd/system/sriov-config-post-network.service").Return(false, nil) hostHelper.EXPECT().EnableService(newServiceNameMatcher("sriov-config.service")).Return(nil) hostHelper.EXPECT().EnableService(newServiceNameMatcher("sriov-config-post-network.service")).Return(nil) - hostHelper.EXPECT().UpdateSystemService(newServiceNameMatcher("sriov-config.service")).Return(nil) - hostHelper.EXPECT().UpdateSystemService(newServiceNameMatcher("sriov-config-post-network.service")).Return(nil) needDrain, needReboot, err := k8sPlugin.OnNodeStateChange(&sriovnetworkv1.SriovNetworkNodeState{}) Expect(err).ToNot(HaveOccurred()) @@ -176,7 +159,6 @@ var _ = Describe("K8s plugin", func() { newServiceNameMatcher("sriov-config.service"), ).Return(true, nil) hostHelper.EXPECT().EnableService(newServiceNameMatcher("sriov-config.service")).Return(nil) - hostHelper.EXPECT().UpdateSystemService(newServiceNameMatcher("sriov-config.service")).Return(nil) hostHelper.EXPECT().IsServiceEnabled("/etc/systemd/system/sriov-config-post-network.service").Return(true, nil) hostHelper.EXPECT().ReadService("/etc/systemd/system/sriov-config-post-network.service").Return( @@ -191,4 +173,51 @@ var _ = Describe("K8s plugin", func() { Expect(needDrain).To(BeTrue()) Expect(k8sPlugin.Apply()).NotTo(HaveOccurred()) }) + It("ovs service not found", func() { + setIsSystemdMode(false) + hostHelper.EXPECT().IsServiceExist("/usr/lib/systemd/system/ovs-vswitchd.service").Return(false, nil) + needDrain, needReboot, err := k8sPlugin.OnNodeStateChange(&sriovnetworkv1.SriovNetworkNodeState{ + Spec: sriovnetworkv1.SriovNetworkNodeStateSpec{Interfaces: []sriovnetworkv1.Interface{{EswitchMode: "switchdev"}}}}) + Expect(err).ToNot(HaveOccurred()) + Expect(needReboot).To(BeFalse()) + Expect(needDrain).To(BeFalse()) + Expect(k8sPlugin.Apply()).NotTo(HaveOccurred()) + }) + It("ovs service updated", func() { + setIsSystemdMode(false) + hostHelper.EXPECT().IsServiceExist("/usr/lib/systemd/system/ovs-vswitchd.service").Return(true, nil) + hostHelper.EXPECT().ReadService("/usr/lib/systemd/system/ovs-vswitchd.service").Return( + &hostTypes.Service{Name: "ovs-vswitchd.service"}, nil) + hostHelper.EXPECT().CompareServices( + &hostTypes.Service{Name: "ovs-vswitchd.service"}, + newServiceNameMatcher("ovs-vswitchd.service"), + ).Return(true, nil) + hostHelper.EXPECT().Chroot("/host").Return(nil, fmt.Errorf("test")) + hostHelper.EXPECT().UpdateSystemService(newServiceNameMatcher("ovs-vswitchd.service")).Return(nil) + needDrain, needReboot, err := k8sPlugin.OnNodeStateChange(&sriovnetworkv1.SriovNetworkNodeState{ + Spec: sriovnetworkv1.SriovNetworkNodeStateSpec{Interfaces: []sriovnetworkv1.Interface{{EswitchMode: "switchdev"}}}}) + Expect(err).ToNot(HaveOccurred()) + Expect(needReboot).To(BeTrue()) + Expect(needDrain).To(BeTrue()) + Expect(k8sPlugin.Apply()).NotTo(HaveOccurred()) + }) + It("ovs service updated - hw offloading already enabled", func() { + setIsSystemdMode(false) + hostHelper.EXPECT().IsServiceExist("/usr/lib/systemd/system/ovs-vswitchd.service").Return(true, nil) + hostHelper.EXPECT().ReadService("/usr/lib/systemd/system/ovs-vswitchd.service").Return( + &hostTypes.Service{Name: "ovs-vswitchd.service"}, nil) + hostHelper.EXPECT().CompareServices( + &hostTypes.Service{Name: "ovs-vswitchd.service"}, + newServiceNameMatcher("ovs-vswitchd.service"), + ).Return(true, nil) + hostHelper.EXPECT().Chroot("/host").Return(func() error { return nil }, nil) + hostHelper.EXPECT().RunCommand("ovs-vsctl", "get", "Open_vSwitch", ".", "other_config:hw-offload").Return("\"true\"\n", "", nil) + hostHelper.EXPECT().UpdateSystemService(newServiceNameMatcher("ovs-vswitchd.service")).Return(nil) + needDrain, needReboot, err := k8sPlugin.OnNodeStateChange(&sriovnetworkv1.SriovNetworkNodeState{ + Spec: sriovnetworkv1.SriovNetworkNodeStateSpec{Interfaces: []sriovnetworkv1.Interface{{EswitchMode: "switchdev"}}}}) + Expect(err).ToNot(HaveOccurred()) + Expect(needReboot).To(BeFalse()) + Expect(needDrain).To(BeFalse()) + Expect(k8sPlugin.Apply()).NotTo(HaveOccurred()) + }) }) diff --git a/pkg/render/render.go b/pkg/render/render.go index 8763cc8f0..aa26b018b 100644 --- a/pkg/render/render.go +++ b/pkg/render/render.go @@ -36,9 +36,7 @@ type DeviceInfo struct { } const ( - filesDir = "files" - ovsUnitsDir = "ovs-units" - switchdevUnitsDir = "switchdev-units" + ovsUnitsDir = "ovs-units" ) func MakeRenderData() RenderData { @@ -159,26 +157,10 @@ func GenerateMachineConfig(path, name, mcRole string, ovsOffload bool, d *Render if !exists { return nil, errors.Errorf("%s is not a directory", path) } - files := map[string]string{} units := map[string]string{} - // if err := filterTemplates(files, path, d); err != nil { - // return nil, err - // } - - p := filepath.Join(path, filesDir) - exists, err = existsDir(p) - if err != nil { - return nil, err - } - if exists { - if err := filterTemplates(files, p, d); err != nil { - return nil, err - } - } - if ovsOffload { - p = filepath.Join(path, ovsUnitsDir) + p := filepath.Join(path, ovsUnitsDir) exists, err = existsDir(p) if err != nil { return nil, err @@ -189,18 +171,6 @@ func GenerateMachineConfig(path, name, mcRole string, ovsOffload bool, d *Render } } } - - p = filepath.Join(path, switchdevUnitsDir) - exists, err = existsDir(p) - if err != nil { - return nil, err - } - if exists { - if err := filterTemplates(units, p, d); err != nil { - return nil, err - } - } - // keySortVals returns a list of values, sorted by key // we need the lists of files and units to have a stable ordering for the checksum keySortVals := func(m map[string]string) []string { @@ -218,7 +188,7 @@ func GenerateMachineConfig(path, name, mcRole string, ovsOffload bool, d *Render return vs } - ignCfg, err := common.TranspileCoreOSConfigToIgn(keySortVals(files), keySortVals(units)) + ignCfg, err := common.TranspileCoreOSConfigToIgn(nil, keySortVals(units)) if err != nil { return nil, errors.Wrap(err, "error transpiling CoreOS config to Ignition config") }