From 99efe55307ff32a41e32d21b23d519719820231a Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Sun, 18 Sep 2022 16:32:16 +0300 Subject: [PATCH] Upgrade PodDisruptionBudget API to v1 Requires k8s 1.21 --- controllers/kafkacluster_controller.go | 4 ++-- .../tests/kafkacluster_controller_kafka_test.go | 4 ++-- pkg/resources/envoy/poddisruptionbudget.go | 16 ++++++++-------- pkg/resources/kafka/poddisruptionbudget.go | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/controllers/kafkacluster_controller.go b/controllers/kafkacluster_controller.go index e86ea6924..3cb301ef7 100644 --- a/controllers/kafkacluster_controller.go +++ b/controllers/kafkacluster_controller.go @@ -24,7 +24,7 @@ import ( "github.com/go-logr/logr" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - policyv1beta1 "k8s.io/api/policy/v1beta1" + policyv1 "k8s.io/api/policy/v1" apiErrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ctrl "sigs.k8s.io/controller-runtime" @@ -397,7 +397,7 @@ func kafkaWatches(builder *ctrl.Builder) *ctrl.Builder { return builder. Owns(&corev1.Service{}). Owns(&corev1.ConfigMap{}). - Owns(&policyv1beta1.PodDisruptionBudget{}). + Owns(&policyv1.PodDisruptionBudget{}). Owns(&corev1.PersistentVolumeClaim{}). Owns(&corev1.Pod{}) } diff --git a/controllers/tests/kafkacluster_controller_kafka_test.go b/controllers/tests/kafkacluster_controller_kafka_test.go index a0b342017..35a37f6e6 100644 --- a/controllers/tests/kafkacluster_controller_kafka_test.go +++ b/controllers/tests/kafkacluster_controller_kafka_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - policyv1beta1 "k8s.io/api/policy/v1beta1" + policyv1 "k8s.io/api/policy/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" @@ -107,7 +107,7 @@ func expectKafkaPDB(kafkaCluster *v1beta1.KafkaCluster) { waitForClusterRunningState(kafkaCluster, kafkaCluster.Namespace) // get created PDB - pdb := policyv1beta1.PodDisruptionBudget{} + pdb := policyv1.PodDisruptionBudget{} Eventually(func() error { return k8sClient.Get(context.Background(), types.NamespacedName{ Namespace: kafkaCluster.Namespace, diff --git a/pkg/resources/envoy/poddisruptionbudget.go b/pkg/resources/envoy/poddisruptionbudget.go index 4ddbc4eb3..30793c5bb 100644 --- a/pkg/resources/envoy/poddisruptionbudget.go +++ b/pkg/resources/envoy/poddisruptionbudget.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" - policyv1beta1 "k8s.io/api/policy/v1beta1" + policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" envoyutils "github.com/banzaicloud/koperator/pkg/util/envoy" @@ -38,7 +38,7 @@ func (r *Reconciler) podDisruptionBudget(log logr.Logger, extListener v1beta1.Ex ingressConfig v1beta1.IngressConfig, ingressConfigName, defaultIngressConfigName string) runtime.Object { eListenerLabelName := util.ConstructEListenerLabelName(ingressConfigName, extListener.Name) - var deploymentName string = util.GenerateEnvoyResourceName(envoyutils.EnvoyDeploymentName, envoyutils.EnvoyDeploymentNameWithScope, + var deploymentName = util.GenerateEnvoyResourceName(envoyutils.EnvoyDeploymentName, envoyutils.EnvoyDeploymentNameWithScope, extListener, ingressConfig, ingressConfigName, r.KafkaCluster.GetName()) pdbConfig := r.KafkaCluster.Spec.EnvoyConfig.GetDistruptionBudget() @@ -47,18 +47,18 @@ func (r *Reconciler) podDisruptionBudget(log logr.Logger, extListener v1beta1.Ex // an improper regex will be used to verify the value budget := intstr.Parse(pdbConfig.DisruptionBudget.Budget) - var spec policyv1beta1.PodDisruptionBudgetSpec - var matchLabels map[string]string = labelsForEnvoyIngress(r.KafkaCluster.GetName(), eListenerLabelName) + var spec policyv1.PodDisruptionBudgetSpec + var matchLabels = labelsForEnvoyIngress(r.KafkaCluster.GetName(), eListenerLabelName) if pdbConfig.Stategy == MIN_AVAILABLE { - spec = policyv1beta1.PodDisruptionBudgetSpec{ + spec = policyv1.PodDisruptionBudgetSpec{ MinAvailable: &budget, Selector: &metav1.LabelSelector{ MatchLabels: matchLabels, }, } } else if pdbConfig.Stategy == MAX_UNAVAILABLE { - spec = policyv1beta1.PodDisruptionBudgetSpec{ + spec = policyv1.PodDisruptionBudgetSpec{ Selector: &metav1.LabelSelector{ MatchLabels: matchLabels, }, @@ -66,10 +66,10 @@ func (r *Reconciler) podDisruptionBudget(log logr.Logger, extListener v1beta1.Ex } } - return &policyv1beta1.PodDisruptionBudget{ + return &policyv1.PodDisruptionBudget{ TypeMeta: metav1.TypeMeta{ Kind: "PodDisruptionBudget", - APIVersion: "policy/v1beta1", + APIVersion: "policy/v1", }, ObjectMeta: templates.ObjectMetaWithAnnotations( deploymentName+"-pdb", diff --git a/pkg/resources/kafka/poddisruptionbudget.go b/pkg/resources/kafka/poddisruptionbudget.go index 7a45445f0..060347245 100644 --- a/pkg/resources/kafka/poddisruptionbudget.go +++ b/pkg/resources/kafka/poddisruptionbudget.go @@ -28,7 +28,7 @@ import ( "github.com/banzaicloud/koperator/pkg/resources/templates" "github.com/banzaicloud/koperator/pkg/util" - policyv1beta1 "k8s.io/api/policy/v1beta1" + policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -39,10 +39,10 @@ func (r *Reconciler) podDisruptionBudget(log logr.Logger) (runtime.Object, error return nil, err } - return &policyv1beta1.PodDisruptionBudget{ + return &policyv1.PodDisruptionBudget{ TypeMeta: metav1.TypeMeta{ Kind: "PodDisruptionBudget", - APIVersion: "policy/v1beta1", + APIVersion: "policy/v1", }, ObjectMeta: templates.ObjectMetaWithAnnotations( fmt.Sprintf("%s-pdb", r.KafkaCluster.Name), @@ -50,7 +50,7 @@ func (r *Reconciler) podDisruptionBudget(log logr.Logger) (runtime.Object, error r.KafkaCluster.Spec.ListenersConfig.GetServiceAnnotations(), r.KafkaCluster, ), - Spec: policyv1beta1.PodDisruptionBudgetSpec{ + Spec: policyv1.PodDisruptionBudgetSpec{ MinAvailable: &minAvailable, Selector: &metav1.LabelSelector{ MatchLabels: apiutil.LabelsForKafka(r.KafkaCluster.Name),