Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit 31e2c89

Browse files
authored
Merge pull request #563 from k82cn/automated-cherry-pick-of-#562-#560-upstream-release-0.4
Automated cherry pick of #562: Update PodGroup status. #560: Update PodGroup status.
2 parents a424b03 + a71079a commit 31e2c89

File tree

16 files changed

+400
-420
lines changed

16 files changed

+400
-420
lines changed

doc/design/podgroup-status.md

+62-39
Original file line numberDiff line numberDiff line change
@@ -31,67 +31,91 @@ const (
3131
// PodPending means the pod group has been accepted by the system, but scheduler can not allocate
3232
// enough resources to it.
3333
PodGroupPending PodGroupPhase = "Pending"
34+
3435
// PodRunning means `spec.minMember` pods of PodGroups has been in running phase.
3536
PodGroupRunning PodGroupPhase = "Running"
36-
// PodGroupRecovering means part of `spec.minMember` pods have exception, e.g. killed; scheduler will
37-
// wait for related controller to recover it.
38-
PodGroupRecovering PodGroupPhase = "Recovering"
39-
// PodGroupUnschedulable means part of `spec.minMember` pods are running but the other part can not
40-
// be scheduled, e.g. not enough resource; scheduler will wait for related controller to recover it.
41-
PodGroupUnschedulable PodGroupPhase = "Unschedulable"
37+
38+
// PodGroupUnknown means part of `spec.minMember` pods are running but the other part can not
39+
// be scheduled, e.g. not enough resource; scheduler will wait for related controller to recover it.
40+
PodGroupUnknown PodGroupPhase = "Unknown"
4241
)
4342

43+
type PodGroupConditionType string
44+
4445
const (
45-
// PodFailedReason is probed if pod of PodGroup failed
46-
PodFailedReason string = "PodFailed"
47-
// PodDeletedReason is probed if pod of PodGroup deleted
48-
PodDeletedReason string = "PodDeleted"
49-
// NotEnoughResourcesReason is probed if there're not enough resources to schedule pods
50-
NotEnoughResourcesReason string = "NotEnoughResources"
51-
// NotEnoughPodsReason is probed if there're not enough tasks compared to `spec.minMember`
52-
NotEnoughPodsReason string = "NotEnoughTasks"
46+
PodGroupUnschedulableType PodGroupConditionType = "Unschedulable"
5347
)
5448

