Skip to content

Commit

Permalink
Deploy sriovd servise in vanilla K8S
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ne committed Oct 31, 2022
1 parent 48e249d commit 695525f
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions pkg/plugins/k8s/k8s_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type K8sPlugin struct {
switchdevAfterNMService *service.Service
openVSwitchService *service.Service
networkManagerService *service.Service
sriovService *service.Service
updateTarget *k8sUpdateTarget
useSystemdService bool
}
Expand All @@ -39,6 +40,7 @@ type k8sUpdateTarget struct {
switchdevBeforeNMRunScript bool
switchdevAfterNMRunScript bool
switchdevUdevScript bool
sriovScript bool
systemServices []*service.Service
}

Expand Down Expand Up @@ -77,11 +79,11 @@ func (u *k8sUpdateTarget) String() string {
}

const (
bindataManifestPath = "bindata/manifests/"
switchdevManifestPath = bindataManifestPath + "switchdev-config/"
switchdevUnits = switchdevManifestPath + "switchdev-units/"
// sriovUnits = bindataManifestPath + "sriov-config-service/units/"
// sriovUnitFile = sriovUnits + "sriov-config-service.yaml"
bindataManifestPath = "bindata/manifests/"
switchdevManifestPath = bindataManifestPath + "switchdev-config/"
switchdevUnits = switchdevManifestPath + "switchdev-units/"
sriovUnits = bindataManifestPath + "sriov-config-service/units/"
sriovUnitFile = sriovUnits + "sriov-config-service.yaml"
switchdevBeforeNMUnitFile = switchdevUnits + "switchdev-configuration-before-nm.yaml"
switchdevAfterNMUnitFile = switchdevUnits + "switchdev-configuration-after-nm.yaml"
networkManagerUnitFile = switchdevUnits + "NetworkManager.service.yaml"
Expand Down Expand Up @@ -129,6 +131,14 @@ func (p *K8sPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState)
return
}

if p.useSystemdService {
// Check sriov service
err = p.sriovServiceStateUpdate()
if err != nil {
glog.Errorf("k8s-plugin OnNodeStateChange(): failed : %v", err)
}
}

if utils.IsSwitchdevModeSpec(new.Spec) {
// Check services
err = p.servicesStateUpdate()
Expand Down Expand Up @@ -237,6 +247,16 @@ func (p *K8sPlugin) readOpenVSwitchdManifest() error {
return nil
}

func (p *K8sPlugin) readSriovdManifest() error {
sriovService, err := service.ReadServiceInjectionManifestFile(sriovUnitFile)
if err != nil {
return err
}

p.sriovService = sriovService
return nil
}

func (p *K8sPlugin) readManifestFiles() error {
if err := p.readSwitchdevManifest(); err != nil {
return err
Expand All @@ -250,6 +270,10 @@ func (p *K8sPlugin) readManifestFiles() error {
return err
}

if err := p.readSriovdManifest(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -288,6 +312,20 @@ func (p *K8sPlugin) switchdevServiceStateUpdate() error {
return nil
}

func (p *K8sPlugin) sriovServiceStateUpdate() error {
exist, err := p.serviceManager.IsServiceExist(p.sriovService.Path)
if err != nil {
return err
}
if !exist {
return fmt.Errorf("k8s-plugin sriovServiceStateUpdate(): %q not found", p.sriovService.Name)
}

p.updateTarget.sriovScript = p.isSystemServiceNeedUpdate(p.sriovService)

return nil
}

func (p *K8sPlugin) getSystemServices() []*service.Service {
return []*service.Service{p.networkManagerService, p.openVSwitchService}
}
Expand Down Expand Up @@ -376,6 +414,25 @@ func (p *K8sPlugin) servicesStateUpdate() error {
return nil
}

func (p *K8sPlugin) updateSriovService() error {
if p.updateTarget.sriovScript {
err := p.serviceManager.EnableService(p.sriovService)
if err != nil {
return err
}
}

if p.updateTarget.sriovScript {
err := ioutil.WriteFile(path.Join(chroot, p.sriovService.Path),
[]byte(p.switchdevBeforeNMRunScript.Contents.Inline), 0755)
if err != nil {
return err
}
}

return nil
}

func (p *K8sPlugin) updateSwitchdevService() error {
if p.updateTarget.switchdevBeforeNMService {
err := p.serviceManager.EnableService(p.switchdevBeforeNMService)
Expand Down

0 comments on commit 695525f

Please sign in to comment.