Skip to content

Commit 5532bde

Browse files
authored
Merge pull request #5 from OyutianO/main
add create queue unit function when a new pytorchjob created
2 parents 44d96b3 + 8c1381f commit 5532bde

File tree

3 files changed

+220
-68
lines changed

3 files changed

+220
-68
lines changed

cmd/app/server.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app
22

33
import (
44
v1 "github.com/kube-queue/pytorch-operator-extension/pkg/pytorch-operator/apis/pytorch/v1"
5+
"k8s.io/client-go/kubernetes"
56
"k8s.io/client-go/rest"
67
"k8s.io/client-go/tools/cache"
78
"k8s.io/client-go/tools/clientcmd"
@@ -17,11 +18,6 @@ import (
1718
"k8s.io/klog/v2"
1819
)
1920

20-
const (
21-
ConsumerRefKind = v1.Kind
22-
ConsumerRefAPIVersion = v1.GroupName + "/" + v1.GroupVersion
23-
)
24-
2521
// Run runs the server.
2622
func Run(opt *options.ServerOption) error {
2723
var restConfig *rest.Config
@@ -35,6 +31,11 @@ func Run(opt *options.ServerOption) error {
3531
}
3632
}
3733

34+
k8sClientSet, err := kubernetes.NewForConfig(restConfig)
35+
if err != nil {
36+
return err
37+
}
38+
3839
queueClient, err := queueversioned.NewForConfig(restConfig)
3940
if err != nil {
4041
return err
@@ -50,7 +51,9 @@ func Run(opt *options.ServerOption) error {
5051
pytorchJobInformerFactory := pytorchjobinformers.NewSharedInformerFactory(pytorchJobClient, 0)
5152
pytorchJobInformer := pytorchJobInformerFactory.Kubeflow().V1().PyTorchJobs().Informer()
5253

53-
pytorchExtensionController := contorller.NewPyTorchExtensionController(queueInformerFactory.Scheduling().V1alpha1().QueueUnits(),
54+
pytorchExtensionController := contorller.NewPyTorchExtensionController(
55+
k8sClientSet,
56+
queueInformerFactory.Scheduling().V1alpha1().QueueUnits(),
5457
queueClient,
5558
pytorchJobInformerFactory.Kubeflow().V1().PyTorchJobs(),
5659
pytorchJobClient,
@@ -62,8 +65,8 @@ func Run(opt *options.ServerOption) error {
6265
switch qu := obj.(type) {
6366
case *v1alpha1.QueueUnit:
6467
if qu.Spec.ConsumerRef != nil &&
65-
qu.Spec.ConsumerRef.Kind == ConsumerRefKind &&
66-
qu.Spec.ConsumerRef.APIVersion == ConsumerRefAPIVersion {
68+
qu.Spec.ConsumerRef.Kind == contorller.ConsumerRefKind &&
69+
qu.Spec.ConsumerRef.APIVersion == contorller.ConsumerRefAPIVersion {
6770
return true
6871
}
6972
return false
@@ -90,9 +93,9 @@ func Run(opt *options.ServerOption) error {
9093
}
9194
},
9295
Handler: cache.ResourceEventHandlerFuncs{
93-
AddFunc: pytorchExtensionController.AddPytorchJob,
94-
UpdateFunc: pytorchExtensionController.UpdatePytorchJob,
95-
DeleteFunc: pytorchExtensionController.DeletePytorchJob,
96+
AddFunc: pytorchExtensionController.AddPyTorchJob,
97+
UpdateFunc: pytorchExtensionController.UpdatePyTorchJob,
98+
DeleteFunc: pytorchExtensionController.DeletePyTorchJob,
9699
},
97100
},
98101
)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
k8s.io/apimachinery v0.21.2
99
k8s.io/client-go v0.21.2
1010
k8s.io/code-generator v0.21.2
11+
k8s.io/klog v1.0.0
1112
k8s.io/klog/v2 v2.8.0
1213
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7
1314
k8s.io/sample-controller v0.21.2

0 commit comments

Comments
 (0)