a877aed45f
Change-Id: I16cd7730c1e0732253ac52f51010f6b813295aa7
37 lines
911 B
Go
37 lines
911 B
Go
package algo
|
|
|
|
// Author: Weisen Pan
|
|
// Date: 2023-10-24
|
|
|
|
|
|
import (
|
|
corev1 "k8s.io/api/core/v1"
|
|
)
|
|
|
|
// TolerationQueue represents a queue of Kubernetes Pods with tolerations.
|
|
type TolerationQueue struct {
|
|
pods []*corev1.Pod
|
|
}
|
|
|
|
// NewTolerationQueue creates a new TolerationQueue with the given list of Pods.
|
|
func NewTolerationQueue(pods []*corev1.Pod) *TolerationQueue {
|
|
return &TolerationQueue{
|
|
pods: pods,
|
|
}
|
|
}
|
|
|
|
// Len returns the number of Pods in the TolerationQueue.
|
|
func (tol *TolerationQueue) Len() int {
|
|
return len(tol.pods)
|
|
}
|
|
|
|
// Swap swaps the Pods at the given indices in the TolerationQueue.
|
|
func (tol *TolerationQueue) Swap(i, j int) {
|
|
tol.pods[i], tol.pods[j] = tol.pods[j], tol.pods[i]
|
|
}
|
|
|
|
// Less compares Pods at the given indices based on the existence of tolerations in their specifications.
|
|
func (tol *TolerationQueue) Less(i, j int) bool {
|
|
return tol.pods[i].Spec.Tolerations != nil
|
|
}
|