/
api.go
148 lines (135 loc) · 6.19 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package k8s
import (
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime/schema"
commomschema "github.com/PaddlePaddle/PaddleFlow/pkg/common/schema"
)
var (
PodGVK = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"}
VCJobGVK = schema.GroupVersionKind{Group: "batch.volcano.sh", Version: "v1alpha1", Kind: "Job"}
PodGroupGVK = schema.GroupVersionKind{Group: "scheduling.volcano.sh", Version: "v1beta1", Kind: "PodGroup"}
VCQueueGVK = schema.GroupVersionKind{Group: "scheduling.volcano.sh", Version: "v1beta1", Kind: "Queue"}
EQuotaGVK = schema.GroupVersionKind{Group: "scheduling.volcano.sh", Version: "v1beta1", Kind: "ElasticResourceQuota"}
SparkAppGVK = schema.GroupVersionKind{Group: "sparkoperator.k8s.io", Version: "v1beta2", Kind: "SparkApplication"}
PaddleJobGVK = schema.GroupVersionKind{Group: "batch.paddlepaddle.org", Version: "v1", Kind: "PaddleJob"}
// PyTorchJobGVK TFJobGVK defines GVK for kubeflow jobs
PyTorchJobGVK = schema.GroupVersionKind{Group: "kubeflow.org", Version: "v1", Kind: "PyTorchJob"}
TFJobGVK = schema.GroupVersionKind{Group: "kubeflow.org", Version: "v1", Kind: "TFJob"}
MPIJobGVK = schema.GroupVersionKind{Group: "kubeflow.org", Version: "v1", Kind: "MPIJob"}
MXNetJobGVK = schema.GroupVersionKind{Group: "kubeflow.org", Version: "v1", Kind: "MXJob"}
XGBoostJobGVK = schema.GroupVersionKind{Group: "kubeflow.org", Version: "v1", Kind: "XGBoostJob"}
RayJobGVK = schema.GroupVersionKind{Group: "ray.io", Version: "v1alpha1", Kind: "RayJob"}
// ArgoWorkflowGVK defines GVK for argo Workflow
ArgoWorkflowGVK = schema.GroupVersionKind{Group: "argoproj.io", Version: "v1alpha1", Kind: "Workflow"}
// PodGVR TODO:// add gvr to process and get rid of all gvks in future
PodGVR = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
SparkAppGVR = schema.GroupVersionResource{Group: "sparkoperator.k8s.io", Version: "v1beta2", Resource: "sparkapplications"}
PaddleJobGVR = schema.GroupVersionResource{Group: "batch.paddlepaddle.org", Version: "v1", Resource: "paddlejobs"}
PyTorchJobGVR = schema.GroupVersionResource{Group: "kubeflow.org", Version: "v1", Resource: "pytorchjobs"}
TFJobGVR = schema.GroupVersionResource{Group: "kubeflow.org", Version: "v1", Resource: "tfjobs"}
MPIJobGVR = schema.GroupVersionResource{Group: "kubeflow.org", Version: "v1", Resource: "mpijobs"}
MXNetJobGVR = schema.GroupVersionResource{Group: "kubeflow.org", Version: "v1", Resource: "mxjobs"}
XGBoostJobGVR = schema.GroupVersionResource{Group: "kubeflow.org", Version: "v1", Resource: "xgboostjobs"}
RayJobGVR = schema.GroupVersionResource{Group: "ray.io", Version: "v1alpha1", Resource: "rayjobs"}
ArgoWorkflowGVR = schema.GroupVersionResource{Group: "argoproj.io", Version: "v1alpha1", Resource: "workflows"}
// GVKJobStatusMap contains GroupVersionKind and convertStatus function to sync job status
GVKJobStatusMap = map[schema.GroupVersionKind]bool{
SparkAppGVK: true,
PaddleJobGVK: true,
PodGVK: true,
ArgoWorkflowGVK: true,
PyTorchJobGVK: true,
TFJobGVK: true,
MXNetJobGVK: true,
MPIJobGVK: true,
RayJobGVK: true,
}
)
func GetJobGVR(framework commomschema.Framework) schema.GroupVersionResource {
switch framework {
case commomschema.FrameworkStandalone:
return PodGVR
// TODO://reopen
// case commomschema.FrameworkTF:
// return TFJobGVR
// case commomschema.FrameworkPytorch:
// return PyTorchJobGVR
// case commomschema.FrameworkSpark:
// return SparkAppGVR
// case commomschema.FrameworkPaddle:
// return PaddleJobGVR
// case commomschema.FrameworkMXNet:
// return MXNetJobGVR
// case commomschema.FrameworkMPI:
// return MPIJobGVR
// case commomschema.FrameworkRay:
// return RayJobGVR
}
// default return pod gvr
return PodGVR
}
func GetJobFrameworkVersion(jobType commomschema.JobType, framework commomschema.Framework) commomschema.FrameworkVersion {
if jobType == commomschema.TypeWorkflow {
return commomschema.NewFrameworkVersion(ArgoWorkflowGVK.Kind, ArgoWorkflowGVK.GroupVersion().String())
}
var gvk schema.GroupVersionKind
switch framework {
case commomschema.FrameworkStandalone:
gvk = PodGVK
case commomschema.FrameworkTF:
gvk = TFJobGVK
case commomschema.FrameworkPytorch:
gvk = PyTorchJobGVK
case commomschema.FrameworkSpark:
gvk = SparkAppGVK
case commomschema.FrameworkPaddle:
gvk = PaddleJobGVK
case commomschema.FrameworkMXNet:
gvk = MXNetJobGVK
case commomschema.FrameworkMPI:
gvk = MPIJobGVK
case commomschema.FrameworkRay:
gvk = RayJobGVK
}
return commomschema.NewFrameworkVersion(gvk.Kind, gvk.GroupVersion().String())
}
func GetJobTypeAndFramework(gvk schema.GroupVersionKind) (commomschema.JobType, commomschema.Framework) {
switch gvk {
case PodGVK:
return commomschema.TypeSingle, commomschema.FrameworkStandalone
case SparkAppGVK:
return commomschema.TypeDistributed, commomschema.FrameworkSpark
case PaddleJobGVK:
return commomschema.TypeDistributed, commomschema.FrameworkPaddle
case PyTorchJobGVK:
return commomschema.TypeDistributed, commomschema.FrameworkPytorch
case TFJobGVK:
return commomschema.TypeDistributed, commomschema.FrameworkTF
case MXNetJobGVK:
return commomschema.TypeDistributed, commomschema.FrameworkMXNet
case MPIJobGVK:
return commomschema.TypeDistributed, commomschema.FrameworkMPI
case RayJobGVK:
return commomschema.TypeDistributed, commomschema.FrameworkRay
default:
log.Errorf("GroupVersionKind %s is not support", gvk)
return "", ""
}
}
type StatusInfo struct {
OriginStatus string
Status commomschema.JobStatus
Message string
}