Skip to content

Commit

Permalink
Merge pull request #118 from Kuadrant/refactor-pdb-reconciler
Browse files Browse the repository at this point in the history
Refactor poddisruptionbudget reconciler
  • Loading branch information
eguzki authored Dec 4, 2023
2 parents 583c7a8 + 6c01727 commit e2d7ae1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
20 changes: 0 additions & 20 deletions controllers/limitador_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
v1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -138,25 +137,6 @@ func (r *LimitadorReconciler) reconcilePdb(ctx context.Context, limitadorObj *li
if err != nil {
return err
}
if limitadorObj.Spec.PodDisruptionBudget == nil {
pdb := &policyv1.PodDisruptionBudget{}
if err := r.GetResource(ctx,
types.NamespacedName{
Namespace: limitadorObj.Namespace,
Name: limitador.PodDisruptionBudgetName(limitadorObj),
}, pdb); err != nil {
if errors.IsNotFound(err) {
return nil
}
return err
}
if pdb.ObjectMeta.DeletionTimestamp == nil {
if err = r.DeleteResource(ctx, pdb); err != nil {
return err
}
}
return nil
}

pdb := limitador.PodDisruptionBudget(limitadorObj)
if err := limitador.ValidatePDB(pdb); err != nil {
Expand Down
14 changes: 11 additions & 3 deletions pkg/limitador/k8s_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,28 @@ func DeploymentName(limitadorObj *limitadorv1alpha1.Limitador) string {
}

func PodDisruptionBudget(limitadorObj *limitadorv1alpha1.Limitador) *policyv1.PodDisruptionBudget {
return &policyv1.PodDisruptionBudget{
pdb := &policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: PodDisruptionBudgetName(limitadorObj),
Namespace: limitadorObj.ObjectMeta.Namespace,
Labels: Labels(limitadorObj),
},
Spec: policyv1.PodDisruptionBudgetSpec{
MaxUnavailable: limitadorObj.Spec.PodDisruptionBudget.MaxUnavailable,
MinAvailable: limitadorObj.Spec.PodDisruptionBudget.MinAvailable,
Selector: &metav1.LabelSelector{
MatchLabels: Labels(limitadorObj),
},
},
}

if limitadorObj.Spec.PodDisruptionBudget == nil {
helpers.TagObjectToDelete(pdb)
return pdb
}

pdb.Spec.MaxUnavailable = limitadorObj.Spec.PodDisruptionBudget.MaxUnavailable
pdb.Spec.MinAvailable = limitadorObj.Spec.PodDisruptionBudget.MinAvailable

return pdb
}

func PodDisruptionBudgetName(limitadorObj *limitadorv1alpha1.Limitador) string {
Expand Down

0 comments on commit e2d7ae1

Please sign in to comment.