55-
// PodGroupState contains details for the current state of this pod group.
56-
type PodGroupState struct {
57-
// Current phase of PodGroup.
58-
Phase PodGroupPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
59-
60-
// Last time we probed to this Phase.
61-
// +optional
62-
LastProbeTime metav1.Time `json:"lastProbeTime,omitempty" protobuf:"bytes,2,opt,name=lastProbeTime"`
49+
// PodGroupCondition contains details for the current state of this pod group.
50+
type PodGroupCondition struct {
51+
// Type is the type of the condition
52+
Type PodGroupConditionType `json:"type,omitempty" protobuf:"bytes,1,opt,name=type"`
53+
54+
// Status is the status of the condition.
55+
Status v1.ConditionStatus `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"`
56+
57+
// The ID of condition transition.
58+
TransitionID string `json:"transitionID,omitempty" protobuf:"bytes,3,opt,name=transitionID"`
59+
6360
// Last time the phase transitioned from another to current phase.
6461
// +optional
65-
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"`
62+
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
63+
6664
// Unique, one-word, CamelCase reason for the phase's last transition.
6765
// +optional
68-
Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
66+
Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"`
67+
6968
// Human-readable message indicating details about last transition.
7069
// +optional
71-
Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
70+
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
7271
}
7372

73+
const (
74+
// PodFailedReason is probed if pod of PodGroup failed
75+
PodFailedReason string = "PodFailed"
76+
77+
// PodDeletedReason is probed if pod of PodGroup deleted
78+
PodDeletedReason string = "PodDeleted"
79+
80+
// NotEnoughResourcesReason is probed if there're not enough resources to schedule pods
81+
NotEnoughResourcesReason string = "NotEnoughResources"
82+
83+
// NotEnoughPodsReason is probed if there're not enough tasks compared to `spec.minMember`
84+
NotEnoughPodsReason string = "NotEnoughTasks"
85+
)
86+
87+
// PodGroupStatus represents the current state of a pod group.
7488
type PodGroupStatus struct {
75-
......
89+
// Current phase of PodGroup.
90+
Phase PodGroupPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
91+
92+
// The conditions of PodGroup.
93+
// +optional
94+
Conditions []PodGroupCondition `json:"conditions,omitempty" protobuf:"bytes,2,opt,name=conditions"`
7695

96+
// The number of actively running pods.
7797
// +optional
78-
State PodGroupState `json:"state,omitempty" protobuf:"bytes,1,opt,name=state,casttype=State"`
98+
Running int32 `json:"running,omitempty" protobuf:"bytes,3,opt,name=running"`
99+
100+
// The number of pods which reached phase Succeeded.
101+
// +optional
102+
Succeeded int32 `json:"succeeded,omitempty" protobuf:"bytes,4,opt,name=succeeded"`
103+
104+
// The number of pods which reached phase Failed.
105+
// +optional
106+
Failed int32 `json:"failed,omitempty" protobuf:"bytes,5,opt,name=failed"`
79107
}
108+
80109
```
81110

82111
According to the PodGroup's lifecycle, the following phase/state transactions are reasonable. And related
83112
reasons will be appended to `Reason` field.
84113

85-
| From | To | Reason |
86-
|---------------|---------------|---------|
87-
| Pending | Running | When every pods of `spec.minMember` are running |
88-
| Pending | Recovering | When only part of `spec.minMember` are running and the other part pod are rejected by kubelet |
89-
| Running | Recovering | When part of `spec.minMember` have exception, e.g. kill |
90-
| Recovering | Running | When the failed pods re-run successfully |
91-
| Recovering | Unschedulable | When the new pod can not be scheduled |
92-
| Unschedulable | Pending | When all pods (`spec.minMember`) in PodGroups are deleted |
93-
| Unschedulable | Running | When all pods (`spec.minMember`) are deleted |
94-
114+
| From | To | Reason |
115+
|---------|---------------|---------|
116+
| Pending | Running | When every pods of `spec.minMember` are running |
117+
| Running | Unknown | When some pods of `spec.minMember` are restarted but can not be rescheduled |
118+
| Unknown | Pending | When all pods (`spec.minMember`) in PodGroups are deleted |
95119

96120
## Feature Interaction
97121

@@ -110,8 +134,7 @@ Cluster-Autoscaler right now. Alternative solution will be proposed later for th
110134
### Operators/Controllers
111135

112136
The lifecycle of `PodGroup` are managed by operators/controllers, the scheduler only probes related state for
113-
controllers. For example, if `PodGroup` is `Unschedulable` for MPI job, the controller need to re-start all
114-
pods in `PodGroup`.
137+
controllers. For example, if `PodGroup` is `Unknown` for MPI job, the controller need to re-start all pods in `PodGroup`.
115138

116139
## Reference
117140

pkg/apis/scheduling/v1alpha1/types.go

+29-30
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
"k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

23-
// Event represent the phase of PodGroup, e.g. pod-failed.
24-
type Event string
25-
26-
const (
27-
EvictEvent Event = "Evict"
28-
UnschedulableEvent Event = "Unschedulable"
29-
FailedSchedulingEvent Event = "FailedScheduling"
30-
)
31-
3224
// PodGroupPhase is the phase of a pod group at the current time.
3325
type PodGroupPhase string
3426

@@ -41,35 +33,39 @@ const (
4133
// PodRunning means `spec.minMember` pods of PodGroups has been in running phase.
4234
PodGroupRunning PodGroupPhase = "Running"
4335

44-
// PodGroupRecovering means part of `spec.minMember` pods have exception, e.g. killed; scheduler will
45-
// wait for related controller to recover it.
46-
PodGroupRecovering PodGroupPhase = "Recovering"
47-
48-
// PodGroupUnschedulable means part of `spec.minMember` pods are running but the other part can not
36+
// PodGroupUnknown means part of `spec.minMember` pods are running but the other part can not
4937
// be scheduled, e.g. not enough resource; scheduler will wait for related controller to recover it.
50-
PodGroupUnschedulable PodGroupPhase = "Unschedulable"
38+
PodGroupUnknown PodGroupPhase = "Unknown"
5139
)
5240

53-
// PodGroupState contains details for the current state of this pod group.
54-
type PodGroupState struct {
55-
// Current phase of PodGroup.
56-
Phase PodGroupPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
41+
type PodGroupConditionType string
5742

58-
// Last time we probed to this Phase.
59-
// +optional
60-
LastProbeTime metav1.Time `json:"lastProbeTime,omitempty" protobuf:"bytes,2,opt,name=lastProbeTime"`
43+
const (
44+
PodGroupUnschedulableType PodGroupConditionType = "Unschedulable"
45+
)
46+
47+
// PodGroupCondition contains details for the current state of this pod group.
48+
type PodGroupCondition struct {
49+
// Type is the type of the condition
50+
Type PodGroupConditionType `json:"type,omitempty" protobuf:"bytes,1,opt,name=type"`
51+
52+
// Status is the status of the condition.
53+
Status v1.ConditionStatus `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"`
54+
55+
// The ID of condition transition.
56+
TransitionID string `json:"transitionID,omitempty" protobuf:"bytes,3,opt,name=transitionID"`
6157

6258
// Last time the phase transitioned from another to current phase.
6359
// +optional
64-
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"`
60+
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
6561

6662
// Unique, one-word, CamelCase reason for the phase's last transition.
6763
// +optional
68-
Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
64+
Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"`
6965

7066
// Human-readable message indicating details about last transition.
7167
// +optional
72-
Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
68+
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
7369
}
7470

