From a7ad94f93b539aac239a52ab441dc5f5cca336d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Skocze=C5=84?= Date: Mon, 22 Jul 2024 11:56:01 +0000 Subject: [PATCH] Unexport podRef in scheduling queue's nominator --- pkg/scheduler/internal/queue/nominator.go | 40 +++++++++---------- .../internal/queue/scheduling_queue.go | 4 +- .../internal/queue/scheduling_queue_test.go | 28 ++++++------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/pkg/scheduler/internal/queue/nominator.go b/pkg/scheduler/internal/queue/nominator.go index e75212ee043..59f7eaa4802 100644 --- a/pkg/scheduler/internal/queue/nominator.go +++ b/pkg/scheduler/internal/queue/nominator.go @@ -46,7 +46,7 @@ type nominator struct { // nominatedPods is a map keyed by a node name and the value is a list of // pods which are nominated to run on the node. These are pods which can be in // the activeQ or unschedulablePods. - nominatedPods map[string][]PodRef + nominatedPods map[string][]podRef // nominatedPodToNode is map keyed by a Pod UID to the node name where it is // nominated. nominatedPodToNode map[types.UID]string @@ -55,7 +55,7 @@ type nominator struct { func newPodNominator(podLister listersv1.PodLister) *nominator { return &nominator{ podLister: podLister, - nominatedPods: make(map[string][]PodRef), + nominatedPods: make(map[string][]podRef), nominatedPodToNode: make(map[types.UID]string), } } @@ -100,12 +100,12 @@ func (npm *nominator) addNominatedPodUnlocked(logger klog.Logger, pi *framework. npm.nominatedPodToNode[pi.Pod.UID] = nodeName for _, np := range npm.nominatedPods[nodeName] { - if np.UID == pi.Pod.UID { - logger.V(4).Info("Pod already exists in the nominator", "pod", np.UID) + if np.uid == pi.Pod.UID { + logger.V(4).Info("Pod already exists in the nominator", "pod", np.uid) return } } - npm.nominatedPods[nodeName] = append(npm.nominatedPods[nodeName], PodToRef(pi.Pod)) + npm.nominatedPods[nodeName] = append(npm.nominatedPods[nodeName], podToRef(pi.Pod)) } // UpdateNominatedPod updates the with . @@ -148,7 +148,7 @@ func (npm *nominator) deleteUnlocked(p *v1.Pod) { return } for i, np := range npm.nominatedPods[nnn] { - if np.UID == p.UID { + if np.uid == p.UID { npm.nominatedPods[nnn] = append(npm.nominatedPods[nnn][:i], npm.nominatedPods[nnn][i+1:]...) if len(npm.nominatedPods[nnn]) == 0 { delete(npm.nominatedPods, nnn) @@ -159,7 +159,7 @@ func (npm *nominator) deleteUnlocked(p *v1.Pod) { delete(npm.nominatedPodToNode, p.UID) } -func (npm *nominator) nominatedPodsForNode(nodeName string) []PodRef { +func (npm *nominator) nominatedPodsForNode(nodeName string) []podRef { npm.nLock.RLock() defer npm.nLock.RUnlock() return slices.Clone(npm.nominatedPods[nodeName]) @@ -170,26 +170,26 @@ func nominatedNodeName(pod *v1.Pod) string { return pod.Status.NominatedNodeName } -type PodRef struct { - Name string - Namespace string - UID types.UID +type podRef struct { + name string + namespace string + uid types.UID } -func PodToRef(pod *v1.Pod) PodRef { - return PodRef{ - Name: pod.Name, - Namespace: pod.Namespace, - UID: pod.UID, +func podToRef(pod *v1.Pod) podRef { + return podRef{ + name: pod.Name, + namespace: pod.Namespace, + uid: pod.UID, } } -func (np PodRef) ToPod() *v1.Pod { +func (np podRef) toPod() *v1.Pod { return &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ - Name: np.Name, - Namespace: np.Namespace, - UID: np.UID, + Name: np.name, + Namespace: np.namespace, + UID: np.uid, }, } } diff --git a/pkg/scheduler/internal/queue/scheduling_queue.go b/pkg/scheduler/internal/queue/scheduling_queue.go index 6fb21c208db..b4fb251f742 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue.go +++ b/pkg/scheduler/internal/queue/scheduling_queue.go @@ -1174,8 +1174,8 @@ func (p *PriorityQueue) PendingPods() ([]*v1.Pod, string) { } // Note: this function assumes the caller locks both p.lock.RLock and p.activeQ.getLock().RLock. -func (p *PriorityQueue) nominatedPodToInfo(np PodRef) *framework.PodInfo { - pod := np.ToPod() +func (p *PriorityQueue) nominatedPodToInfo(np podRef) *framework.PodInfo { + pod := np.toPod() pInfoLookup := newQueuedPodInfoForLookup(pod) queuedPodInfo, exists := p.activeQ.unlocked().Get(pInfoLookup) diff --git a/pkg/scheduler/internal/queue/scheduling_queue_test.go b/pkg/scheduler/internal/queue/scheduling_queue_test.go index c00a3006d29..9a6e4cc1e9b 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue_test.go +++ b/pkg/scheduler/internal/queue/scheduling_queue_test.go @@ -83,7 +83,7 @@ var ( ) nominatorCmpOpts = []cmp.Option{ - cmp.AllowUnexported(nominator{}), + cmp.AllowUnexported(nominator{}, podRef{}), cmpopts.IgnoreFields(nominator{}, "podLister", "nLock"), } @@ -129,8 +129,8 @@ func TestPriorityQueue_Add(t *testing.T) { medPriorityPodInfo.Pod.UID: "node1", unschedulablePodInfo.Pod.UID: "node1", }, - nominatedPods: map[string][]PodRef{ - "node1": {PodToRef(medPriorityPodInfo.Pod), PodToRef(unschedulablePodInfo.Pod)}, + nominatedPods: map[string][]podRef{ + "node1": {podToRef(medPriorityPodInfo.Pod), podToRef(unschedulablePodInfo.Pod)}, }, } if diff := cmp.Diff(q.nominator, expectedNominatedPods, nominatorCmpOpts...); diff != "" { @@ -2118,10 +2118,10 @@ func TestPriorityQueue_UpdateNominatedPodForNode(t *testing.T) { highPriorityPodInfo.Pod.UID: "node2", unschedulablePodInfo.Pod.UID: "node5", }, - nominatedPods: map[string][]PodRef{ - "node1": {PodToRef(medPriorityPodInfo.Pod)}, - "node2": {PodToRef(highPriorityPodInfo.Pod)}, - "node5": {PodToRef(unschedulablePodInfo.Pod)}, + nominatedPods: map[string][]podRef{ + "node1": {podToRef(medPriorityPodInfo.Pod)}, + "node2": {podToRef(highPriorityPodInfo.Pod)}, + "node5": {podToRef(unschedulablePodInfo.Pod)}, }, } if diff := cmp.Diff(q.nominator, expectedNominatedPods, nominatorCmpOpts...); diff != "" { @@ -2143,10 +2143,10 @@ func TestPriorityQueue_UpdateNominatedPodForNode(t *testing.T) { highPriorityPodInfo.Pod.UID: "node4", unschedulablePodInfo.Pod.UID: "node5", }, - nominatedPods: map[string][]PodRef{ - "node1": {PodToRef(medPriorityPodInfo.Pod)}, - "node4": {PodToRef(highPriorityPodInfo.Pod)}, - "node5": {PodToRef(unschedulablePodInfo.Pod)}, + nominatedPods: map[string][]podRef{ + "node1": {podToRef(medPriorityPodInfo.Pod)}, + "node4": {podToRef(highPriorityPodInfo.Pod)}, + "node5": {podToRef(unschedulablePodInfo.Pod)}, }, } if diff := cmp.Diff(q.nominator, expectedNominatedPods, nominatorCmpOpts...); diff != "" { @@ -2176,9 +2176,9 @@ func TestPriorityQueue_UpdateNominatedPodForNode(t *testing.T) { medPriorityPodInfo.Pod.UID: "node1", unschedulablePodInfo.Pod.UID: "node5", }, - nominatedPods: map[string][]PodRef{ - "node1": {PodToRef(medPriorityPodInfo.Pod)}, - "node5": {PodToRef(unschedulablePodInfo.Pod)}, + nominatedPods: map[string][]podRef{ + "node1": {podToRef(medPriorityPodInfo.Pod)}, + "node5": {podToRef(unschedulablePodInfo.Pod)}, }, } if diff := cmp.Diff(q.nominator, expectedNominatedPods, nominatorCmpOpts...); diff != "" {