@@ -37,9 +37,6 @@ import (
37
37
"k8s.io/client-go/tools/record"
38
38
clientretry "k8s.io/client-go/util/retry"
39
39
cloudprovider "k8s.io/cloud-provider"
40
- nodeutilv1 "k8s.io/kubernetes/pkg/api/v1/node"
41
- "k8s.io/kubernetes/pkg/controller"
42
- nodectrlutil "k8s.io/kubernetes/pkg/controller/util/node"
43
40
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
44
41
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
45
42
nodeutil "k8s.io/kubernetes/pkg/util/node"
@@ -58,11 +55,6 @@ type CloudNodeController struct {
58
55
59
56
cloud cloudprovider.Interface
60
57
61
- // Value controlling NodeController monitoring period, i.e. how often does NodeController
62
- // check node status posted from kubelet. This value should be lower than nodeMonitorGracePeriod
63
- // set in controller-manager
64
- nodeMonitorPeriod time.Duration
65
-
66
58
nodeStatusUpdateFrequency time.Duration
67
59
}
68
60
@@ -79,7 +71,6 @@ func NewCloudNodeController(
79
71
nodeInformer coreinformers.NodeInformer ,
80
72
kubeClient clientset.Interface ,
81
73
cloud cloudprovider.Interface ,
82
- nodeMonitorPeriod time.Duration ,
83
74
nodeStatusUpdateFrequency time.Duration ) * CloudNodeController {
84
75
85
76
eventBroadcaster := record .NewBroadcaster ()
@@ -97,7 +88,6 @@ func NewCloudNodeController(
97
88
kubeClient : kubeClient ,
98
89
recorder : recorder ,
99
90
cloud : cloud ,
100
- nodeMonitorPeriod : nodeMonitorPeriod ,
101
91
nodeStatusUpdateFrequency : nodeStatusUpdateFrequency ,
102
92
}
103
93
@@ -111,8 +101,9 @@ func NewCloudNodeController(
111
101
return cnc
112
102
}
113
103
114
- // This controller deletes a node if kubelet is not reporting
115
- // and the node is gone from the cloud provider.
104
+ // This controller updates newly registered nodes with information
105
+ // from the cloud provider. This call is blocking so should be called
106
+ // via a goroutine
116
107
func (cnc * CloudNodeController ) Run (stopCh <- chan struct {}) {
117
108
defer utilruntime .HandleCrash ()
118
109
@@ -121,10 +112,7 @@ func (cnc *CloudNodeController) Run(stopCh <-chan struct{}) {
121
112
// very infrequently. DO NOT MODIFY this to perform frequent operations.
122
113
123
114
// Start a loop to periodically update the node addresses obtained from the cloud
124
- go wait .Until (cnc .UpdateNodeStatus , cnc .nodeStatusUpdateFrequency , stopCh )
125
-
126
- // Start a loop to periodically check if any nodes have been deleted from cloudprovider
127
- go wait .Until (cnc .MonitorNode , cnc .nodeMonitorPeriod , stopCh )
115
+ wait .Until (cnc .UpdateNodeStatus , cnc .nodeStatusUpdateFrequency , stopCh )
128
116
}
129
117
130
118
// UpdateNodeStatus updates the node status, such as node addresses
@@ -210,108 +198,6 @@ func (cnc *CloudNodeController) updateNodeAddress(node *v1.Node, instances cloud
210
198
}
211
199
}
212
200
213
- // Monitor node queries the cloudprovider for non-ready nodes and deletes them
214
- // if they cannot be found in the cloud provider
215
- func (cnc * CloudNodeController ) MonitorNode () {
216
- instances , ok := cnc .cloud .Instances ()
217
- if ! ok {
218
- utilruntime .HandleError (fmt .Errorf ("failed to get instances from cloud provider" ))
219
- return
220
- }
221
-
222
- nodes , err := cnc .kubeClient .CoreV1 ().Nodes ().List (metav1.ListOptions {ResourceVersion : "0" })
223
- if err != nil {
224
- klog .Errorf ("Error monitoring node status: %v" , err )
225
- return
226
- }
227
-
228
- for i := range nodes .Items {
229
- var currentReadyCondition * v1.NodeCondition
230
- node := & nodes .Items [i ]
231
- // Try to get the current node status
232
- // If node status is empty, then kubelet has not posted ready status yet. In this case, process next node
233
- for rep := 0 ; rep < nodeStatusUpdateRetry ; rep ++ {
234
- _ , currentReadyCondition = nodeutilv1 .GetNodeCondition (& node .Status , v1 .NodeReady )
235
- if currentReadyCondition != nil {
236
- break
237
- }
238
- name := node .Name
239
- node , err = cnc .kubeClient .CoreV1 ().Nodes ().Get (name , metav1.GetOptions {})
240
- if err != nil {
241
- klog .Errorf ("Failed while getting a Node to retry updating NodeStatus. Probably Node %s was deleted." , name )
242
- break
243
- }
244
- time .Sleep (retrySleepTime )
245
- }
246
- if currentReadyCondition == nil {
247
- klog .Errorf ("Update status of Node %v from CloudNodeController exceeds retry count or the Node was deleted." , node .Name )
248
- continue
249
- }
250
- // If the known node status says that Node is NotReady, then check if the node has been removed
251
- // from the cloud provider. If node cannot be found in cloudprovider, then delete the node immediately
252
- if currentReadyCondition != nil {
253
- if currentReadyCondition .Status != v1 .ConditionTrue {
254
- // we need to check this first to get taint working in similar in all cloudproviders
255
- // current problem is that shutdown nodes are not working in similar way ie. all cloudproviders
256
- // does not delete node from kubernetes cluster when instance it is shutdown see issue #46442
257
- shutdown , err := nodectrlutil .ShutdownInCloudProvider (context .TODO (), cnc .cloud , node )
258
- if err != nil {
259
- klog .Errorf ("Error checking if node %s is shutdown: %v" , node .Name , err )
260
- }
261
-
262
- if shutdown && err == nil {
263
- // if node is shutdown add shutdown taint
264
- err = controller .AddOrUpdateTaintOnNode (cnc .kubeClient , node .Name , controller .ShutdownTaint )
265
- if err != nil {
266
- klog .Errorf ("Error patching node taints: %v" , err )
267
- }
268
- // Continue checking the remaining nodes since the current one is shutdown.
269
- continue
270
- }
271
-
272
- // Check with the cloud provider to see if the node still exists. If it
273
- // doesn't, delete the node immediately.
274
- exists , err := ensureNodeExistsByProviderID (instances , node )
275
- if err != nil {
276
- klog .Errorf ("Error checking if node %s exists: %v" , node .Name , err )
277
- continue
278
- }
279
-
280
- if exists {
281
- // Continue checking the remaining nodes since the current one is fine.
282
- continue
283
- }
284
-
285
- klog .V (2 ).Infof ("Deleting node since it is no longer present in cloud provider: %s" , node .Name )
286
-
287
- ref := & v1.ObjectReference {
288
- Kind : "Node" ,
289
- Name : node .Name ,
290
- UID : types .UID (node .UID ),
291
- Namespace : "" ,
292
- }
293
- klog .V (2 ).Infof ("Recording %s event message for node %s" , "DeletingNode" , node .Name )
294
-
295
- cnc .recorder .Eventf (ref , v1 .EventTypeNormal , fmt .Sprintf ("Deleting Node %v because it's not present according to cloud provider" , node .Name ), "Node %s event: %s" , node .Name , "DeletingNode" )
296
-
297
- go func (nodeName string ) {
298
- defer utilruntime .HandleCrash ()
299
- if err := cnc .kubeClient .CoreV1 ().Nodes ().Delete (nodeName , nil ); err != nil {
300
- klog .Errorf ("unable to delete node %q: %v" , nodeName , err )
301
- }
302
- }(node .Name )
303
-
304
- } else {
305
- // if taint exist remove taint
306
- err = controller .RemoveTaintOffNode (cnc .kubeClient , node .Name , node , controller .ShutdownTaint )
307
- if err != nil {
308
- klog .Errorf ("Error patching node taints: %v" , err )
309
- }
310
- }
311
- }
312
- }
313
- }
314
-
315
201
func (cnc * CloudNodeController ) UpdateCloudNode (_ , newObj interface {}) {
316
202
if _ , ok := newObj .(* v1.Node ); ! ok {
317
203
utilruntime .HandleError (fmt .Errorf ("unexpected object type: %v" , newObj ))
0 commit comments