Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to instantiate a Taint Manager

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "how to instantiate a Taint Manager". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to instantiate a Taint Manager.

NewNoExecuteTaintManager

When PodInformer adds Event Handler, add updateItem to tc.podUpdateQueue by calling taintManager.PodUpdated (oldPod * v1.Pod, newPod * v1.Pod).

When NodeInformer adds Event Handler, add updateItem to tc.nodeUpdateQueue by calling taintManager.NodeUpdated (oldNode * v1.Node, newNode * v1.Node).

When creating a NodeController, if runTaintManager is true (specified by default in kube-controller-manager 's-- enable-taint-manager, default is true), a TaintManager is instantiated through NewNoExecuteTaintManager.

Pkg/controller/node/nodecontroller.go:195func NewNodeController (..) (* NodeController, error) {... PodInformer.Informer () .AddEventHandler (cache.ResourceEventHandlerFuncs {AddFunc: func (obj interface {}) {... If nc.taintManager! = nil {nc.taintManager.PodUpdated (nil, pod)}} ...} else {nodeEventHandlerFuncs = cache.ResourceEventHandlerFuncs {AddFunc: func (originalObj interface {}) {... If nc.taintManager! = nil {nc.taintManager.NodeUpdated (nil, node)}},...}}. If nc.runTaintManager {nc.taintManager = NewNoExecuteTaintManager (kubeClient)}. Return nc, nil}

Therefore, when the NodeController is created, it is configured to listen for events of pod and node, and the relevant data is sent to tc.podUpdateQueue and tc.nodeUpdateQueue, from which the Taint Manager fetches the data for processing. Before that, let's take a look at how NewNoExecuteTaintManager instantiates a TaintManager.

Pkg/controller/node/taint_controller.go:152func NewNoExecuteTaintManager (c clientset.Interface) * NoExecuteTaintManager {... Tm: = & NoExecuteTaintManager {client: C, recorder: recorder, / / taintedNodes records the Taint information corresponding to each Node. TaintedNodes: make (map [string] [] v1.Taint), the updateItem extracted in / / nodeUpdateQueue will be sent to nodeUpdateChannel,Tait Manager to retrieve the corresponding node update info from the Channel. NodeUpdateChannel: make (chan * nodeUpdateItem, nodeUpdateChannelSize), / / the updateItem extracted in podUpdateQueue will be sent to podUpdateChannel,Tait Manager to retrieve the corresponding pod update info from the Channel. PodUpdateChannel: make (chan * podUpdateItem, podUpdateChannelSize), / / node update info monitored by Node Controller will be sent to nodeUpdateQueue. NodeUpdateQueue: workqueue.New (), / / pod update info that Node Controller monitors will be sent to podUpdateQueue. PodUpdateQueue: workqueue.New (),} / / CreateWorkerQueue creates a new TimedWorkerQueue for workers that will execute deletePodHandler. Tm.taintEvictionQueue = CreateWorkerQueue (deletePodHandler (c, tm.emitPodDeletionEvent)) return tm}

For related code analysis, see the code comments inside. It is important to emphasize that we have registered the function deletePodHandler with tm.taintEvictionQueue here, which is used to call when deleting pod when passing through Taint Eviction. When Taint Manager Run, the deletePodHandler is executed by creating a Worker when tc.taintEvictionQueue.AddWork ().

Func deletePodHandler (c clientset.Interface, emitEventFunc func (types.NamespacedName)) func (args * WorkArgs) error {return func (args * WorkArgs) error {ns: = args.NamespacedName.Namespace name: = args.NamespacedName.Name glog.V (0). Infof ("NoExecuteTaintManager is deleting Pod:% v" Args.NamespacedName.String () if emitEventFunc! = nil {emitEventFunc (args.NamespacedName)} var err error / / retry 5 times according to failure For each retry mechanism with an interval of 10 seconds, call the api of apiserver to delete the corresponding Pod. For I: = 0; I < retries Delete + {err = c.Core () .Pods (ns) .Delete (name) & metav1.DeleteOptions {}) if err = = nil {break} time.Sleep (10 * time.Millisecond)} return err}} Run

In the executive section of Kubernetes Node Controller source code analysis, it is mentioned that in Node Controller Run, if runTaintManager is true, nc.taintManager.Run will be called to start TaintManager loop.

Pkg/controller/node/nodecontroller.go:550func (nc * NodeController) Run () {go func () {... If nc.runTaintManager {go nc.taintManager.Run (wait.NeverStop)}...} ()}

Next, let's take a look at Taint Manager's Run method. The TaintManager instance started by Node Controller is actually NoExecuteTaintManager, and the corresponding Run method code is as follows.

Pkg/controller/node/taint_controller.go:179// Run starts NoExecuteTaintManager which will run in loop until `stopCh` is closed.func (tc * NoExecuteTaintManager) Run (stopCh

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report