Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix taint removal retry for non-swallowed errors #1898

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func newNodeService(driverOptions *DriverOptions) nodeService {

// Remove taint from node to indicate driver startup success
// This is done at the last possible moment to prevent race conditions or false positive removals
go removeTaintInBackground(cloud.DefaultKubernetesAPIClient)
go removeTaintInBackground(cloud.DefaultKubernetesAPIClient, removeNotReadyTaint)

return nodeService{
metadata: metadata,
Expand Down Expand Up @@ -854,12 +854,12 @@ type JSONPatch struct {
}

// removeTaintInBackground is a goroutine that retries removeNotReadyTaint with exponential backoff
func removeTaintInBackground(k8sClient cloud.KubernetesAPIClient) {
func removeTaintInBackground(k8sClient cloud.KubernetesAPIClient, removalFunc func(cloud.KubernetesAPIClient) error) {
backoffErr := wait.ExponentialBackoff(taintRemovalBackoff, func() (bool, error) {
err := removeNotReadyTaint(k8sClient)
err := removalFunc(k8sClient)
if err != nil {
klog.ErrorS(err, "Unexpected failure when attempting to remove node taint(s)")
return false, err
return false, nil
}
return true, nil
})
Expand Down
16 changes: 16 additions & 0 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver/internal"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -2405,6 +2406,21 @@ func TestRemoveNotReadyTaint(t *testing.T) {
}
}

func TestRemoveTaintInBackground(t *testing.T) {
mockRemovalCount := 0
mockRemovalFunc := func(_ cloud.KubernetesAPIClient) error {
mockRemovalCount += 1
if mockRemovalCount == 3 {
return nil
} else {
return fmt.Errorf("Taint removal failed!")
}
}

removeTaintInBackground(nil, mockRemovalFunc)
assert.Equal(t, mockRemovalCount, 3)
}

func getNodeMock(mockCtl *gomock.Controller, nodeName string, returnNode *corev1.Node, returnError error) (kubernetes.Interface, *MockNodeInterface) {
mockClient := NewMockKubernetesClient(mockCtl)
mockCoreV1 := NewMockCoreV1Interface(mockCtl)
Expand Down
Loading