Skip to content

Commit

Permalink
Update Kafka PDB to use live Pods instead of the CR Spec
Browse files Browse the repository at this point in the history
  • Loading branch information
alungu committed Feb 11, 2022
1 parent 4ee4330 commit 3a3f558
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/resources/kafka/poddisruptionbudget.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
package kafka

import (
"context"
"fmt"
"math"
"strconv"
"strings"

"emperror.dev/errors"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/banzaicloud/koperator/pkg/resources/templates"
"github.com/banzaicloud/koperator/pkg/util"
"github.com/banzaicloud/koperator/pkg/util/kafka"
Expand Down Expand Up @@ -73,8 +78,16 @@ func (r *Reconciler) computeMinAvailable(log logr.Logger) (intstr.IntOrString, e
Max(1, brokers-brokers*percentage) - for a percentage budget
*/

podList := &corev1.PodList{}
matchingLabels := client.MatchingLabels(kafka.LabelsForKafka(r.KafkaCluster.Name))
err := r.Client.List(context.TODO(), podList, client.ListOption(client.InNamespace(r.KafkaCluster.Namespace)), client.ListOption(matchingLabels))
if err != nil {
return intstr.FromInt(-1), errors.WrapIf(err, "failed to reconcile resource")
}

// number of brokers in the KafkaCluster
brokers := len(r.KafkaCluster.Spec.Brokers)
brokers := len(podList.Items)

// configured budget in the KafkaCluster
disruptionBudget := r.KafkaCluster.Spec.DisruptionBudget.Budget
Expand Down

0 comments on commit 3a3f558

Please sign in to comment.