Skip to content

Commit

Permalink
Remove OnNodeStateAdd method from plugins
Browse files Browse the repository at this point in the history
All implementations of OnNodeStateAdd method are the same as
OnNodeStateChange, so we don't need this code dublication.
  • Loading branch information
e0ne committed Jul 15, 2022
1 parent 9440e86 commit e3af669
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 64 deletions.
6 changes: 1 addition & 5 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,7 @@ func (dn *Daemon) nodeStateSyncHandler(generation int64) error {
reqDrain := false
for k, p := range dn.enabledPlugins {
d, r := false, false
if dn.nodeState.GetName() == "" {
d, r, err = p.OnNodeStateAdd(latestState)
} else {
d, r, err = p.OnNodeStateChange(dn.nodeState, latestState)
}
d, r, err = p.OnNodeStateChange(dn.nodeState, latestState)
if err != nil {
glog.Errorf("nodeStateSyncHandler(): plugin %s error: %v", k, err)
return err
Expand Down
19 changes: 1 addition & 18 deletions pkg/plugins/generic/generic_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,7 @@ 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
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *GenericPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("generic-plugin OnNodeStateChange()")
needDrain = false
Expand Down
8 changes: 1 addition & 7 deletions pkg/plugins/intel/intel_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ 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
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *IntelPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("intel-plugin OnNodeStateChange()")
return false, false, nil
Expand Down
8 changes: 1 addition & 7 deletions pkg/plugins/k8s/k8s_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,7 @@ 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
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or 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
Expand Down
9 changes: 1 addition & 8 deletions pkg/plugins/mellanox/mellanox_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,7 @@ 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
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *MellanoxPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("mellanox-Plugin OnNodeStateChange()")

Expand Down
4 changes: 1 addition & 3 deletions pkg/plugins/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ 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
// Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (bool, bool, error)
// Apply config change
Apply() error
Expand Down
17 changes: 1 addition & 16 deletions pkg/plugins/virtual/virtual_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,7 @@ 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
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
func (p *VirtualPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
glog.Info("virtual-plugin OnNodeStateChange()")
needDrain = false
Expand Down

0 comments on commit e3af669

Please sign in to comment.