Skip to content

Commit

Permalink
Merge pull request #341 from e0ne/remove-on-node-state-add
Browse files Browse the repository at this point in the history
Remove duplicated and unused code in plugins
  • Loading branch information
SchSeba authored Aug 11, 2022
2 parents 82f8612 + 5addec7 commit 181d1b9
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 67 deletions.
5 changes: 3 additions & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,11 @@ func (dn *Daemon) nodeStateSyncHandler(generation int64) error {
for k, p := range dn.enabledPlugins {
d, r := false, false
if dn.nodeState.GetName() == "" {
d, r, err = p.OnNodeStateAdd(latestState)
glog.V(0).Infof("nodeStateSyncHandler(): calling OnNodeStateChange for a new node state")
} else {
d, r, err = p.OnNodeStateChange(dn.nodeState, latestState)
glog.V(0).Infof("nodeStateSyncHandler(): calling OnNodeStateChange for an updated node state")
}
d, r, err = p.OnNodeStateChange(latestState)
if err != nil {
glog.Errorf("nodeStateSyncHandler(): plugin %s error: %v", k, err)
return err
Expand Down
21 changes: 2 additions & 19 deletions pkg/plugins/generic/generic_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,8 @@ func (p *GenericPlugin) Spec() string {
return p.SpecVersion
}

// OnNodeStateAdd Invoked when SriovNetworkNodeState CR is created, return if need dain and/or reboot node
func (p *GenericPlugin) OnNodeStateAdd(state *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("generic-plugin OnNodeStateAdd()")
needDrain = false
needReboot = false
err = nil
p.DesireState = state

needDrain = needDrainNode(state.Spec.Interfaces, state.Status.Interfaces)
needReboot = needRebootNode(state, &p.LoadVfioDriver)

if needReboot {
needDrain = true
}
return
}

// OnNodeStateChange Invoked when SriovNetworkNodeState CR is updated, return if need dain and/or reboot node
func (p *GenericPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *GenericPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("generic-plugin OnNodeStateChange()")
needDrain = false
needReboot = false
Expand Down
10 changes: 2 additions & 8 deletions pkg/plugins/intel/intel_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@ func (p *IntelPlugin) Spec() string {
return p.SpecVersion
}

// OnNodeStateAdd Invoked when SriovNetworkNodeState CR is created, return if need dain and/or reboot node
func (p *IntelPlugin) OnNodeStateAdd(state *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("intel-plugin OnNodeStateAdd()")
return false, false, nil
}

// OnNodeStateChange Invoked when SriovNetworkNodeState CR is updated, return if need dain and/or reboot node
func (p *IntelPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *IntelPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("intel-plugin OnNodeStateChange()")
return false, false, nil
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/plugins/k8s/k8s_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,8 @@ 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) {
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *K8sPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("k8s-plugin OnNodeStateChange()")
needDrain = false
needReboot = false
Expand Down
11 changes: 2 additions & 9 deletions pkg/plugins/mellanox/mellanox_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,8 @@ func (p *MellanoxPlugin) Spec() string {
return p.SpecVersion
}

// OnNodeStateAdd Invoked when SriovNetworkNodeState CR is created, return if need dain and/or reboot node
func (p *MellanoxPlugin) OnNodeStateAdd(state *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("mellanox-plugin OnNodeStateAdd()")

return p.OnNodeStateChange(nil, state)
}

// OnNodeStateChange Invoked when SriovNetworkNodeState CR is updated, return if need dain and/or reboot node
func (p *MellanoxPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *MellanoxPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("mellanox-Plugin OnNodeStateChange()")

needDrain = false
Expand Down
6 changes: 2 additions & 4 deletions pkg/plugins/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ type VendorPlugin interface {
Name() string
// Return the SpecVersion followed by plugin
Spec() string
// Invoked when SriovNetworkNodeState CR is created, return if need dain and/or reboot node
OnNodeStateAdd(state *sriovnetworkv1.SriovNetworkNodeState) (bool, bool, error)
// Invoked when SriovNetworkNodeState CR is updated, return if need dain and/or reboot node
OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (bool, bool, error)
// Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) (bool, bool, error)
// Apply config change
Apply() error
}
19 changes: 2 additions & 17 deletions pkg/plugins/virtual/virtual_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,8 @@ func (p *VirtualPlugin) Spec() string {
return p.SpecVersion
}

// OnNodeStateAdd Invoked when SriovNetworkNodeState CR is created, return if need dain and/or reboot node
func (p *VirtualPlugin) OnNodeStateAdd(state *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("virtual-plugin OnNodeStateAdd()")
needReboot = false
err = nil
p.DesireState = state

if p.LoadVfioDriver != loaded {
if needVfioDriver(state) {
p.LoadVfioDriver = loading
}
}
return
}

// OnNodeStateChange Invoked when SriovNetworkNodeState CR is updated, return if need dain and/or reboot node
func (p *VirtualPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *VirtualPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("virtual-plugin OnNodeStateChange()")
needDrain = false
needReboot = false
Expand Down

0 comments on commit 181d1b9

Please sign in to comment.