Skip to content

Commit

Permalink
Upgrade PodDisruptionBudget API to v1
Browse files Browse the repository at this point in the history
Requires k8s 1.21
  • Loading branch information
amuraru committed Sep 19, 2022
1 parent 65c4e1a commit 99efe55
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions controllers/kafkacluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/tests/kafkacluster_controller_kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions pkg/resources/envoy/poddisruptionbudget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand All @@ -47,29 +47,29 @@ 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,
},
MaxUnavailable: &budget,
}
}

return &policyv1beta1.PodDisruptionBudget{
return &policyv1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
Kind: "PodDisruptionBudget",
APIVersion: "policy/v1beta1",
APIVersion: "policy/v1",
},
ObjectMeta: templates.ObjectMetaWithAnnotations(
deploymentName+"-pdb",
Expand Down
8 changes: 4 additions & 4 deletions pkg/resources/kafka/poddisruptionbudget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -39,18 +39,18 @@ 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),
apiutil.MergeLabels(apiutil.LabelsForKafka(r.KafkaCluster.Name), r.KafkaCluster.Labels),
r.KafkaCluster.Spec.ListenersConfig.GetServiceAnnotations(),
r.KafkaCluster,
),
Spec: policyv1beta1.PodDisruptionBudgetSpec{
Spec: policyv1.PodDisruptionBudgetSpec{
MinAvailable: &minAvailable,
Selector: &metav1.LabelSelector{
MatchLabels: apiutil.LabelsForKafka(r.KafkaCluster.Name),
Expand Down

0 comments on commit 99efe55

Please sign in to comment.