Update e2e tests to use the policy v1 api

This commit is contained in:
Morten Torkildsen 2021-03-08 22:00:47 -08:00 committed by Jordan Liggitt
parent 621aed4d32
commit 66e722765a
3 changed files with 49 additions and 48 deletions

View File

@ -27,6 +27,7 @@ import (
appsv1 "k8s.io/api/apps/v1" appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1" policyv1beta1 "k8s.io/api/policy/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -103,7 +104,7 @@ var _ = SIGDescribe("DisruptionController", func() {
// Since disruptionAllowed starts out 0, if we see it ever become positive, // Since disruptionAllowed starts out 0, if we see it ever become positive,
// that means the controller is working. // that means the controller is working.
err := wait.PollImmediate(framework.Poll, timeout, func() (bool, error) { err := wait.PollImmediate(framework.Poll, timeout, func() (bool, error) {
pdb, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Get(context.TODO(), defaultName, metav1.GetOptions{}) pdb, err := cs.PolicyV1().PodDisruptionBudgets(ns).Get(context.TODO(), defaultName, metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -121,17 +122,17 @@ var _ = SIGDescribe("DisruptionController", func() {
createPodsOrDie(cs, ns, 1) createPodsOrDie(cs, ns, 1)
waitForPodsOrDie(cs, ns, 1) waitForPodsOrDie(cs, ns, 1)
pod, _ := locateRunningPod(cs, ns) pod, _ := locateRunningPod(cs, ns)
updatePDBOrDie(cs, ns, defaultName, func(old *policyv1beta1.PodDisruptionBudget) *policyv1beta1.PodDisruptionBudget { updatePDBOrDie(cs, ns, defaultName, func(old *policyv1.PodDisruptionBudget) *policyv1.PodDisruptionBudget {
old.Status.DisruptedPods = make(map[string]metav1.Time) old.Status.DisruptedPods = make(map[string]metav1.Time)
old.Status.DisruptedPods[pod.Name] = metav1.NewTime(time.Now()) old.Status.DisruptedPods[pod.Name] = metav1.NewTime(time.Now())
return old return old
}, cs.PolicyV1beta1().PodDisruptionBudgets(ns).UpdateStatus) }, cs.PolicyV1().PodDisruptionBudgets(ns).UpdateStatus)
// fetch again to make sure the update from API was effective // fetch again to make sure the update from API was effective
updated := getPDBStatusOrDie(dc, ns, defaultName) updated := getPDBStatusOrDie(dc, ns, defaultName)
framework.ExpectHaveKey(updated.Status.DisruptedPods, pod.Name, "Expecting the DisruptedPods have %s", pod.Name) framework.ExpectHaveKey(updated.Status.DisruptedPods, pod.Name, "Expecting the DisruptedPods have %s", pod.Name)
ginkgo.By("Patching PodDisruptionBudget status") ginkgo.By("Patching PodDisruptionBudget status")
patched := patchPDBOrDie(cs, dc, ns, defaultName, func(old *policyv1beta1.PodDisruptionBudget) (bytes []byte, err error) { patched := patchPDBOrDie(cs, dc, ns, defaultName, func(old *policyv1.PodDisruptionBudget) (bytes []byte, err error) {
oldBytes, err := json.Marshal(old) oldBytes, err := json.Marshal(old)
framework.ExpectNoError(err, "failed to marshal JSON for old data") framework.ExpectNoError(err, "failed to marshal JSON for old data")
old.Status.DisruptedPods = make(map[string]metav1.Time) old.Status.DisruptedPods = make(map[string]metav1.Time)
@ -290,11 +291,11 @@ var _ = SIGDescribe("DisruptionController", func() {
gomega.Expect(err).Should(gomega.MatchError("Cannot evict pod as it would violate the pod's disruption budget.")) gomega.Expect(err).Should(gomega.MatchError("Cannot evict pod as it would violate the pod's disruption budget."))
ginkgo.By("Updating the pdb to allow a pod to be evicted") ginkgo.By("Updating the pdb to allow a pod to be evicted")
updatePDBOrDie(cs, ns, defaultName, func(pdb *policyv1beta1.PodDisruptionBudget) *policyv1beta1.PodDisruptionBudget { updatePDBOrDie(cs, ns, defaultName, func(pdb *policyv1.PodDisruptionBudget) *policyv1.PodDisruptionBudget {
newMinAvailable := intstr.FromInt(2) newMinAvailable := intstr.FromInt(2)
pdb.Spec.MinAvailable = &newMinAvailable pdb.Spec.MinAvailable = &newMinAvailable
return pdb return pdb
}, cs.PolicyV1beta1().PodDisruptionBudgets(ns).Update) }, cs.PolicyV1().PodDisruptionBudgets(ns).Update)
ginkgo.By("Trying to evict the same pod we tried earlier which should now be evictable") ginkgo.By("Trying to evict the same pod we tried earlier which should now be evictable")
waitForPodsOrDie(cs, ns, 3) waitForPodsOrDie(cs, ns, 3)
@ -303,7 +304,7 @@ var _ = SIGDescribe("DisruptionController", func() {
framework.ExpectNoError(err) // the eviction is now allowed framework.ExpectNoError(err) // the eviction is now allowed
ginkgo.By("Patching the pdb to disallow a pod to be evicted") ginkgo.By("Patching the pdb to disallow a pod to be evicted")
patchPDBOrDie(cs, dc, ns, defaultName, func(old *policyv1beta1.PodDisruptionBudget) (bytes []byte, err error) { patchPDBOrDie(cs, dc, ns, defaultName, func(old *policyv1.PodDisruptionBudget) (bytes []byte, err error) {
oldData, err := json.Marshal(old) oldData, err := json.Marshal(old)
framework.ExpectNoError(err, "failed to marshal JSON for old data") framework.ExpectNoError(err, "failed to marshal JSON for old data")
old.Spec.MinAvailable = nil old.Spec.MinAvailable = nil
@ -338,45 +339,45 @@ var _ = SIGDescribe("DisruptionController", func() {
}) })
func createPDBMinAvailableOrDie(cs kubernetes.Interface, ns string, name string, minAvailable intstr.IntOrString, labels map[string]string) { func createPDBMinAvailableOrDie(cs kubernetes.Interface, ns string, name string, minAvailable intstr.IntOrString, labels map[string]string) {
pdb := policyv1beta1.PodDisruptionBudget{ pdb := policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
Namespace: ns, Namespace: ns,
Labels: labels, Labels: labels,
}, },
Spec: policyv1beta1.PodDisruptionBudgetSpec{ Spec: policyv1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}}, Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
MinAvailable: &minAvailable, MinAvailable: &minAvailable,
}, },
} }
_, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Create(context.TODO(), &pdb, metav1.CreateOptions{}) _, err := cs.PolicyV1().PodDisruptionBudgets(ns).Create(context.TODO(), &pdb, metav1.CreateOptions{})
framework.ExpectNoError(err, "Waiting for the pdb to be created with minAvailable %d in namespace %s", minAvailable.IntVal, ns) framework.ExpectNoError(err, "Waiting for the pdb to be created with minAvailable %d in namespace %s", minAvailable.IntVal, ns)
waitForPdbToBeProcessed(cs, ns, name) waitForPdbToBeProcessed(cs, ns, name)
} }
func createPDBMaxUnavailableOrDie(cs kubernetes.Interface, ns string, name string, maxUnavailable intstr.IntOrString) { func createPDBMaxUnavailableOrDie(cs kubernetes.Interface, ns string, name string, maxUnavailable intstr.IntOrString) {
pdb := policyv1beta1.PodDisruptionBudget{ pdb := policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
Namespace: ns, Namespace: ns,
}, },
Spec: policyv1beta1.PodDisruptionBudgetSpec{ Spec: policyv1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}}, Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
MaxUnavailable: &maxUnavailable, MaxUnavailable: &maxUnavailable,
}, },
} }
_, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Create(context.TODO(), &pdb, metav1.CreateOptions{}) _, err := cs.PolicyV1().PodDisruptionBudgets(ns).Create(context.TODO(), &pdb, metav1.CreateOptions{})
framework.ExpectNoError(err, "Waiting for the pdb to be created with maxUnavailable %d in namespace %s", maxUnavailable.IntVal, ns) framework.ExpectNoError(err, "Waiting for the pdb to be created with maxUnavailable %d in namespace %s", maxUnavailable.IntVal, ns)
waitForPdbToBeProcessed(cs, ns, name) waitForPdbToBeProcessed(cs, ns, name)
} }
type updateFunc func(pdb *policyv1beta1.PodDisruptionBudget) *policyv1beta1.PodDisruptionBudget type updateFunc func(pdb *policyv1.PodDisruptionBudget) *policyv1.PodDisruptionBudget
type updateRestAPI func(ctx context.Context, podDisruptionBudget *policyv1beta1.PodDisruptionBudget, opts metav1.UpdateOptions) (*policyv1beta1.PodDisruptionBudget, error) type updateRestAPI func(ctx context.Context, podDisruptionBudget *policyv1.PodDisruptionBudget, opts metav1.UpdateOptions) (*policyv1.PodDisruptionBudget, error)
type patchFunc func(pdb *policyv1beta1.PodDisruptionBudget) ([]byte, error) type patchFunc func(pdb *policyv1.PodDisruptionBudget) ([]byte, error)
func updatePDBOrDie(cs kubernetes.Interface, ns string, name string, f updateFunc, api updateRestAPI) (updated *policyv1beta1.PodDisruptionBudget) { func updatePDBOrDie(cs kubernetes.Interface, ns string, name string, f updateFunc, api updateRestAPI) (updated *policyv1.PodDisruptionBudget) {
err := retry.RetryOnConflict(retry.DefaultRetry, func() error { err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
old, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Get(context.TODO(), name, metav1.GetOptions{}) old, err := cs.PolicyV1().PodDisruptionBudgets(ns).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil { if err != nil {
return err return err
} }
@ -392,12 +393,12 @@ func updatePDBOrDie(cs kubernetes.Interface, ns string, name string, f updateFun
return updated return updated
} }
func patchPDBOrDie(cs kubernetes.Interface, dc dynamic.Interface, ns string, name string, f patchFunc, subresources ...string) (updated *policyv1beta1.PodDisruptionBudget) { func patchPDBOrDie(cs kubernetes.Interface, dc dynamic.Interface, ns string, name string, f patchFunc, subresources ...string) (updated *policyv1.PodDisruptionBudget) {
err := retry.RetryOnConflict(retry.DefaultRetry, func() error { err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
old := getPDBStatusOrDie(dc, ns, name) old := getPDBStatusOrDie(dc, ns, name)
patchBytes, err := f(old) patchBytes, err := f(old)
framework.ExpectNoError(err) framework.ExpectNoError(err)
if updated, err = cs.PolicyV1beta1().PodDisruptionBudgets(ns).Patch(context.TODO(), old.Name, types.MergePatchType, patchBytes, metav1.PatchOptions{}, subresources...); err != nil { if updated, err = cs.PolicyV1().PodDisruptionBudgets(ns).Patch(context.TODO(), old.Name, types.MergePatchType, patchBytes, metav1.PatchOptions{}, subresources...); err != nil {
return err return err
} }
framework.ExpectNoError(err) framework.ExpectNoError(err)
@ -410,13 +411,13 @@ func patchPDBOrDie(cs kubernetes.Interface, dc dynamic.Interface, ns string, nam
} }
func deletePDBOrDie(cs kubernetes.Interface, ns string, name string) { func deletePDBOrDie(cs kubernetes.Interface, ns string, name string) {
err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Delete(context.TODO(), name, metav1.DeleteOptions{}) err := cs.PolicyV1().PodDisruptionBudgets(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
framework.ExpectNoError(err, "Deleting pdb in namespace %s", ns) framework.ExpectNoError(err, "Deleting pdb in namespace %s", ns)
waitForPdbToBeDeleted(cs, ns, name) waitForPdbToBeDeleted(cs, ns, name)
} }
func listPDBs(cs kubernetes.Interface, ns string, labelSelector string, count int, expectedPDBNames []string) { func listPDBs(cs kubernetes.Interface, ns string, labelSelector string, count int, expectedPDBNames []string) {
pdbList, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: labelSelector}) pdbList, err := cs.PolicyV1().PodDisruptionBudgets(ns).List(context.TODO(), metav1.ListOptions{LabelSelector: labelSelector})
framework.ExpectNoError(err, "Listing PDB set in namespace %s", ns) framework.ExpectNoError(err, "Listing PDB set in namespace %s", ns)
framework.ExpectEqual(len(pdbList.Items), count, "Expecting %d PDBs returned in namespace %s", count, ns) framework.ExpectEqual(len(pdbList.Items), count, "Expecting %d PDBs returned in namespace %s", count, ns)
@ -429,7 +430,7 @@ func listPDBs(cs kubernetes.Interface, ns string, labelSelector string, count in
func deletePDBCollection(cs kubernetes.Interface, ns string) { func deletePDBCollection(cs kubernetes.Interface, ns string) {
ginkgo.By("deleting a collection of PDBs") ginkgo.By("deleting a collection of PDBs")
err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{}) err := cs.PolicyV1().PodDisruptionBudgets(ns).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{})
framework.ExpectNoError(err, "Deleting PDB set in namespace %s", ns) framework.ExpectNoError(err, "Deleting PDB set in namespace %s", ns)
waitForPDBCollectionToBeDeleted(cs, ns) waitForPDBCollectionToBeDeleted(cs, ns)
@ -438,7 +439,7 @@ func deletePDBCollection(cs kubernetes.Interface, ns string) {
func waitForPDBCollectionToBeDeleted(cs kubernetes.Interface, ns string) { func waitForPDBCollectionToBeDeleted(cs kubernetes.Interface, ns string) {
ginkgo.By("Waiting for the PDB collection to be deleted") ginkgo.By("Waiting for the PDB collection to be deleted")
err := wait.PollImmediate(framework.Poll, schedulingTimeout, func() (bool, error) { err := wait.PollImmediate(framework.Poll, schedulingTimeout, func() (bool, error) {
pdbList, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).List(context.TODO(), metav1.ListOptions{}) pdbList, err := cs.PolicyV1().PodDisruptionBudgets(ns).List(context.TODO(), metav1.ListOptions{})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -564,7 +565,7 @@ func locateRunningPod(cs kubernetes.Interface, ns string) (pod *v1.Pod, err erro
func waitForPdbToBeProcessed(cs kubernetes.Interface, ns string, name string) { func waitForPdbToBeProcessed(cs kubernetes.Interface, ns string, name string) {
ginkgo.By("Waiting for the pdb to be processed") ginkgo.By("Waiting for the pdb to be processed")
err := wait.PollImmediate(framework.Poll, schedulingTimeout, func() (bool, error) { err := wait.PollImmediate(framework.Poll, schedulingTimeout, func() (bool, error) {
pdb, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Get(context.TODO(), name, metav1.GetOptions{}) pdb, err := cs.PolicyV1().PodDisruptionBudgets(ns).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -579,7 +580,7 @@ func waitForPdbToBeProcessed(cs kubernetes.Interface, ns string, name string) {
func waitForPdbToBeDeleted(cs kubernetes.Interface, ns string, name string) { func waitForPdbToBeDeleted(cs kubernetes.Interface, ns string, name string) {
ginkgo.By("Waiting for the pdb to be deleted") ginkgo.By("Waiting for the pdb to be deleted")
err := wait.PollImmediate(framework.Poll, schedulingTimeout, func() (bool, error) { err := wait.PollImmediate(framework.Poll, schedulingTimeout, func() (bool, error) {
_, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Get(context.TODO(), name, metav1.GetOptions{}) _, err := cs.PolicyV1().PodDisruptionBudgets(ns).Get(context.TODO(), name, metav1.GetOptions{})
if apierrors.IsNotFound(err) { if apierrors.IsNotFound(err) {
return true, nil // done return true, nil // done
} }
@ -594,7 +595,7 @@ func waitForPdbToBeDeleted(cs kubernetes.Interface, ns string, name string) {
func waitForPdbToObserveHealthyPods(cs kubernetes.Interface, ns string, healthyCount int32) { func waitForPdbToObserveHealthyPods(cs kubernetes.Interface, ns string, healthyCount int32) {
ginkgo.By("Waiting for the pdb to observed all healthy pods") ginkgo.By("Waiting for the pdb to observed all healthy pods")
err := wait.PollImmediate(framework.Poll, wait.ForeverTestTimeout, func() (bool, error) { err := wait.PollImmediate(framework.Poll, wait.ForeverTestTimeout, func() (bool, error) {
pdb, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Get(context.TODO(), "foo", metav1.GetOptions{}) pdb, err := cs.PolicyV1().PodDisruptionBudgets(ns).Get(context.TODO(), "foo", metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -606,8 +607,8 @@ func waitForPdbToObserveHealthyPods(cs kubernetes.Interface, ns string, healthyC
framework.ExpectNoError(err, "Waiting for the pdb in namespace %s to observed %d healthy pods", ns, healthyCount) framework.ExpectNoError(err, "Waiting for the pdb in namespace %s to observed %d healthy pods", ns, healthyCount)
} }
func getPDBStatusOrDie(dc dynamic.Interface, ns string, name string) *policyv1beta1.PodDisruptionBudget { func getPDBStatusOrDie(dc dynamic.Interface, ns string, name string) *policyv1.PodDisruptionBudget {
pdbStatusResource := policyv1beta1.SchemeGroupVersion.WithResource("poddisruptionbudgets") pdbStatusResource := policyv1.SchemeGroupVersion.WithResource("poddisruptionbudgets")
unstruct, err := dc.Resource(pdbStatusResource).Namespace(ns).Get(context.TODO(), name, metav1.GetOptions{}, "status") unstruct, err := dc.Resource(pdbStatusResource).Namespace(ns).Get(context.TODO(), name, metav1.GetOptions{}, "status")
framework.ExpectNoError(err) framework.ExpectNoError(err)
pdb, err := unstructuredToPDB(unstruct) pdb, err := unstructuredToPDB(unstruct)
@ -615,12 +616,12 @@ func getPDBStatusOrDie(dc dynamic.Interface, ns string, name string) *policyv1be
return pdb return pdb
} }
func unstructuredToPDB(obj *unstructured.Unstructured) (*policyv1beta1.PodDisruptionBudget, error) { func unstructuredToPDB(obj *unstructured.Unstructured) (*policyv1.PodDisruptionBudget, error) {
json, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj) json, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pdb := &policyv1beta1.PodDisruptionBudget{} pdb := &policyv1.PodDisruptionBudget{}
err = runtime.DecodeInto(clientscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), json, pdb) err = runtime.DecodeInto(clientscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), json, pdb)
pdb.Kind = "" pdb.Kind = ""
pdb.APIVersion = "" pdb.APIVersion = ""

View File

@ -30,7 +30,7 @@ import (
"time" "time"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1" policyv1 "k8s.io/api/policy/v1"
schedulingv1 "k8s.io/api/scheduling/v1" schedulingv1 "k8s.io/api/scheduling/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -1028,20 +1028,20 @@ func runDrainTest(f *framework.Framework, migSizes map[string]int, namespace str
ginkgo.By("Create a PodDisruptionBudget") ginkgo.By("Create a PodDisruptionBudget")
minAvailable := intstr.FromInt(numPods - pdbSize) minAvailable := intstr.FromInt(numPods - pdbSize)
pdb := &policyv1beta1.PodDisruptionBudget{ pdb := &policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "test_pdb", Name: "test_pdb",
Namespace: namespace, Namespace: namespace,
}, },
Spec: policyv1beta1.PodDisruptionBudgetSpec{ Spec: policyv1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{MatchLabels: labelMap}, Selector: &metav1.LabelSelector{MatchLabels: labelMap},
MinAvailable: &minAvailable, MinAvailable: &minAvailable,
}, },
} }
_, err = f.ClientSet.PolicyV1beta1().PodDisruptionBudgets(namespace).Create(context.TODO(), pdb, metav1.CreateOptions{}) _, err = f.ClientSet.PolicyV1().PodDisruptionBudgets(namespace).Create(context.TODO(), pdb, metav1.CreateOptions{})
defer func() { defer func() {
f.ClientSet.PolicyV1beta1().PodDisruptionBudgets(namespace).Delete(context.TODO(), pdb.Name, metav1.DeleteOptions{}) f.ClientSet.PolicyV1().PodDisruptionBudgets(namespace).Delete(context.TODO(), pdb.Name, metav1.DeleteOptions{})
}() }()
framework.ExpectNoError(err) framework.ExpectNoError(err)
@ -1881,7 +1881,7 @@ func addKubeSystemPdbs(f *framework.Framework) (func(), error) {
var finalErr error var finalErr error
for _, newPdbName := range newPdbs { for _, newPdbName := range newPdbs {
ginkgo.By(fmt.Sprintf("Delete PodDisruptionBudget %v", newPdbName)) ginkgo.By(fmt.Sprintf("Delete PodDisruptionBudget %v", newPdbName))
err := f.ClientSet.PolicyV1beta1().PodDisruptionBudgets("kube-system").Delete(context.TODO(), newPdbName, metav1.DeleteOptions{}) err := f.ClientSet.PolicyV1().PodDisruptionBudgets("kube-system").Delete(context.TODO(), newPdbName, metav1.DeleteOptions{})
if err != nil { if err != nil {
// log error, but attempt to remove other pdbs // log error, but attempt to remove other pdbs
klog.Errorf("Failed to delete PodDisruptionBudget %v, err: %v", newPdbName, err) klog.Errorf("Failed to delete PodDisruptionBudget %v, err: %v", newPdbName, err)
@ -1909,17 +1909,17 @@ func addKubeSystemPdbs(f *framework.Framework) (func(), error) {
labelMap := map[string]string{"k8s-app": pdbData.label} labelMap := map[string]string{"k8s-app": pdbData.label}
pdbName := fmt.Sprintf("test-pdb-for-%v", pdbData.label) pdbName := fmt.Sprintf("test-pdb-for-%v", pdbData.label)
minAvailable := intstr.FromInt(pdbData.minAvailable) minAvailable := intstr.FromInt(pdbData.minAvailable)
pdb := &policyv1beta1.PodDisruptionBudget{ pdb := &policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: pdbName, Name: pdbName,
Namespace: "kube-system", Namespace: "kube-system",
}, },
Spec: policyv1beta1.PodDisruptionBudgetSpec{ Spec: policyv1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{MatchLabels: labelMap}, Selector: &metav1.LabelSelector{MatchLabels: labelMap},
MinAvailable: &minAvailable, MinAvailable: &minAvailable,
}, },
} }
_, err := f.ClientSet.PolicyV1beta1().PodDisruptionBudgets("kube-system").Create(context.TODO(), pdb, metav1.CreateOptions{}) _, err := f.ClientSet.PolicyV1().PodDisruptionBudgets("kube-system").Create(context.TODO(), pdb, metav1.CreateOptions{})
newPdbs = append(newPdbs, pdbName) newPdbs = append(newPdbs, pdbName)
if err != nil { if err != nil {

View File

@ -28,7 +28,7 @@ import (
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
discoveryv1 "k8s.io/api/discovery/v1" discoveryv1 "k8s.io/api/discovery/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1" policyv1 "k8s.io/api/policy/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/fields"
@ -679,9 +679,9 @@ func (j *TestJig) AddRCAntiAffinity(rc *v1.ReplicationController) {
} }
// CreatePDB returns a PodDisruptionBudget for the given ReplicationController, or returns an error if a PodDisruptionBudget isn't ready // CreatePDB returns a PodDisruptionBudget for the given ReplicationController, or returns an error if a PodDisruptionBudget isn't ready
func (j *TestJig) CreatePDB(rc *v1.ReplicationController) (*policyv1beta1.PodDisruptionBudget, error) { func (j *TestJig) CreatePDB(rc *v1.ReplicationController) (*policyv1.PodDisruptionBudget, error) {
pdb := j.newPDBTemplate(rc) pdb := j.newPDBTemplate(rc)
newPdb, err := j.Client.PolicyV1beta1().PodDisruptionBudgets(j.Namespace).Create(context.TODO(), pdb, metav1.CreateOptions{}) newPdb, err := j.Client.PolicyV1().PodDisruptionBudgets(j.Namespace).Create(context.TODO(), pdb, metav1.CreateOptions{})
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create PDB %q %v", pdb.Name, err) return nil, fmt.Errorf("failed to create PDB %q %v", pdb.Name, err)
} }
@ -692,19 +692,19 @@ func (j *TestJig) CreatePDB(rc *v1.ReplicationController) (*policyv1beta1.PodDis
return newPdb, nil return newPdb, nil
} }
// newPDBTemplate returns the default policyv1beta1.PodDisruptionBudget object for // newPDBTemplate returns the default policyv1.PodDisruptionBudget object for
// this j, but does not actually create the PDB. The default PDB specifies a // this j, but does not actually create the PDB. The default PDB specifies a
// MinAvailable of N-1 and matches the pods created by the RC. // MinAvailable of N-1 and matches the pods created by the RC.
func (j *TestJig) newPDBTemplate(rc *v1.ReplicationController) *policyv1beta1.PodDisruptionBudget { func (j *TestJig) newPDBTemplate(rc *v1.ReplicationController) *policyv1.PodDisruptionBudget {
minAvailable := intstr.FromInt(int(*rc.Spec.Replicas) - 1) minAvailable := intstr.FromInt(int(*rc.Spec.Replicas) - 1)
pdb := &policyv1beta1.PodDisruptionBudget{ pdb := &policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Namespace: j.Namespace, Namespace: j.Namespace,
Name: j.Name, Name: j.Name,
Labels: j.Labels, Labels: j.Labels,
}, },
Spec: policyv1beta1.PodDisruptionBudgetSpec{ Spec: policyv1.PodDisruptionBudgetSpec{
MinAvailable: &minAvailable, MinAvailable: &minAvailable,
Selector: &metav1.LabelSelector{MatchLabels: j.Labels}, Selector: &metav1.LabelSelector{MatchLabels: j.Labels},
}, },
@ -762,7 +762,7 @@ func (j *TestJig) Scale(replicas int) error {
func (j *TestJig) waitForPdbReady() error { func (j *TestJig) waitForPdbReady() error {
timeout := 2 * time.Minute timeout := 2 * time.Minute
for start := time.Now(); time.Since(start) < timeout; time.Sleep(2 * time.Second) { for start := time.Now(); time.Since(start) < timeout; time.Sleep(2 * time.Second) {
pdb, err := j.Client.PolicyV1beta1().PodDisruptionBudgets(j.Namespace).Get(context.TODO(), j.Name, metav1.GetOptions{}) pdb, err := j.Client.PolicyV1().PodDisruptionBudgets(j.Namespace).Get(context.TODO(), j.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return err return err
} }