use-case-and-architecture/ai_computing_force_scheduling/knets_pkg/algo/toleration.go
Weisen Pan a877aed45f AI-based CFN Traffic Control and Computer Force Scheduling
Change-Id: I16cd7730c1e0732253ac52f51010f6b813295aa7
2023-11-03 00:09:19 -07:00

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
}