@@ -23,6 +23,7 @@ import (
23
23
corev1 "k8s.io/api/core/v1"
24
24
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
25
"k8s.io/apimachinery/pkg/types"
26
+ "k8s.io/klog/v2"
26
27
"sigs.k8s.io/controller-runtime/pkg/client"
27
28
schedulerpluginsv1alpha1 "sigs.k8s.io/scheduler-plugins/apis/scheduling/v1alpha1"
28
29
volcanobatchv1alpha1 "volcano.sh/apis/pkg/apis/batch/v1alpha1"
@@ -33,20 +34,22 @@ import (
33
34
// PodGroupControlInterface is an interface that knows how to add or delete PodGroups
34
35
// created as an interface to allow testing.
35
36
type PodGroupControlInterface interface {
36
- // NewEmptyPodGroup returns an empty PodGroup
37
+ // NewEmptyPodGroup returns an empty PodGroup.
37
38
NewEmptyPodGroup () client.Object
38
- // GetPodGroup gets the PodGroup identified by namespace and name
39
+ // GetPodGroup gets the PodGroup identified by namespace and name.
39
40
GetPodGroup (namespace string , name string ) (metav1.Object , error )
40
41
// DeletePodGroup deletes the PodGroup identified by namespace and name.
41
42
DeletePodGroup (namespace string , name string ) error
43
+ // UpdatePodGroup updates a PodGroup.
44
+ UpdatePodGroup (podGroup client.Object ) error
42
45
// CreatePodGroup creates a new PodGroup with PodGroup spec fill function.
43
46
CreatePodGroup (podGroup client.Object ) error
44
47
// DelayPodCreationDueToPodGroup determines whether it should delay Pod Creation.
45
48
DelayPodCreationDueToPodGroup (pg metav1.Object ) bool
46
49
// DecoratePodTemplateSpec decorates PodTemplateSpec.
47
- // If the PodTemplateSpec has SchedulerName set, this method will Not override
50
+ // If the PodTemplateSpec has SchedulerName set, this method will Not override.
48
51
DecoratePodTemplateSpec (pts * corev1.PodTemplateSpec , job metav1.Object , rtype string )
49
- // GetSchedulerName returns the name of the gang scheduler
52
+ // GetSchedulerName returns the name of the gang scheduler.
50
53
GetSchedulerName () string
51
54
}
52
55
@@ -99,6 +102,15 @@ func (v *VolcanoControl) DeletePodGroup(namespace string, name string) error {
99
102
return v .Client .SchedulingV1beta1 ().PodGroups (namespace ).Delete (context .TODO (), name , metav1.DeleteOptions {})
100
103
}
101
104
105
+ func (v * VolcanoControl ) UpdatePodGroup (podGroup client.Object ) error {
106
+ pg := podGroup .(* volcanov1beta1.PodGroup )
107
+ _ , err := v .Client .SchedulingV1beta1 ().PodGroups (pg .GetNamespace ()).Update (context .TODO (), pg , metav1.UpdateOptions {})
108
+ if err != nil {
109
+ return fmt .Errorf ("unable to update a PodGroup, '%v': %v" , klog .KObj (pg ), err )
110
+ }
111
+ return nil
112
+ }
113
+
102
114
func (v * VolcanoControl ) CreatePodGroup (podGroup client.Object ) error {
103
115
pg := podGroup .(* volcanov1beta1.PodGroup )
104
116
createPodGroup , err := v .Client .SchedulingV1beta1 ().PodGroups (pg .GetNamespace ()).Create (context .TODO (), pg , metav1.CreateOptions {})
@@ -162,9 +174,22 @@ func (s *SchedulerPluginsControl) DeletePodGroup(namespace, name string) error {
162
174
return s .Client .Delete (ctx , pg )
163
175
}
164
176
177
+ func (s * SchedulerPluginsControl ) UpdatePodGroup (podGroup client.Object ) error {
178
+ pg := podGroup .(* schedulerpluginsv1alpha1.PodGroup )
179
+ err := s .Client .Update (context .TODO (), pg , & client.UpdateOptions {})
180
+ if err != nil {
181
+ return fmt .Errorf ("unable to update a PodGroup, '%v': %v" , klog .KObj (pg ), err )
182
+ }
183
+ return nil
184
+ }
185
+
165
186
func (s * SchedulerPluginsControl ) CreatePodGroup (podGroup client.Object ) error {
166
- ctx := context .TODO ()
167
- return s .Client .Create (ctx , podGroup )
187
+ pg := podGroup .(* schedulerpluginsv1alpha1.PodGroup )
188
+ err := s .Client .Create (context .TODO (), pg , & client.CreateOptions {})
189
+ if err != nil {
190
+ return fmt .Errorf ("unable to create a PodGroup, '%v': %v" , klog .KObj (pg ), err )
191
+ }
192
+ return nil
168
193
}
169
194
170
195
var _ PodGroupControlInterface = & SchedulerPluginsControl {}
0 commit comments