Skip to content

Commit bf08e30

Browse files
wangshulei098ahg-g
andcommitted
Update pkg/utils/utils.go
Co-authored-by: Abdullah Gharaibeh <[email protected]>
1 parent 8b87efa commit bf08e30

File tree

5 files changed

+67
-13
lines changed

5 files changed

+67
-13
lines changed

docs/examples/sample/gang-scheduling/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,10 @@ This ensures that resources for all pods are reserved before the leader starts,
7575

7676
To assign all groups of a LeaderWorkerSet to a specific Volcano queue, add the `scheduling.volcano.sh/queue-name` annotation to the LeaderWorkerSet metadata.
7777

78+
79+
### Volcano Scheduler Configurations
80+
81+
To configure certain annotations in the PodGroup that are used by the Volcano scheduler to control specific scheduling behaviors, the PodGroup created by the LeaderWorkerSet will inherit the annotations starting with `volcano.sh/` from the LeaderWorkerSet's metadata.annotations.
82+
7883
For a complete example, please refer to the [lws-sample-volcano.yaml](./lws-sample-volcano.yaml) file.
7984

docs/examples/sample/gang-scheduling/lws-sample-volcano.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ kind: LeaderWorkerSet
33
metadata:
44
# annotations:
55
# scheduling.volcano.sh/queue-name: lws-queue # Uncomment the annotation to set the queue name if needed
6+
# volcano.sh/sla-waiting-time: 5m # PodGroups can inherit annotations with the prefix volcano.sh/.
67
name: lws-sample-volcano
78
spec:
89
replicas: 2

pkg/schedulerprovider/volcano_provider.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package schedulerprovider
1818

1919
import (
2020
"context"
21+
"strings"
2122

2223
corev1 "k8s.io/api/core/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -31,7 +32,8 @@ import (
3132
)
3233

3334
const (
34-
Volcano ProviderType = "volcano"
35+
Volcano ProviderType = "volcano"
36+
VolcanoAnnotationPrefix string = "volcano.sh/"
3537
)
3638

3739
type VolcanoProvider struct {
@@ -63,7 +65,7 @@ func (v *VolcanoProvider) CreatePodGroupIfNotExists(ctx context.Context, lws *le
6365
leaderworkerset.GroupIndexLabelKey: leaderPod.Labels[leaderworkerset.GroupIndexLabelKey],
6466
leaderworkerset.RevisionKey: leaderPod.Labels[leaderworkerset.RevisionKey],
6567
},
66-
Annotations: utils.InheritVolcanoAnnotations(lws),
68+
Annotations: inheritVolcanoAnnotations(lws),
6769
},
6870
Spec: volcanov1beta1.PodGroupSpec{
6971
// Default startupPolicy is LeaderCreated, Leader and Workers Pods are scheduled together, so MinAvailable is set to size
@@ -105,3 +107,13 @@ func (v *VolcanoProvider) InjectPodGroupMetadata(pod *corev1.Pod) error {
105107

106108
return nil
107109
}
110+
111+
func inheritVolcanoAnnotations(lws *leaderworkerset.LeaderWorkerSet) map[string]string {
112+
res := map[string]string{}
113+
for k, v := range lws.Annotations {
114+
if strings.HasPrefix(k, VolcanoAnnotationPrefix) {
115+
res[k] = v
116+
}
117+
}
118+
return res
119+
}

pkg/schedulerprovider/volcano_provider_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func TestVolcanoProvider_CreatePodGroupIfNotExists(t *testing.T) {
5050
testLeaderPod1 := createTestLeaderPod("test-lws-0", "default", "test-lws", "0", "abc123")
5151
testLeaderPod2 := createTestLeaderPod("test-lws-1", "default", "test-lws", "1", "def456")
5252
testLeaderPod3 := createTestLeaderPod("test-lws-0", "default", "test-lws", "0", "xyz789")
53+
testLeaderPod4 := createTestLeaderPod("test-lws-0", "default", "test-lws", "0", "jkl012")
5354

5455
tests := []struct {
5556
name string
@@ -155,6 +156,52 @@ func TestVolcanoProvider_CreatePodGroupIfNotExists(t *testing.T) {
155156
Spec: volcanov1beta1.PodGroupSpec{MinMember: 3},
156157
},
157158
},
159+
{
160+
name: "create podgroup inherit volcano annotations",
161+
lws: &leaderworkerset.LeaderWorkerSet{
162+
ObjectMeta: metav1.ObjectMeta{
163+
Name: "test-lws",
164+
Namespace: "default",
165+
Annotations: map[string]string{
166+
"volcano.sh/sla-waiting-time": "5m",
167+
},
168+
},
169+
Spec: leaderworkerset.LeaderWorkerSetSpec{
170+
LeaderWorkerTemplate: leaderworkerset.LeaderWorkerTemplate{
171+
Size: ptr.To[int32](3),
172+
WorkerTemplate: corev1.PodTemplateSpec{
173+
Spec: corev1.PodSpec{
174+
Containers: []corev1.Container{{
175+
Name: "worker", Image: "nginx",
176+
Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")}},
177+
}},
178+
},
179+
},
180+
},
181+
},
182+
},
183+
leaderPod: testLeaderPod4,
184+
expectError: false,
185+
expectedPG: &volcanov1beta1.PodGroup{
186+
ObjectMeta: metav1.ObjectMeta{
187+
Name: "test-lws-0-jkl012",
188+
Namespace: "default",
189+
Labels: map[string]string{
190+
leaderworkerset.GroupIndexLabelKey: "0",
191+
leaderworkerset.SetNameLabelKey: "test-lws",
192+
leaderworkerset.RevisionKey: "jkl012",
193+
},
194+
Annotations: map[string]string{
195+
"volcano.sh/sla-waiting-time": "5m",
196+
},
197+
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(testLeaderPod4, corev1.SchemeGroupVersion.WithKind("Pod"))},
198+
},
199+
Spec: volcanov1beta1.PodGroupSpec{
200+
MinMember: 3,
201+
MinResources: &corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("300m")},
202+
},
203+
},
204+
},
158205
{
159206
name: "generic error on getting podgroup",
160207
lws: &leaderworkerset.LeaderWorkerSet{

pkg/utils/utils.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333

3434
const (
3535
defaultNamespace = "lws-system"
36-
AnnotationPrefix = "volcano.sh/"
3736
)
3837

3938
// Sha1Hash accepts an input string and returns the 40 character SHA1 hash digest of the input string.
@@ -102,13 +101,3 @@ func CalculatePGMinResources(lws *leaderworkerset.LeaderWorkerSet) corev1.Resour
102101

103102
return totalResources
104103
}
105-
106-
func InheritVolcanoAnnotations(lws *leaderworkerset.LeaderWorkerSet) map[string]string {
107-
res := map[string]string{}
108-
for k, v := range lws.Annotations {
109-
if strings.HasPrefix(k, AnnotationPrefix) {
110-
res[k] = v
111-
}
112-
}
113-
return res
114-
}

0 commit comments

Comments
 (0)