diff --git a/test/framework/deployment_helpers.go b/test/framework/deployment_helpers.go index 4849db633805..c09b3067b5ca 100644 --- a/test/framework/deployment_helpers.go +++ b/test/framework/deployment_helpers.go @@ -34,7 +34,6 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" - "k8s.io/api/policy/v1beta1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -528,73 +527,35 @@ func DeployUnevictablePod(ctx context.Context, input DeployUnevictablePodInput) Deployment: workloadDeployment, }) - // TODO(oscr): Remove when Kubernetes 1.20 support is dropped. - serverVersion, err := workloadClient.ServerVersion() - Expect(err).ToNot(HaveOccurred(), "Failed to get Kubernetes version for workload") - - // If Kubernetes < 1.21.0 we need to use PDB from v1beta1 - if utilversion.MustParseGeneric(serverVersion.String()).LessThan(utilversion.MustParseGeneric("v1.21.0")) { - budgetV1Beta1 := &v1beta1.PodDisruptionBudget{ - TypeMeta: metav1.TypeMeta{ - Kind: "PodDisruptionBudget", - APIVersion: "policy/v1beta1", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: input.DeploymentName, - Namespace: input.Namespace, - }, - Spec: v1beta1.PodDisruptionBudgetSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "app": "nonstop", - }, - }, - MaxUnavailable: &intstr.IntOrString{ - Type: intstr.Int, - IntVal: 1, - StrVal: "1", - }, - }, - } - - AddPodDisruptionBudgetV1Beta1(ctx, AddPodDisruptionBudgetInputV1Beta1{ + budget := &policyv1.PodDisruptionBudget{ + TypeMeta: metav1.TypeMeta{ + Kind: "PodDisruptionBudget", + APIVersion: "policy/v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: input.DeploymentName, Namespace: input.Namespace, - ClientSet: workloadClient, - Budget: budgetV1Beta1, - }) - - // If Kubernetes >= 1.21.0 then we need to use PDB from v1 - } else { - budget := &policyv1.PodDisruptionBudget{ - TypeMeta: metav1.TypeMeta{ - Kind: "PodDisruptionBudget", - APIVersion: "policy/v1", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: input.DeploymentName, - Namespace: input.Namespace, - }, - Spec: policyv1.PodDisruptionBudgetSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "app": "nonstop", - }, - }, - MaxUnavailable: &intstr.IntOrString{ - Type: intstr.Int, - IntVal: 1, - StrVal: "1", + }, + Spec: policyv1.PodDisruptionBudgetSpec{ + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app": "nonstop", }, }, - } - - AddPodDisruptionBudget(ctx, AddPodDisruptionBudgetInput{ - Namespace: input.Namespace, - ClientSet: workloadClient, - Budget: budget, - }) + MaxUnavailable: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 1, + StrVal: "1", + }, + }, } + AddPodDisruptionBudget(ctx, AddPodDisruptionBudgetInput{ + Namespace: input.Namespace, + ClientSet: workloadClient, + Budget: budget, + }) + WaitForDeploymentsAvailable(ctx, WaitForDeploymentsAvailableInput{ Getter: input.WorkloadClusterProxy.GetClient(), Deployment: workloadDeployment, @@ -632,21 +593,3 @@ func AddPodDisruptionBudget(ctx context.Context, input AddPodDisruptionBudgetInp return fmt.Errorf("podDisruptionBudget needs to be successfully deployed: %v", err) }, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "podDisruptionBudget needs to be successfully deployed") } - -// TODO(oscr): Delete below when Kubernetes 1.20 support is dropped. - -type AddPodDisruptionBudgetInputV1Beta1 struct { - ClientSet *kubernetes.Clientset - Budget *v1beta1.PodDisruptionBudget - Namespace string -} - -func AddPodDisruptionBudgetV1Beta1(ctx context.Context, input AddPodDisruptionBudgetInputV1Beta1) { - Eventually(func() error { - budget, err := input.ClientSet.PolicyV1beta1().PodDisruptionBudgets(input.Namespace).Create(ctx, input.Budget, metav1.CreateOptions{}) - if budget != nil && err == nil { - return nil - } - return fmt.Errorf("podDisruptionBudget needs to be successfully deployed: %v", err) - }, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "podDisruptionBudget needs to be successfully deployed") -}