Skip to content

Commit f6b12fd

Browse files
committed
Cleanup in-memory node state on node removal
Signed-off-by: Patryk Diak <[email protected]>
1 parent 21112b9 commit f6b12fd

File tree

7 files changed

+29
-0
lines changed

7 files changed

+29
-0
lines changed

pkg/cloudprovider/aws.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ func sharedCredentialsFileFromDirectory(dir string) (string, error) {
447447
return f.Name(), nil
448448
}
449449

450+
func (a *AWS) CleanupNode(nodeName string) {
451+
}
452+
450453
// newConfigForStaticCreds is copied verbatim from:
451454
// https://github.com/openshift/cluster-ingress-operator/blob/1600a0e349ef075fcb52ab65b33445e256358ab8/pkg/util/aws/shared_credentials_file.go#L52
452455
func newConfigForStaticCreds(accessKey string, accessSecret string) []byte {

pkg/cloudprovider/azure.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,12 @@ func (a *Azure) getNodeLock(nodeName string) *sync.Mutex {
667667
return a.nodeLockMap[nodeName]
668668
}
669669

670+
func (a *Azure) CleanupNode(nodeName string) {
671+
a.nodeMapLock.Lock()
672+
defer a.nodeMapLock.Unlock()
673+
delete(a.nodeLockMap, nodeName)
674+
}
675+
670676
func getNameFromResourceID(id string) string {
671677
return id[strings.LastIndex(id, "/"):]
672678
}

pkg/cloudprovider/cloudprovider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ type CloudProviderIntf interface {
6363
// The cpicIPs parameter is a set of IP addresses that are
6464
// managed by CloudPrivateIPConfigs and should be excluded from capacity calculations.
6565
GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error)
66+
67+
// CleanupNode removes any internal state associated with the node.
68+
// This should be called when a node is deleted.
69+
CleanupNode(nodeName string)
6670
}
6771

6872
// CloudProviderWithMoveIntf is additional interface that can be added to cloud

pkg/cloudprovider/cloudprovider_fake.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ func (f *FakeCloudProvider) GetNodeEgressIPConfiguration(node *corev1.Node, cpic
6969
}
7070
return nil, nil
7171
}
72+
73+
func (f *FakeCloudProvider) CleanupNode(nodeName string) {
74+
}

pkg/cloudprovider/gcp.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,9 @@ func (g *GCP) getNodeLock(nodeName string) *sync.Mutex {
335335
}
336336
return g.nodeLockMap[nodeName]
337337
}
338+
339+
func (g *GCP) CleanupNode(nodeName string) {
340+
g.nodeMapLock.Lock()
341+
defer g.nodeMapLock.Unlock()
342+
delete(g.nodeLockMap, nodeName)
343+
}

pkg/cloudprovider/openstack.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,3 +1015,6 @@ func getNodeInternalAddrs(node *corev1.Node) (net.IP, net.IP) {
10151015
}
10161016
return v4Addr, v6Addr
10171017
}
1018+
1019+
func (o *OpenStack) CleanupNode(nodeName string) {
1020+
}

pkg/controller/node/node_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ func NewNodeController(
8787
controller.Enqueue(newN)
8888
}
8989
},
90+
// Enqueue removals for cleanup purposes only
91+
DeleteFunc: controller.Enqueue,
9092
})
9193
if err != nil {
9294
return nil, err
@@ -103,6 +105,8 @@ func (n *NodeController) SyncHandler(key string) error {
103105
// // A lister can only return ErrNotFound, which means: the Node
104106
// resource no longer exist, in which case we stop processing.
105107
klog.Infof("corev1.Node: '%s' in work queue no longer exists", key)
108+
// Clean up any cloud provider state associated with this node
109+
n.cloudProviderClient.CleanupNode(key)
106110
return nil
107111
}
108112

0 commit comments

Comments
 (0)