Skip to content

Commit 95751be

Browse files
authored
Merge pull request #521 from czybjtu/feat_podgroup_label
feat: update PodGroup label key
2 parents c6c82af + 23e980c commit 95751be

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

apis/scheduling/v1alpha1/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const (
112112
PodGroupFailed PodGroupPhase = "Failed"
113113

114114
// PodGroupLabel is the default label of coscheduling
115-
PodGroupLabel = "pod-group." + scheduling.GroupName
115+
PodGroupLabel = scheduling.GroupName + "/pod-group"
116116
)
117117

118118
// PodGroup is a collection of Pod; used for batch workload.

doc/install.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Now, we're able to verify how the coscheduling plugin works.
193193
$ kubectl apply -f podgroup.yaml
194194
```
195195
196-
1. Create a deployment labelled `pod-group.scheduling.x-k8s.io: pg1` to associated with PodGroup
196+
1. Create a deployment labelled `scheduling.x-k8s.io/pod-group: pg1` to associated with PodGroup
197197
`pg1` created in the previous step.
198198
199199
```yaml
@@ -211,7 +211,7 @@ Now, we're able to verify how the coscheduling plugin works.
211211
metadata:
212212
labels:
213213
app: pause
214-
pod-group.scheduling.x-k8s.io: pg1
214+
scheduling.x-k8s.io/pod-group: pg1
215215
spec:
216216
containers:
217217
- name: pause

