From 73ed5e850e030f801577567cfe7a4aa04c2f4552 Mon Sep 17 00:00:00 2001 From: Ivan Kolodiazhnyi Date: Mon, 10 Apr 2023 17:31:40 +0300 Subject: [PATCH] Clean up duplicated and obsolete logic --- pkg/daemon/daemon.go | 45 ++------------------------------------------ 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index faf2961e8..0adfeabbe 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -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" @@ -89,9 +88,6 @@ type Daemon struct { node *corev1.Node - // TODO(e0ne): remove it - drainable bool - disableDrain bool nodeLister listerv1.NodeLister @@ -261,10 +257,6 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error) error { ) dn.nodeLister = nodeInformerFactory.Core().V1().Nodes().Lister() nodeInformer := nodeInformerFactory.Core().V1().Nodes().Informer() - nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: dn.nodeAddHandler, - UpdateFunc: dn.nodeUpdateHandler, - }) go cfgInformer.Run(dn.stopCh) go nodeInformer.Run(dn.stopCh) time.Sleep(5 * time.Second) @@ -366,30 +358,6 @@ func (dn *Daemon) processNextWorkItem() bool { return true } -func (dn *Daemon) nodeAddHandler(obj interface{}) { - dn.nodeUpdateHandler(nil, obj) -} - -func (dn *Daemon) nodeUpdateHandler(old, new interface{}) { - node, err := dn.nodeLister.Get(dn.name) - if errors.IsNotFound(err) { - glog.V(2).Infof("nodeUpdateHandler(): node %v has been deleted", dn.name) - 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{}) { dn.operatorConfigChangeHandler(&sriovnetworkv1.SriovOperatorConfig{}, obj) } @@ -497,7 +465,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 } @@ -557,7 +525,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 @@ -575,15 +543,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 {