Skip to content

Commit d63021c

Browse files
authored
Merge pull request #10158 from Fedosin/drop_policy_v1beta1
🌱 Drop policy v1beta1 API support in the testing framework
2 parents 08fb445 + 06cd070 commit d63021c

File tree

1 file changed

+24
-81
lines changed

1 file changed

+24
-81
lines changed

test/framework/deployment_helpers.go

Lines changed: 24 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
appsv1 "k8s.io/api/apps/v1"
3535
corev1 "k8s.io/api/core/v1"
3636
policyv1 "k8s.io/api/policy/v1"
37-
"k8s.io/api/policy/v1beta1"
3837
apierrors "k8s.io/apimachinery/pkg/api/errors"
3938
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4039
"k8s.io/apimachinery/pkg/labels"
@@ -528,73 +527,35 @@ func DeployUnevictablePod(ctx context.Context, input DeployUnevictablePodInput)
528527
Deployment: workloadDeployment,
529528
})
530529

531-
// TODO(oscr): Remove when Kubernetes 1.20 support is dropped.
532-
serverVersion, err := workloadClient.ServerVersion()
533-
Expect(err).ToNot(HaveOccurred(), "Failed to get Kubernetes version for workload")
534-
535-
// If Kubernetes < 1.21.0 we need to use PDB from v1beta1
536-
if utilversion.MustParseGeneric(serverVersion.String()).LessThan(utilversion.MustParseGeneric("v1.21.0")) {
537-
budgetV1Beta1 := &v1beta1.PodDisruptionBudget{
538-
TypeMeta: metav1.TypeMeta{
539-
Kind: "PodDisruptionBudget",
540-
APIVersion: "policy/v1beta1",
541-
},
542-
ObjectMeta: metav1.ObjectMeta{
543-
Name: input.DeploymentName,
544-
Namespace: input.Namespace,
545-
},
546-
Spec: v1beta1.PodDisruptionBudgetSpec{
547-
Selector: &metav1.LabelSelector{
548-
MatchLabels: map[string]string{
549-
"app": "nonstop",
550-
},
551-
},
552-
MaxUnavailable: &intstr.IntOrString{
553-
Type: intstr.Int,
554-
IntVal: 1,
555-
StrVal: "1",
556-
},
557-
},
558-
}
559-
560-
AddPodDisruptionBudgetV1Beta1(ctx, AddPodDisruptionBudgetInputV1Beta1{
530+
budget := &policyv1.PodDisruptionBudget{
531+
TypeMeta: metav1.TypeMeta{
532+
Kind: "PodDisruptionBudget",
533+
APIVersion: "policy/v1",
534+
},
535+
ObjectMeta: metav1.ObjectMeta{
536+
Name: input.DeploymentName,
561537
Namespace: input.Namespace,
562-
ClientSet: workloadClient,
563-
Budget: budgetV1Beta1,
564-
})
565-
566-
// If Kubernetes >= 1.21.0 then we need to use PDB from v1
567-
} else {
568-
budget := &policyv1.PodDisruptionBudget{
569-
TypeMeta: metav1.TypeMeta{
570-
Kind: "PodDisruptionBudget",
571-
APIVersion: "policy/v1",
572-
},
573-
ObjectMeta: metav1.ObjectMeta{
574-
Name: input.DeploymentName,
575-
Namespace: input.Namespace,
576-
},
577-
Spec: policyv1.PodDisruptionBudgetSpec{
578-
Selector: &metav1.LabelSelector{
579-
MatchLabels: map[string]string{
580-
"app": "nonstop",
581-
},
582-
},
583-
MaxUnavailable: &intstr.IntOrString{
584-
Type: intstr.Int,
585-
IntVal: 1,
586-
StrVal: "1",
538+
},
539+
Spec: policyv1.PodDisruptionBudgetSpec{
540+
Selector: &metav1.LabelSelector{
541+
MatchLabels: map[string]string{
542+
"app": "nonstop",
587543
},
588544
},
589-
}
590-
591-
AddPodDisruptionBudget(ctx, AddPodDisruptionBudgetInput{
592-
Namespace: input.Namespace,
593-
ClientSet: workloadClient,
594-
Budget: budget,
595-
})
545+
MaxUnavailable: &intstr.IntOrString{
546+
Type: intstr.Int,
547+
IntVal: 1,
548+
StrVal: "1",
549+
},
550+
},
596551
}
597552

553+
AddPodDisruptionBudget(ctx, AddPodDisruptionBudgetInput{
554+
Namespace: input.Namespace,
555+
ClientSet: workloadClient,
556+
Budget: budget,
557+
})
558+
598559
WaitForDeploymentsAvailable(ctx, WaitForDeploymentsAvailableInput{
599560
Getter: input.WorkloadClusterProxy.GetClient(),
600561
Deployment: workloadDeployment,
@@ -632,21 +593,3 @@ func AddPodDisruptionBudget(ctx context.Context, input AddPodDisruptionBudgetInp
632593
return fmt.Errorf("podDisruptionBudget needs to be successfully deployed: %v", err)
633594
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "podDisruptionBudget needs to be successfully deployed")
634595
}
635-
636-
// TODO(oscr): Delete below when Kubernetes 1.20 support is dropped.
637-
638-
type AddPodDisruptionBudgetInputV1Beta1 struct {
639-
ClientSet *kubernetes.Clientset
640-
Budget *v1beta1.PodDisruptionBudget
641-
Namespace string
642-
}
643-
644-
func AddPodDisruptionBudgetV1Beta1(ctx context.Context, input AddPodDisruptionBudgetInputV1Beta1) {
645-
Eventually(func() error {
646-
budget, err := input.ClientSet.PolicyV1beta1().PodDisruptionBudgets(input.Namespace).Create(ctx, input.Budget, metav1.CreateOptions{})
647-
if budget != nil && err == nil {
648-
return nil
649-
}
650-
return fmt.Errorf("podDisruptionBudget needs to be successfully deployed: %v", err)
651-
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "podDisruptionBudget needs to be successfully deployed")
652-
}

0 commit comments

Comments
 (0)