Repository: spotahome/redis-operator
Pull request #343 (2022-01-11 12:48:56)

Bump kubernetes APIs policyV1 extensionsV1
Bump beta APIs to stable.
policyv1betav1 -> policyv1
extensionsv1betav1 -> extensionsv1

```
W0111 12:27:15.202735       1 warnings.go:70] policy/v1beta1 PodDisruptionBudget is deprecated in v1.21+, unavailable in v1.25+; use policy/v1 PodDisruptionBudget
```


Patch:
diff --git a/api/redisfailover/v1/register.go b/api/redisfailover/v1/register.go
index 68e3f3ef..3cbb33bc 100644
--- a/api/redisfailover/v1/register.go
+++ b/api/redisfailover/v1/register.go
@@ -3,7 +3,7 @@ package v1
 import (
 	"github.com/spotahome/redis-operator/api/redisfailover"
 
-	apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
+	apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/runtime/schema"
@@ -18,7 +18,7 @@ const (
 	RFKind       = "RedisFailover"
 	RFName       = "redisfailover"
 	RFNamePlural = "redisfailovers"
-	RFScope      = apiextensionsv1beta1.NamespaceScoped
+	RFScope      = apiextensionsv1.NamespaceScoped
 )
 
 // SchemeGroupVersion is group version used to register these objects
diff --git a/mocks/service/k8s/Services.go b/mocks/service/k8s/Services.go
index d1f9a3d7..0e70b8f7 100644
--- a/mocks/service/k8s/Services.go
+++ b/mocks/service/k8s/Services.go
@@ -7,10 +7,10 @@ import context "context"
 
 import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 import mock "github.com/stretchr/testify/mock"
+import policyv1 "k8s.io/api/policy/v1"
 import rbacv1 "k8s.io/api/rbac/v1"
 import redisfailoverv1 "github.com/spotahome/redis-operator/api/redisfailover/v1"
 import v1 "k8s.io/api/core/v1"
-import v1beta1 "k8s.io/api/policy/v1beta1"
 import watch "k8s.io/apimachinery/pkg/watch"
 
 // Services is an autogenerated mock type for the Services type
@@ -103,11 +103,11 @@ func (_m *Services) CreateOrUpdatePod(namespace string, pod *v1.Pod) error {
 }
 
 // CreateOrUpdatePodDisruptionBudget provides a mock function with given fields: namespace, podDisruptionBudget
-func (_m *Services) CreateOrUpdatePodDisruptionBudget(namespace string, podDisruptionBudget *v1beta1.PodDisruptionBudget) error {
+func (_m *Services) CreateOrUpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error {
 	ret := _m.Called(namespace, podDisruptionBudget)
 
 	var r0 error
-	if rf, ok := ret.Get(0).(func(string, *v1beta1.PodDisruptionBudget) error); ok {
+	if rf, ok := ret.Get(0).(func(string, *policyv1.PodDisruptionBudget) error); ok {
 		r0 = rf(namespace, podDisruptionBudget)
 	} else {
 		r0 = ret.Error(0)
@@ -187,11 +187,11 @@ func (_m *Services) CreatePod(namespace string, pod *v1.Pod) error {
 }
 
 // CreatePodDisruptionBudget provides a mock function with given fields: namespace, podDisruptionBudget
-func (_m *Services) CreatePodDisruptionBudget(namespace string, podDisruptionBudget *v1beta1.PodDisruptionBudget) error {
+func (_m *Services) CreatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error {
 	ret := _m.Called(namespace, podDisruptionBudget)
 
 	var r0 error
-	if rf, ok := ret.Get(0).(func(string, *v1beta1.PodDisruptionBudget) error); ok {
+	if rf, ok := ret.Get(0).(func(string, *policyv1.PodDisruptionBudget) error); ok {
 		r0 = rf(namespace, podDisruptionBudget)
 	} else {
 		r0 = ret.Error(0)
@@ -456,15 +456,15 @@ func (_m *Services) GetPod(namespace string, name string) (*v1.Pod, error) {
 }
 
 // GetPodDisruptionBudget provides a mock function with given fields: namespace, name
-func (_m *Services) GetPodDisruptionBudget(namespace string, name string) (*v1beta1.PodDisruptionBudget, error) {
+func (_m *Services) GetPodDisruptionBudget(namespace string, name string) (*policyv1.PodDisruptionBudget, error) {
 	ret := _m.Called(namespace, name)
 
-	var r0 *v1beta1.PodDisruptionBudget
-	if rf, ok := ret.Get(0).(func(string, string) *v1beta1.PodDisruptionBudget); ok {
+	var r0 *policyv1.PodDisruptionBudget
+	if rf, ok := ret.Get(0).(func(string, string) *policyv1.PodDisruptionBudget); ok {
 		r0 = rf(namespace, name)
 	} else {
 		if ret.Get(0) != nil {
-			r0 = ret.Get(0).(*v1beta1.PodDisruptionBudget)
+			r0 = ret.Get(0).(*policyv1.PodDisruptionBudget)
 		}
 	}
 
@@ -797,11 +797,11 @@ func (_m *Services) UpdatePod(namespace string, pod *v1.Pod) error {
 }
 
 // UpdatePodDisruptionBudget provides a mock function with given fields: namespace, podDisruptionBudget
-func (_m *Services) UpdatePodDisruptionBudget(namespace string, podDisruptionBudget *v1beta1.PodDisruptionBudget) error {
+func (_m *Services) UpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error {
 	ret := _m.Called(namespace, podDisruptionBudget)
 
 	var r0 error
-	if rf, ok := ret.Get(0).(func(string, *v1beta1.PodDisruptionBudget) error); ok {
+	if rf, ok := ret.Get(0).(func(string, *policyv1.PodDisruptionBudget) error); ok {
 		r0 = rf(namespace, podDisruptionBudget)
 	} else {
 		r0 = ret.Error(0)
diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go
index fe228b12..13da90ff 100644
--- a/operator/redisfailover/service/generator.go
+++ b/operator/redisfailover/service/generator.go
@@ -8,7 +8,7 @@ import (
 	appsv1 "k8s.io/api/apps/v1"
 	v1 "k8s.io/api/apps/v1"
 	corev1 "k8s.io/api/core/v1"
-	policyv1beta1 "k8s.io/api/policy/v1beta1"
+	policyv1 "k8s.io/api/policy/v1"
 	"k8s.io/apimachinery/pkg/api/resource"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/util/intstr"
@@ -508,15 +508,15 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st
 	return sd
 }
 
-func generatePodDisruptionBudget(name string, namespace string, labels map[string]string, ownerRefs []metav1.OwnerReference, minAvailable intstr.IntOrString) *policyv1beta1.PodDisruptionBudget {
-	return &policyv1beta1.PodDisruptionBudget{
+func generatePodDisruptionBudget(name string, namespace string, labels map[string]string, ownerRefs []metav1.OwnerReference, minAvailable intstr.IntOrString) *policyv1.PodDisruptionBudget {
+	return &policyv1.PodDisruptionBudget{
 		ObjectMeta: metav1.ObjectMeta{
 			Name:            name,
 			Namespace:       namespace,
 			Labels:          labels,
 			OwnerReferences: ownerRefs,
 		},
-		Spec: policyv1beta1.PodDisruptionBudgetSpec{
+		Spec: policyv1.PodDisruptionBudgetSpec{
 			MinAvailable: &minAvailable,
 			Selector: &metav1.LabelSelector{
 				MatchLabels: labels,
diff --git a/service/k8s/poddisruptionbudget.go b/service/k8s/poddisruptionbudget.go
index cc658b5a..0f7af87a 100644
--- a/service/k8s/poddisruptionbudget.go
+++ b/service/k8s/poddisruptionbudget.go
@@ -3,7 +3,7 @@ package k8s
 import (
 	"context"
 
-	policyv1beta1 "k8s.io/api/policy/v1beta1"
+	policyv1 "k8s.io/api/policy/v1"
 	"k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/client-go/kubernetes"
@@ -13,10 +13,10 @@ import (
 
 // PodDisruptionBudget the ServiceAccount service that knows how to interact with k8s to manage them
 type PodDisruptionBudget interface {
-	GetPodDisruptionBudget(namespace string, name string) (*policyv1beta1.PodDisruptionBudget, error)
-	CreatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1beta1.PodDisruptionBudget) error
-	UpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1beta1.PodDisruptionBudget) error
-	CreateOrUpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1beta1.PodDisruptionBudget) error
+	GetPodDisruptionBudget(namespace string, name string) (*policyv1.PodDisruptionBudget, error)
+	CreatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error
+	UpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error
+	CreateOrUpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error
 	DeletePodDisruptionBudget(namespace string, name string) error
 }
 
@@ -35,16 +35,16 @@ func NewPodDisruptionBudgetService(kubeClient kubernetes.Interface, logger log.L
 	}
 }
 
-func (p *PodDisruptionBudgetService) GetPodDisruptionBudget(namespace string, name string) (*policyv1beta1.PodDisruptionBudget, error) {
-	podDisruptionBudget, err := p.kubeClient.PolicyV1beta1().PodDisruptionBudgets(namespace).Get(context.TODO(), name, metav1.GetOptions{})
+func (p *PodDisruptionBudgetService) GetPodDisruptionBudget(namespace string, name string) (*policyv1.PodDisruptionBudget, error) {
+	podDisruptionBudget, err := p.kubeClient.PolicyV1().PodDisruptionBudgets(namespace).Get(context.TODO(), name, metav1.GetOptions{})
 	if err != nil {
 		return nil, err
 	}
 	return podDisruptionBudget, nil
 }
 
-func (p *PodDisruptionBudgetService) CreatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1beta1.PodDisruptionBudget) error {
-	_, err := p.kubeClient.PolicyV1beta1().PodDisruptionBudgets(namespace).Create(context.TODO(), podDisruptionBudget, metav1.CreateOptions{})
+func (p *PodDisruptionBudgetService) CreatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error {
+	_, err := p.kubeClient.PolicyV1().PodDisruptionBudgets(namespace).Create(context.TODO(), podDisruptionBudget, metav1.CreateOptions{})
 	if err != nil {
 		return err
 	}
@@ -52,8 +52,8 @@ func (p *PodDisruptionBudgetService) CreatePodDisruptionBudget(namespace string,
 	return nil
 }
 
-func (p *PodDisruptionBudgetService) UpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1beta1.PodDisruptionBudget) error {
-	_, err := p.kubeClient.PolicyV1beta1().PodDisruptionBudgets(namespace).Update(context.TODO(), podDisruptionBudget, metav1.UpdateOptions{})
+func (p *PodDisruptionBudgetService) UpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error {
+	_, err := p.kubeClient.PolicyV1().PodDisruptionBudgets(namespace).Update(context.TODO(), podDisruptionBudget, metav1.UpdateOptions{})
 	if err != nil {
 		return err
 	}
@@ -61,7 +61,7 @@ func (p *PodDisruptionBudgetService) UpdatePodDisruptionBudget(namespace string,
 	return nil
 }
 
-func (p *PodDisruptionBudgetService) CreateOrUpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1beta1.PodDisruptionBudget) error {
+func (p *PodDisruptionBudgetService) CreateOrUpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error {
 	storedPodDisruptionBudget, err := p.GetPodDisruptionBudget(namespace, podDisruptionBudget.Name)
 	if err != nil {
 		// If no resource we need to create.


Test patch:
diff --git a/service/k8s/poddisruptionbudget_test.go b/service/k8s/poddisruptionbudget_test.go
index 1bf8ed43..d9a11c58 100644
--- a/service/k8s/poddisruptionbudget_test.go
+++ b/service/k8s/poddisruptionbudget_test.go
@@ -5,7 +5,7 @@ import (
 	"testing"
 
 	"github.com/stretchr/testify/assert"
-	policyv1beta1 "k8s.io/api/policy/v1beta1"
+	policyv1 "k8s.io/api/policy/v1"
 	kubeerrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
@@ -18,10 +18,10 @@ import (
 )
 
 var (
-	podDisruptionBudgetsGroup = schema.GroupVersionResource{Group: "policy", Version: "v1beta1", Resource: "poddisruptionbudgets"}
+	podDisruptionBudgetsGroup = schema.GroupVersionResource{Group: "policy", Version: "v1", Resource: "poddisruptionbudgets"}
 )
 
-func newPodDisruptionBudgetUpdateAction(ns string, podDisruptionBudget *policyv1beta1.PodDisruptionBudget) kubetesting.UpdateActionImpl {
+func newPodDisruptionBudgetUpdateAction(ns string, podDisruptionBudget *policyv1.PodDisruptionBudget) kubetesting.UpdateActionImpl {
 	return kubetesting.NewUpdateAction(podDisruptionBudgetsGroup, ns, podDisruptionBudget)
 }
 
@@ -29,12 +29,12 @@ func newPodDisruptionBudgetGetAction(ns, name string) kubetesting.GetActionImpl
 	return kubetesting.NewGetAction(podDisruptionBudgetsGroup, ns, name)
 }
 
-func newPodDisruptionBudgetCreateAction(ns string, podDisruptionBudget *policyv1beta1.PodDisruptionBudget) kubetesting.CreateActionImpl {
+func newPodDisruptionBudgetCreateAction(ns string, podDisruptionBudget *policyv1.PodDisruptionBudget) kubetesting.CreateActionImpl {
 	return kubetesting.NewCreateAction(podDisruptionBudgetsGroup, ns, podDisruptionBudget)
 }
 
 func TestPodDisruptionBudgetServiceGetCreateOrUpdate(t *testing.T) {
-	testPodDisruptionBudget := &policyv1beta1.PodDisruptionBudget{
+	testPodDisruptionBudget := &policyv1.PodDisruptionBudget{
 		ObjectMeta: metav1.ObjectMeta{
 			Name:            "testpodDisruptionBudget1",
 			ResourceVersion: "10",
@@ -45,8 +45,8 @@ func TestPodDisruptionBudgetServiceGetCreateOrUpdate(t *testing.T) {
 
 	tests := []struct {
 		name                         string
-		podDisruptionBudget          *policyv1beta1.PodDisruptionBudget
-		getPodDisruptionBudgetResult *policyv1beta1.PodDisruptionBudget
+		podDisruptionBudget          *policyv1.PodDisruptionBudget
+		getPodDisruptionBudgetResult *policyv1.PodDisruptionBudget
 		errorOnGet                   error
 		errorOnCreation              error
 		expActions                   []kubetesting.Action