-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SliceGwReconciler): Add PodDisruptionBudget logic
The SliceGwReconciler should handle the lifecycle of PodDisruptionBudget objects that match the slice gateway deployments. Signed-off-by: Bhargav Ravuri <[email protected]>
- Loading branch information
1 parent
051dbde
commit 210cff2
Showing
5 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package slicegateway | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/kubeslice/worker-operator/controllers" | ||
webhook "github.com/kubeslice/worker-operator/pkg/webhook/pod" | ||
policyv1 "k8s.io/api/policy/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// formatPodDisruptionBudget creates the PodDisruptionBudget's manifest with labels matching the slice gateway pods. | ||
func formatPodDisruptionBudget(slice, sliceGateway string, minAvailable intstr.IntOrString) *policyv1.PodDisruptionBudget { | ||
return &policyv1.PodDisruptionBudget{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: fmt.Sprintf("%s-pdb", sliceGateway), | ||
Namespace: controllers.ControlPlaneNamespace, | ||
Labels: map[string]string{ | ||
controllers.ApplicationNamespaceSelectorLabelKey: slice, | ||
controllers.SliceGatewaySelectorLabelKey: sliceGateway, | ||
}, | ||
}, | ||
Spec: policyv1.PodDisruptionBudgetSpec{ | ||
MinAvailable: &minAvailable, | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
controllers.ApplicationNamespaceSelectorLabelKey: slice, | ||
webhook.PodInjectLabelKey: "slicegateway", | ||
controllers.SliceGatewaySelectorLabelKey: sliceGateway, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// listPodDisruptionBudgetForSliceGateway lists the PodDisruptionBudget objects that match the slice gateway pods. | ||
func listPodDisruptionBudgetForSliceGateway(ctx context.Context, kubeClient client.Client, | ||
sliceName, sliceGwName string) ([]policyv1.PodDisruptionBudget, error) { | ||
// Options for listing the PDBs that match the slice and slice gateway | ||
listOpts := []client.ListOption{ | ||
client.MatchingLabels(map[string]string{ | ||
controllers.ApplicationNamespaceSelectorLabelKey: sliceName, | ||
controllers.SliceGatewaySelectorLabelKey: sliceGwName, | ||
}), | ||
client.InNamespace(controllers.ControlPlaneNamespace), | ||
} | ||
|
||
// List PDBs from cluster that match the slice and slice gateway | ||
pdbList := policyv1.PodDisruptionBudgetList{} | ||
if err := kubeClient.List(ctx, &pdbList, listOpts...); err != nil { | ||
return nil, err | ||
} | ||
|
||
return pdbList.Items, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.