Skip to content

Commit

Permalink
chore: drop policy v1beta1 API support in the testing framework
Browse files Browse the repository at this point in the history
This API was deprecated in v1.21 and completely removed in v1.25.
We can safely remove its support in the test framework.
  • Loading branch information
Fedosin committed Feb 15, 2024
1 parent 08fb445 commit 06cd070
Showing 1 changed file with 24 additions and 81 deletions.
105 changes: 24 additions & 81 deletions test/framework/deployment_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
}

0 comments on commit 06cd070

Please sign in to comment.