Skip to content

Commit

Permalink
Clean up duplicated and obsolete logic
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ne committed May 9, 2023
1 parent 86804e0 commit 1664ad2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
2 changes: 1 addition & 1 deletion controllers/drain_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (dr *DrainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

for _, node := range nodeList.Items {
if utils.NodeHasAnnotation(node, "sriovnetwork.openshift.io/state", "Drain_Required") {
if drainingNodes < config.Spec.MaxParallelNodeConfiguration {
if config.Spec.MaxParallelNodeConfiguration == 0 || drainingNodes < config.Spec.MaxParallelNodeConfiguration {
reqLogger.Info("Start draining node", "node", node.Name)
node.Annotations["sriovnetwork.openshift.io/state"] = "Draining"
if err := dr.Update(ctx, &node); err != nil {
Expand Down
30 changes: 3 additions & 27 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/strategicpatch"
Expand Down Expand Up @@ -89,9 +88,6 @@ type Daemon struct {

node *corev1.Node

// TODO(e0ne): remove it
drainable bool

disableDrain bool

nodeLister listerv1.NodeLister
Expand Down Expand Up @@ -274,7 +270,7 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error) error {
}

glog.Info("Starting workers")
// Launch one workers to process
// Launch one worker to process
go wait.Until(dn.runWorker, time.Second, stopCh)
glog.Info("Started workers")

Expand Down Expand Up @@ -377,17 +373,6 @@ func (dn *Daemon) nodeUpdateHandler(old, new interface{}) {
return
}
dn.node = node.DeepCopy()
nodes, err := dn.nodeLister.List(labels.Everything())
if err != nil {
return
}
for _, node := range nodes {
if node.GetName() != dn.name && (node.Annotations[annoKey] == annoDraining || node.Annotations[annoKey] == annoMcpPaused) {
dn.drainable = false
return
}
}
dn.drainable = true
}

func (dn *Daemon) operatorConfigAddHandler(obj interface{}) {
Expand Down Expand Up @@ -497,7 +482,7 @@ func (dn *Daemon) nodeStateSyncHandler() error {
}
}

if dn.nodeHasAnnotation(annoKey, annoDrainRequired) {
if utils.NodeHasAnnotation(*dn.node, annoKey, annoDrainRequired) {
glog.Info("nodeStateSyncHandler(): waiting for drain")
return nil
}
Expand Down Expand Up @@ -557,7 +542,7 @@ func (dn *Daemon) nodeStateSyncHandler() error {
return err
}
} else {
if !dn.nodeHasAnnotation(annoKey, annoIdle) {
if !utils.NodeHasAnnotation(*dn.node, annoKey, annoIdle) {
if err := dn.annotateNode(dn.name, annoIdle); err != nil {
glog.Errorf("nodeStateSyncHandler(): failed to annotate node: %v", err)
return err
Expand All @@ -575,15 +560,6 @@ func (dn *Daemon) nodeStateSyncHandler() error {
return nil
}

func (dn *Daemon) nodeHasAnnotation(annoKey string, value string) bool {
// TODO(e0ne): re-use cluster.NodeHasAnnotation function
// Check if node already contains annotation
if anno, ok := dn.node.Annotations[annoKey]; ok && (anno == value) {
return true
}
return false
}

func (dn *Daemon) isNodeDraining() bool {
anno, ok := dn.node.Annotations[annoKey]
if !ok {
Expand Down

0 comments on commit 1664ad2

Please sign in to comment.