diff --git a/kubernetes/base/rbac.yaml b/kubernetes/base/rbac.yaml index 60726624d0..6667ecaae8 100644 --- a/kubernetes/base/rbac.yaml +++ b/kubernetes/base/rbac.yaml @@ -25,7 +25,7 @@ rules: - apiGroups: ["coordination.k8s.io"] resources: ["leases"] resourceNames: ["descheduler"] - verbs: ["get", "patch", "delete","create", "update"] + verbs: ["get", "patch", "delete", "create", "update"] --- apiVersion: v1 kind: ServiceAccount diff --git a/test/e2e/e2e_leaderelection_test.go b/test/e2e/e2e_leaderelection_test.go index d84fe71157..a0e0ba8650 100644 --- a/test/e2e/e2e_leaderelection_test.go +++ b/test/e2e/e2e_leaderelection_test.go @@ -27,6 +27,7 @@ import ( appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -124,6 +125,15 @@ func TestLeaderElection(t *testing.T) { waitForPodsRunning(ctx, t, clientSet, deployment2.Labels, 5, deployment2.Namespace) podListBOrg := getCurrentPodNames(t, ctx, clientSet, ns2) + // Delete the descheduler lease + err = clientSet.CoordinationV1().Leases("kube-system").Delete(ctx, "descheduler", metav1.DeleteOptions{}) + if err != nil { + if !apierrors.IsNotFound(err) { + t.Fatalf("Unable to remove kube-system/descheduler lease: %v", err) + } + } + t.Logf("Removed kube-system/descheduler lease") + t.Log("Starting deschedulers") pod1Name, deploy1, cm1 := startDeschedulerServer(t, ctx, clientSet, ns1) time.Sleep(1 * time.Second) @@ -150,6 +160,8 @@ func TestLeaderElection(t *testing.T) { t.Fatalf("Unable to delete %q CM: %v", cm.Name, err) } } + + clientSet.CoordinationV1().Leases("kube-system").Delete(ctx, "descheduler", metav1.DeleteOptions{}) }() // wait for a while so all the pods are 5 seconds older @@ -226,7 +238,7 @@ func startDeschedulerServer(t *testing.T, ctx context.Context, clientSet clients deschedulerDeploymentObj := deschedulerDeployment(testName, func(deployment *appsv1.Deployment) { deployment.Name = fmt.Sprintf("%s-%s", deployment.Name, testName) args := deployment.Spec.Template.Spec.Containers[0].Args - deployment.Spec.Template.Spec.Containers[0].Args = append(args, "--leader-elect") + deployment.Spec.Template.Spec.Containers[0].Args = append(args, "--leader-elect", "--leader-elect-retry-period", "1s") deployment.Spec.Template.Spec.Volumes = []v1.Volume{ { Name: "policy-volume",