Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor poddisruptionbudget reconciler #118

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Comment on lines +196 to +199
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question that raise a concern with me on this. If I understand PR will mean that we always create the PDB CR even if it is not being used. When it is not being used we mark it to be delete. Is it possible for us to get into an infinite loop here?

If we create a resource we should be reconciling any changes the user might make to that resource. By this logic if the resource is delete from the cluster we should check to see if that is the correct state, and with this change we would recreate the resource marking it for deletion causing the loop to start over. If we are not watching the resource for change causing use to not be affected by the infinite loop, then the question becomes how do we guarantee the resource is in the condition stated in the limitador CR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we "tag" object to be deleted, the reconciler will make sure it is deleted and if it exists, it will delete it. https://github.com/Kuadrant/kuadrant-operator/blob/main/pkg/reconcilers/base_reconciler.go#L110-L127

Objects tagged as deleted will never be created


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

return pdb
}

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