-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support changing Eswitch mode of SR-IOV NICs for kubernetes deployment
Signed-off-by: Mamduh Alassi <[email protected]>
- Loading branch information
Showing
12 changed files
with
392 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Service] | ||
ExecStart=/bin/ovs-vsctl set Open_vSwitch . other_config:hw-offload=true |
16 changes: 16 additions & 0 deletions
16
bindata/manifests/k8s-services/switchdev-configuration.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[Unit] | ||
Description=Configures SRIOV NIC into switchdev mode | ||
# Run service only when SR-IOV Network Operator is running | ||
ConditionPathExists=/etc/sriov-netowrk-operator-run | ||
# This service is used to move a SRIOV NIC into switchdev mode | ||
Wants=network-pre.target | ||
Before=network-pre.target | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/local/bin/configure-switchdev.sh | ||
StandardOutput=journal+console | ||
StandardError=journal+console | ||
|
||
[Install] | ||
WantedBy=network-online.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"path" | ||
|
||
"github.com/golang/glog" | ||
"gopkg.in/yaml.v2" | ||
|
||
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" | ||
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/service" | ||
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" | ||
) | ||
|
||
type K8sPlugin struct { | ||
PluginName string | ||
SpecVersion string | ||
services []serviceConf | ||
} | ||
|
||
type serviceConf struct { | ||
name string | ||
serviceBin string | ||
} | ||
|
||
const ( | ||
k8sServicesManifestPath = "bindata/manifests/k8s-services" | ||
ovsVSwitchdService = "ovs-vswitchd" | ||
switchdevService = "switchdev-configuration" | ||
configuresSwitchdevScript = "bindata/manifests/machine-config/files/configure-switchdev.sh.yaml" | ||
) | ||
|
||
var ( | ||
Plugin K8sPlugin | ||
|
||
serviceManager service.ServiceManager | ||
) | ||
|
||
// Initialize our plugin and set up initial values | ||
func init() { | ||
Plugin = K8sPlugin{ | ||
PluginName: "k8s_plugin", | ||
SpecVersion: "1.0", | ||
services: []serviceConf{{ | ||
name: "switchdev-configuration", | ||
serviceBin: "configure-switchdev.sh", | ||
}}, | ||
} | ||
serviceManager = service.NewServiceManager("/host") | ||
} | ||
|
||
// Name returns the name of the plugin | ||
func (p *K8sPlugin) Name() string { | ||
return p.PluginName | ||
} | ||
|
||
// Spec returns the version of the spec expected by the plugin | ||
func (p *K8sPlugin) Spec() string { | ||
return p.SpecVersion | ||
} | ||
|
||
// OnNodeStateAdd Invoked when SriovNetworkNodeState CR is created, return if need dain and/or reboot node | ||
func (p *K8sPlugin) OnNodeStateAdd(state *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) { | ||
glog.Info("k8s-plugin OnNodeStateAdd()") | ||
return p.OnNodeStateChange(nil, state) | ||
} | ||
|
||
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is updated, return if need dain and/or reboot node | ||
func (p *K8sPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) { | ||
glog.Info("k8s-plugin OnNodeStateChange()") | ||
needDrain = false | ||
needReboot = false | ||
|
||
// Check services | ||
var needServices bool | ||
needServices, err = handleAddingServices() | ||
if err != nil { | ||
return | ||
} | ||
|
||
if !needServices { | ||
needServices, err = serviceManager.CheckServicesLoaded() | ||
if err != nil { | ||
return | ||
} | ||
} | ||
needDrain = needServices | ||
|
||
// Check switchdev config | ||
var update, remove bool | ||
if update, remove, err = utils.WriteSwitchdevConfFile(new); err != nil { | ||
glog.Errorf("k8s-plugin OnNodeStateChange():fail to update switchdev.conf file: %v", err) | ||
return | ||
} | ||
if remove { | ||
needDrain = true | ||
return | ||
} | ||
if update { | ||
glog.Info("k8s-plugin OnNodeStateChange(): need reboot node to use the up-to-date switchdev.conf") | ||
needDrain = true | ||
needReboot = true | ||
return | ||
} | ||
return | ||
} | ||
|
||
// Apply config change | ||
func (p *K8sPlugin) Apply() error { | ||
glog.Info("k8s-plugin Apply()") | ||
if err := serviceManager.LoadMissingServices(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func handleAddingServices() (bool, error) { | ||
needChange := false | ||
|
||
smServices := serviceManager.ServicesSet() | ||
if _, ok := smServices[ovsVSwitchdService]; !ok { | ||
ovsService, err := service.ServiceFromFile(ovsVSwitchdService, path.Join(k8sServicesManifestPath, ovsVSwitchdService+".service")) | ||
if err != nil { | ||
return false, err | ||
} | ||
needChange = true | ||
_ = serviceManager.AddService(ovsService) | ||
} | ||
|
||
if _, ok := smServices[switchdevService]; !ok { | ||
switchdevService, err := service.ServiceFromFile(switchdevService, path.Join(k8sServicesManifestPath, switchdevService+".service")) | ||
if err != nil { | ||
return false, err | ||
} | ||
data, err := ioutil.ReadFile(configuresSwitchdevScript) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
var switchdevBinYaml struct { | ||
Path string | ||
Contents struct { | ||
Inline string | ||
} | ||
} | ||
if err := yaml.Unmarshal(data, &switchdevBinYaml); err != nil { | ||
return false, err | ||
} | ||
switchdevService.Run = switchdevBinYaml.Path | ||
switchdevService.RunBody = switchdevBinYaml.Contents.Inline | ||
needChange = true | ||
_ = serviceManager.AddService(switchdevService) | ||
} | ||
|
||
return needChange, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package service | ||
|
||
import ( | ||
"io/ioutil" | ||
) | ||
|
||
type Service struct { | ||
Name string | ||
Body string | ||
Run string | ||
RunBody string | ||
} | ||
|
||
func ServiceFromFile(name, file string) (*Service, error) { | ||
data, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
service := &Service{ | ||
Name: name, | ||
Body: string(data), | ||
} | ||
|
||
return service, nil | ||
} |
Oops, something went wrong.