Skip to content

Commit

Permalink
Merge pull request kubernetes#7493 from BigDarkClown/remove-unneeded
Browse files Browse the repository at this point in the history
Add flag to force remove long unregistered nodes
  • Loading branch information
k8s-ci-robot authored Nov 19, 2024
2 parents 2d37aee + 1580315 commit a01276e
Show file tree
Hide file tree
Showing 43 changed files with 399 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ func (asg *Asg) DeleteNodes(nodes []*apiv1.Node) error {
return asg.manager.DeleteInstances(nodeIds)
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (asg *Asg) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// Id returns asg id.
func (asg *Asg) Id() string {
return asg.id
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ func (ng *AwsNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return ng.awsManager.DeleteInstances(refs)
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (ng *AwsNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// Id returns asg id.
func (ng *AwsNodeGroup) Id() string {
return ng.asg.Name
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ func (as *AgentPool) DeleteNodes(nodes []*apiv1.Node) error {
return as.DeleteInstances(refs)
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (as *AgentPool) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// Debug returns a debug string for the agent pool.
func (as *AgentPool) Debug() string {
return fmt.Sprintf("%s (%d:%d)", as.Name, as.MinSize(), as.MaxSize())
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,11 @@ func (scaleSet *ScaleSet) DeleteNodes(nodes []*apiv1.Node) error {
return scaleSet.DeleteInstances(refs, hasUnregisteredNodes)
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (scaleSet *ScaleSet) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// Id returns ScaleSet id.
func (scaleSet *ScaleSet) Id() string {
return scaleSet.Name
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_vms_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (agentPool *VMsPool) DeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (agentPool *VMsPool) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group.
func (agentPool *VMsPool) DecreaseTargetSize(delta int) error {
// TODO(wenxuan): Implement this method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ func (asg *Asg) DeleteNodes(nodes []*apiv1.Node) error {
return asg.baiducloudManager.ScaleDownCluster(nodeID)
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (asg *Asg) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// Belongs returns true if the given node belongs to the NodeGroup.
func (asg *Asg) Belongs(instanceID string) (bool, error) {
targetAsg, err := asg.baiducloudManager.GetAsgForInstance(instanceID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func (n *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (ng *brightboxNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (ng *brightboxNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This
// function doesn't permit to delete any existing node and can be used
// only to reduce the request for new nodes that have not been yet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ func (ng *cherryNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (ng *cherryNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// getNodesToDelete safely gets all of the nodes added to the delete queue.
// "safely", as in it locks, gets and then releases the queue.
func (ng *cherryNodeGroup) getNodesToDelete() []*apiv1.Node {
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/civo/civo_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func (n *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
6 changes: 6 additions & 0 deletions cluster-autoscaler/cloudprovider/cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ type NodeGroup interface {
// should wait until node group size is updated. Implementation required.
DeleteNodes([]*apiv1.Node) error

// ForceDeleteNodes deletes nodes from this node group, without checking for
// constraints like minimal size validation etc. Error is returned either on
// failure or if the given node doesn't belong to this node group. This function
// should wait until node group size is updated.
ForceDeleteNodes([]*apiv1.Node) error

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func (asg *asg) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (asg *asg) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// Id returns cluster id.
func (asg *asg) Id() string {
return asg.cluster.ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ func (ng *nodegroup) DeleteNodes(nodes []*corev1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (ng *nodegroup) ForceDeleteNodes(nodes []*corev1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group.
// This function doesn't permit to delete any existing node and can be
// used only to reduce the request for new nodes that have not been
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func (n *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/equinixmetal/node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ func (ng *equinixMetalNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (ng *equinixMetalNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the cluster node_count in Equinix Metal.
func (ng *equinixMetalNodeGroup) DecreaseTargetSize(delta int) error {
if delta >= 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ func (n *instancePoolNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *instancePoolNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func (n *sksNodepoolNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *sksNodepoolNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func (n *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ func (mig *gceMig) DeleteNodes(nodes []*apiv1.Node) error {
if int(size) <= mig.MinSize() {
return fmt.Errorf("min size reached, nodes will not be deleted")
}
return mig.ForceDeleteNodes(nodes)
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (mig *gceMig) ForceDeleteNodes(nodes []*apiv1.Node) error {
refs := make([]GceRef, 0, len(nodes))
for _, node := range nodes {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ func TestMig(t *testing.T) {
assert.Equal(t, "min size reached, nodes will not be deleted", err.Error())
mock.AssertExpectationsForObjects(t, gceManagerMock)

// Test ForceDeleteNodes - ignore the min size constraint.
gceManagerMock.On("GetMigForInstance", n1ref).Return(mig1, nil).Once()
gceManagerMock.On("GetMigForInstance", n2ref).Return(mig1, nil).Once()
gceManagerMock.On("DeleteInstances", []GceRef{n1ref, n2ref}).Return(nil).Once()
err = mig1.ForceDeleteNodes([]*apiv1.Node{n1, n2})
assert.NoError(t, err)
mock.AssertExpectationsForObjects(t, gceManagerMock)

// Test Nodes.
gceManagerMock.On("GetMigNodes", mock.AnythingOfType("*gce.gceMig")).Return(
[]GceInstance{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func (n *hetznerNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *hetznerNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (asg *AutoScalingGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (asg *AutoScalingGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func (n *nodePool) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *nodePool) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func (n *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/kubemark/kubemark_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ func (nodeGroup *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (nodeGroup *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// IncreaseSize increases NodeGroup size.
func (nodeGroup *NodeGroup) IncreaseSize(delta int) error {
if delta <= 0 {
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (nodeGroup *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (nodeGroup *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/linode/linode_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func (n *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (n *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/magnum/magnum_nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func (ng *magnumNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (ng *magnumNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the cluster node_count in magnum.
func (ng *magnumNodeGroup) DecreaseTargetSize(delta int) error {
ng.clusterUpdateLock.Lock()
Expand Down
14 changes: 14 additions & 0 deletions cluster-autoscaler/cloudprovider/mocks/NodeGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ func (_m *NodeGroup) DeleteNodes(_a0 []*v1.Node) error {
return r0
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (_m *NodeGroup) ForceDeleteNodes(_a0 []*v1.Node) error {
ret := _m.Called(_a0)

var r0 error
if rf, ok := ret.Get(0).(func([]*v1.Node) error); ok {
r0 = rf(_a0)
} else {
r0 = ret.Error(0)
}

return r0
}

// Exist provides a mock function with given fields:
func (_m *NodeGroup) Exist() bool {
ret := _m.Called()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (ip *InstancePoolNodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return ip.manager.DeleteInstances(*ip, refs)
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (ip *InstancePoolNodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the instance-pool based node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func (np *nodePool) DeleteNodes(nodes []*apiv1.Node) (err error) {
return deleteInstancesErr
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (np *nodePool) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func (ng *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
return nil
}

// ForceDeleteNodes deletes nodes from the group regardless of constraints.
func (ng *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error {
return cloudprovider.ErrNotImplemented
}

// DecreaseTargetSize decreases the target size of the node group. This function
// doesn't permit to delete any existing node and can be used only to reduce the
// request for new nodes that have not been yet fulfilled. Delta should be negative.
Expand Down
Loading

0 comments on commit a01276e

Please sign in to comment.