pkg/controllers/podgroup_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ func setUp(ctx context.Context,
281281
objs := []runtime.Object{pg}
282282
if len(podNames) != 0 {
283283
ps := makePods(podNames, pgName, podPhase, podOwnerReference)
284-
// s.AddKnownTypes(clientgoscheme.SchemeGroupVersion, ps)
285284
objs = append(objs, ps[0], ps[1])
286285
}
287286
client := fake.NewFakeClient(objs...)

pkg/coscheduling/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This folder holds the coscheduling plugin implementations based on [Coscheduling
1616

1717
### PodGroup
1818

19-
We use a special label named `pod-group.scheduling.x-k8s.io` to define a PodGroup. Pods that set this label and use the same value belong to the same PodGroup.
19+
We use a special label named `scheduling.x-k8s.io/pod-group` to define a PodGroup. Pods that set this label and use the same value belong to the same PodGroup.
2020

2121
```
2222
# PodGroup CRD spec
@@ -28,9 +28,9 @@ spec:
2828
scheduleTimeoutSeconds: 10
2929
minMember: 3
3030
---
31-
# Add a label `pod-group.scheduling.x-k8s.io` to mark the pod belongs to a group
31+
# Add a label `scheduling.x-k8s.io/pod-group` to mark the pod belongs to a group
3232
labels:
33-
pod-group.scheduling.x-k8s.io: nginx
33+
scheduling.x-k8s.io/pod-group: nginx
3434
```
3535

3636
We will calculate the sum of the Running pods and the Waiting pods (assumed but not bind) in scheduler, if the sum is greater than or equal to the minMember, the Waiting pods
@@ -108,7 +108,7 @@ spec:
108108
name: nginx
109109
labels:
110110
app: nginx
111-
pod-group.scheduling.x-k8s.io: nginx
111+
scheduling.x-k8s.io/pod-group: nginx
112112
spec:
113113
containers:
114114
- name: nginx

pkg/coscheduling/core/core.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func (pgMgr *PodGroupManager) ActivateSiblings(pod *corev1.Pod, state *framework
111111
klog.ErrorS(err, "Failed to obtain pods belong to a PodGroup", "podGroup", pgName)
112112
return
113113
}
114+
114115
for i := range pods {
115116
if pods[i].UID == pod.UID {
116117
pods = append(pods[:i], pods[i+1:]...)
@@ -149,6 +150,7 @@ func (pgMgr *PodGroupManager) PreFilter(ctx context.Context, pod *corev1.Pod) er
149150
if err != nil {
150151
return fmt.Errorf("podLister list pods failed: %w", err)
151152
}
153+
152154
if len(pods) < int(pg.Spec.MinMember) {
153155
return fmt.Errorf("pre-filter pod %v cannot find enough sibling pods, "+
154156
"current pods number: %v, minMember of group: %v", pod.Name, len(pods), pg.Spec.MinMember)
@@ -290,7 +292,7 @@ func (pgMgr *PodGroupManager) CalculateAssignedPods(podGroupName, namespace stri
290292
for _, nodeInfo := range nodeInfos {
291293
for _, podInfo := range nodeInfo.Pods {
292294
pod := podInfo.Pod
293-
if pod.Labels[v1alpha1.PodGroupLabel] == podGroupName && pod.Namespace == namespace && pod.Spec.NodeName != "" {
295+
if util.GetPodGroupLabel(pod) == podGroupName && pod.Namespace == namespace && pod.Spec.NodeName != "" {
294296
count++
295297
}
296298
}

pkg/coscheduling/coscheduling.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030

3131
"sigs.k8s.io/scheduler-plugins/apis/config"
3232
"sigs.k8s.io/scheduler-plugins/apis/scheduling"
33-
"sigs.k8s.io/scheduler-plugins/apis/scheduling/v1alpha1"
3433
"sigs.k8s.io/scheduler-plugins/pkg/coscheduling/core"
3534
pgclientset "sigs.k8s.io/scheduler-plugins/pkg/generated/clientset/versioned"
3635
pgformers "sigs.k8s.io/scheduler-plugins/pkg/generated/informers/externalversions"
@@ -162,7 +161,7 @@ func (cs *Coscheduling) PostFilter(ctx context.Context, state *framework.CycleSt
162161
// It's based on an implicit assumption: if the nth Pod failed,
163162
// it's inferrable other Pods belonging to the same PodGroup would be very likely to fail.
164163
cs.frameworkHandler.IterateOverWaitingPods(func(waitingPod framework.WaitingPod) {
165-
if waitingPod.GetPod().Namespace == pod.Namespace && waitingPod.GetPod().Labels[v1alpha1.PodGroupLabel] == pg.Name {
164+
if waitingPod.GetPod().Namespace == pod.Namespace && util.GetPodGroupLabel(waitingPod.GetPod()) == pg.Name {
166165
klog.V(3).InfoS("PostFilter rejects the pod", "podGroup", klog.KObj(pg), "pod", klog.KObj(waitingPod.GetPod()))
167166
waitingPod.Reject(cs.Name(), "optimistic rejection in PostFilter")
168167
}
@@ -224,7 +223,7 @@ func (cs *Coscheduling) Unreserve(ctx context.Context, state *framework.CycleSta
224223
return
225224
}
226225
cs.frameworkHandler.IterateOverWaitingPods(func(waitingPod framework.WaitingPod) {
227-
if waitingPod.GetPod().Namespace == pod.Namespace && waitingPod.GetPod().Labels[v1alpha1.PodGroupLabel] == pg.Name {
226+
if waitingPod.GetPod().Namespace == pod.Namespace && util.GetPodGroupLabel(waitingPod.GetPod()) == pg.Name {
228227
klog.V(3).InfoS("Unreserve rejects", "pod", klog.KObj(waitingPod.GetPod()), "podGroup", klog.KObj(pg))
229228
waitingPod.Reject(cs.Name(), "rejection in Unreserve")
230229
}

pkg/util/podgroup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ func CreateMergePatch(original, new interface{}) ([]byte, error) {
4747
return patch, nil
4848
}
4949

50-
// GetPodGroupLabel get pod group from pod annotations
50+
// GetPodGroupLabel get pod group name from pod labels
5151
func GetPodGroupLabel(pod *v1.Pod) string {
5252
return pod.Labels[v1alpha1.PodGroupLabel]
5353
}
5454

55-
// GetPodGroupFullName get namespaced group name from pod annotations
55+
// GetPodGroupFullName get namespaced group name from pod labels
5656
func GetPodGroupFullName(pod *v1.Pod) string {
5757
pgName := GetPodGroupLabel(pod)
5858
if len(pgName) == 0 {

0 commit comments

Comments
 (0)