7571
const (
@@ -122,21 +118,24 @@ type PodGroupSpec struct {
122118

123119
// PodGroupStatus represents the current state of a pod group.
124120
type PodGroupStatus struct {
125-
// The state of PodGroup.
121+
// Current phase of PodGroup.
122+
Phase PodGroupPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
123+
124+
// The conditions of PodGroup.
126125
// +optional
127-
State PodGroupState `json:"state,omitempty" protobuf:"bytes,1,opt,name=state,casttype=State"`
126+
Conditions []PodGroupCondition `json:"conditions,omitempty" protobuf:"bytes,2,opt,name=conditions"`
128127

129128
// The number of actively running pods.
130129
// +optional
131-
Running int32 `json:"running,omitempty" protobuf:"bytes,2,opt,name=running"`
130+
Running int32 `json:"running,omitempty" protobuf:"bytes,3,opt,name=running"`
132131

133132
// The number of pods which reached phase Succeeded.
134133
// +optional
135-
Succeeded int32 `json:"succeeded,omitempty" protobuf:"bytes,3,opt,name=succeeded"`
134+
Succeeded int32 `json:"succeeded,omitempty" protobuf:"bytes,4,opt,name=succeeded"`
136135

137136
// The number of pods which reached phase Failed.
138137
// +optional
139-
Failed int32 `json:"failed,omitempty" protobuf:"bytes,4,opt,name=failed"`
138+
Failed int32 `json:"failed,omitempty" protobuf:"bytes,5,opt,name=failed"`
140139
}
141140

142141
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/apis/scheduling/v1alpha1/zz_generated.deepcopy.go

+24-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/scheduler/actions/allocate/allocate_test.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/apimachinery/pkg/api/resource"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/types"
31+
"k8s.io/client-go/tools/record"
3132

3233
kbv1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
3334
"github.com/kubernetes-sigs/kube-batch/pkg/scheduler/api"
@@ -113,12 +114,17 @@ func (fb *fakeBinder) Bind(p *v1.Pod, hostname string) error {
113114
return nil
114115
}
115116

116-
type fakeTaskStatusUpdater struct {
117+
type fakeStatusUpdater struct {
117118
}
118119

119-
func (ftsu *fakeTaskStatusUpdater) Update(pod *v1.Pod, podCondition *v1.PodCondition) error {
120+
func (ftsu *fakeStatusUpdater) UpdatePod(pod *v1.Pod, podCondition *v1.PodCondition) (*v1.Pod, error) {
120121
// do nothing here
121-
return nil
122+
return nil, nil
123+
}
124+
125+
func (ftsu *fakeStatusUpdater) UpdatePodGroup(pg *kbv1.PodGroup) (*kbv1.PodGroup, error) {
126+
// do nothing here
127+
return nil, nil
122128
}
123129

124130
type fakeVolumeBinder struct {
@@ -239,12 +245,14 @@ func TestAllocate(t *testing.T) {
239245
c: make(chan string),
240246
}
241247
schedulerCache := &cache.SchedulerCache{
242-
Nodes: make(map[string]*api.NodeInfo),
243-
Jobs: make(map[api.JobID]*api.JobInfo),
244-
Queues: make(map[api.QueueID]*api.QueueInfo),
245-
Binder: binder,
246-
TaskStatusUpdater: &fakeTaskStatusUpdater{},
247-
VolumeBinder: &fakeVolumeBinder{},
248+
Nodes: make(map[string]*api.NodeInfo),
249+
Jobs: make(map[api.JobID]*api.JobInfo),
250+
Queues: make(map[api.QueueID]*api.QueueInfo),
251+
Binder: binder,
252+
StatusUpdater: &fakeStatusUpdater{},
253+
VolumeBinder: &fakeVolumeBinder{},
254+
255+
Recorder: record.NewFakeRecorder(100),
248256
}
249257
for _, node := range test.nodes {
250258
schedulerCache.AddNode(node)

pkg/scheduler/api/helpers.go

-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,5 @@ func MergeErrors(errs ...error) error {
9999
// JobTerminated checkes whether job was terminated.
100100
func JobTerminated(job *JobInfo) bool {
101101
return job.PodGroup == nil &&
102-
job.PDB == nil &&
103102
len(job.Tasks) == 0
104103
}

0 commit comments

Comments
 (0)