Skip to content

Commit

Permalink
fix(qrm): use phase pending instead of active to judge if need to ram…
Browse files Browse the repository at this point in the history
…p up
  • Loading branch information
csfldf authored and waynepeking348 committed Dec 14, 2023
1 parent 705f7fa commit bacb868
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,8 @@ func (p *DynamicPolicy) shouldSharedCoresRampUp(podUID string) bool {
} else if pod == nil {
general.Infof("can't get pod: %s from metaServer, try to ramp up it", podUID)
return true
} else if native.PodIsActive(pod) {
general.Infof("pod: %s/%s is active, not try to ramp up it", pod.Namespace, pod.Name)
} else if !native.PodIsPending(pod) {
general.Infof("pod: %s/%s isn't pending(not admit firstly), not try to ramp up it", pod.Namespace, pod.Name)
return false
} else {
general.Infof("pod: %s/%s isn't active, try to ramp up it", pod.Namespace, pod.Name)
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/native/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ func PodIsActive(pod *v1.Pod) bool {
return !PodIsTerminated(pod)
}

// PodIsPending returns whether the pod is pending.
func PodIsPending(pod *v1.Pod) bool {
if pod == nil {
return false
}
return pod.Status.Phase == v1.PodPending
}

// FilterOutSkipEvictionPods return pods should be candidates to evict
// including native critical pods and user-defined filtered pods
func FilterOutSkipEvictionPods(pods []*v1.Pod, filterOutAnnotations, filterOutLabels sets.String) []*v1.Pod {
Expand Down
45 changes: 45 additions & 0 deletions pkg/util/native/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,48 @@ func TestParseHostPortForPod(t *testing.T) {
})
}
}
func TestPodIsPending(t *testing.T) {
type args struct {
pod *v1.Pod
}
tests := []struct {
name string
args args
want bool
}{
{
name: "pod is pending",
args: args{
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodPending,
},
},
},
want: true,
},
{
name: "pod isn't pending",
args: args{
pod: &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodRunning,
},
},
},
want: false,
},
{
name: "nil pod",
args: args{},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := PodIsPending(tt.args.pod); got != tt.want {
t.Errorf("PodIsPending() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit bacb868

Please sign in to comment.