Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit 2533e97

Browse files
authored
Merge pull request #870 from thandayuthapani/dualversion
Support Both versions of PodGroup
2 parents bdb561d + 2572005 commit 2533e97

File tree

14 files changed

+571
-63
lines changed

14 files changed

+571
-63
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: podgroups.scheduling.sigs.dev
5+
spec:
6+
group: scheduling.sigs.dev
7+
names:
8+
kind: PodGroup
9+
plural: podgroups
10+
scope: Namespaced
11+
validation:
12+
openAPIV3Schema:
13+
properties:
14+
apiVersion:
15+
type: string
16+
kind:
17+
type: string
18+
metadata:
19+
type: object
20+
spec:
21+
properties:
22+
minMember:
23+
format: int32
24+
type: integer
25+
queue:
26+
type: string
27+
priorityClassName:
28+
type: string
29+
type: object
30+
status:
31+
properties:
32+
succeeded:
33+
format: int32
34+
type: integer
35+
failed:
36+
format: int32
37+
type: integer
38+
running:
39+
format: int32
40+
type: integer
41+
type: object
42+
type: object
43+
version: v1alpha2

hack/run-e2e-kind.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function kube-batch-up {
7171

7272
kubectl create -f deployment/kube-batch/templates/scheduling_v1alpha1_queue.yaml
7373
kubectl create -f deployment/kube-batch/templates/scheduling_v1alpha1_podgroup.yaml
74+
kubectl create -f deployment/kube-batch/templates/scheduling_v1alpha2_podgroup.yaml
7475
kubectl create -f deployment/kube-batch/templates/default.yaml
7576

7677
# start kube-batch

pkg/scheduler/actions/allocate/allocate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func TestAllocate(t *testing.T) {
169169
}
170170

171171
for _, ss := range test.podGroups {
172-
schedulerCache.AddPodGroup(ss)
172+
schedulerCache.AddPodGroupAlpha1(ss)
173173
}
174174

175175
for _, q := range test.queues {

pkg/scheduler/actions/preempt/preempt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestPreempt(t *testing.T) {
161161
}
162162

163163
for _, ss := range test.podGroups {
164-
schedulerCache.AddPodGroup(ss)
164+
schedulerCache.AddPodGroupAlpha1(ss)
165165
}
166166

167167
for _, q := range test.queues {

pkg/scheduler/actions/reclaim/reclaim_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestReclaim(t *testing.T) {
130130
}
131131

132132
for _, ss := range test.podGroups {
133-
schedulerCache.AddPodGroup(ss)
133+
schedulerCache.AddPodGroupAlpha1(ss)
134134
}
135135

136136
for _, q := range test.queues {

pkg/scheduler/api/job_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ type JobInfo struct {
147147
TotalRequest *Resource
148148

149149
CreationTimestamp metav1.Time
150-
PodGroup *v1alpha1.PodGroup
150+
PodGroup *PodGroup
151151

152152
// TODO(k82cn): keep backward compatibility, removed it when v1alpha1 finalized.
153153
PDB *policyv1.PodDisruptionBudget
@@ -181,7 +181,7 @@ func (ji *JobInfo) UnsetPodGroup() {
181181
}
182182

183183
// SetPodGroup sets podGroup details to a job
184-
func (ji *JobInfo) SetPodGroup(pg *v1alpha1.PodGroup) {
184+
func (ji *JobInfo) SetPodGroup(pg *PodGroup) {
185185
ji.Name = pg.Name
186186
ji.Namespace = pg.Namespace
187187
ji.MinAvailable = pg.Spec.MinMember
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package api
18+
19+
import (
20+
"encoding/json"
21+
22+
"github.com/golang/glog"
23+
"github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
24+
"github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha2"
25+
v1 "k8s.io/api/core/v1"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
)
28+
29+
//PodGroupConditionType is of string type which represents podGroup Condition
30+
type PodGroupConditionType string
31+
32+
const (
33+
//PodGroupUnschedulableType represents unschedulable podGroup condition
34+
PodGroupUnschedulableType PodGroupConditionType = "Unschedulable"
35+
)
36+
37+
// PodGroupPhase is the phase of a pod group at the current time.
38+
type PodGroupPhase string
39+
40+
// These are the valid phase of podGroups.
41+
const (
42+
//PodGroupVersionV1Alpha1 represents PodGroupVersion of V1Alpha1
43+
PodGroupVersionV1Alpha1 string = "v1alpha1"
44+
45+
//PodGroupVersionV1Alpha2 represents PodGroupVersion of V1Alpha2
46+
PodGroupVersionV1Alpha2 string = "v1alpha2"
47+
// PodPending means the pod group has been accepted by the system, but scheduler can not allocate
48+
// enough resources to it.
49+
PodGroupPending PodGroupPhase = "Pending"
50+
51+
// PodRunning means `spec.minMember` pods of PodGroups has been in running phase.
52+
PodGroupRunning PodGroupPhase = "Running"
53+
54+
// PodGroupUnknown means part of `spec.minMember` pods are running but the other part can not
55+
// be scheduled, e.g. not enough resource; scheduler will wait for related controller to recover it.
56+
PodGroupUnknown PodGroupPhase = "Unknown"
57+
)
58+
59+
// PodGroupCondition contains details for the current state of this pod group.
60+
type PodGroupCondition struct {
61+
// Type is the type of the condition
62+
Type PodGroupConditionType `json:"type,omitempty" protobuf:"bytes,1,opt,name=type"`
63+
64+
// Status is the status of the condition.
65+
Status v1.ConditionStatus `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"`
66+
67+
// The ID of condition transition.
68+
TransitionID string `json:"transitionID,omitempty" protobuf:"bytes,3,opt,name=transitionID"`
69+
70+
// Last time the phase transitioned from another to current phase.
71+
// +optional
72+
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
73+
74+
// Unique, one-word, CamelCase reason for the phase's last transition.
75+
// +optional
76+
Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"`
77+
78+
// Human-readable message indicating details about last transition.
79+
// +optional
80+
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
81+
}
82+
83+
// PodGroup is a collection of Pod; used for batch workload.
84+
type PodGroup struct {
85+
metav1.TypeMeta `json:",inline"`
86+
// Standard object's metadata.
87+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
88+
// +optional
89+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
90+
91+
// Specification of the desired behavior of the pod group.
92+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
93+
// +optional
94+
Spec PodGroupSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
95+
96+
// Status represents the current information about a pod group.
97+
// This data may not be up to date.
98+
// +optional
99+
Status PodGroupStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
100+
101+
//Version represents the version of PodGroup
102+
Version string
103+
}
104+
105+
// PodGroupSpec represents the template of a pod group.
106+
type PodGroupSpec struct {
107+
// MinMember defines the minimal number of members/tasks to run the pod group;
108+
// if there's not enough resources to start all tasks, the scheduler
109+
// will not start anyone.
110+
MinMember int32 `json:"minMember,omitempty" protobuf:"bytes,1,opt,name=minMember"`
111+
112+
// Queue defines the queue to allocate resource for PodGroup; if queue does not exist,
113+
// the PodGroup will not be scheduled.
114+
Queue string `json:"queue,omitempty" protobuf:"bytes,2,opt,name=queue"`
115+
116+
// If specified, indicates the PodGroup's priority. "system-node-critical" and
117+
// "system-cluster-critical" are two special keywords which indicate the
118+
// highest priorities with the former being the highest priority. Any other
119+
// name must be defined by creating a PriorityClass object with that name.
120+
// If not specified, the PodGroup priority will be default or zero if there is no
121+
// default.
122+
// +optional
123+
PriorityClassName string `json:"priorityClassName,omitempty" protobuf:"bytes,3,opt,name=priorityClassName"`
124+
}
125+
126+
// PodGroupStatus represents the current state of a pod group.
127+
type PodGroupStatus struct {
128+
// Current phase of PodGroup.
129+
Phase PodGroupPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase"`
130+
131+
// The conditions of PodGroup.
132+
// +optional
133+
Conditions []PodGroupCondition `json:"conditions,omitempty" protobuf:"bytes,2,opt,name=conditions"`
134+
135+
// The number of actively running pods.
136+
// +optional
137+
Running int32 `json:"running,omitempty" protobuf:"bytes,3,opt,name=running"`
138+
139+
// The number of pods which reached phase Succeeded.
140+
// +optional
141+
Succeeded int32 `json:"succeeded,omitempty" protobuf:"bytes,4,opt,name=succeeded"`
142+
143+
// The number of pods which reached phase Failed.
144+
// +optional
145+
Failed int32 `json:"failed,omitempty" protobuf:"bytes,5,opt,name=failed"`
146+
}
147+
148+
//ConvertPodGroupInfoToV1Alpha converts api.PodGroup type to v1alpha1.PodGroup
149+
func ConvertPodGroupInfoToV1Alpha(pg *PodGroup) (*v1alpha1.PodGroup, error) {
150+
marshalled, err := json.Marshal(*pg)
151+
if err != nil {
152+
glog.Errorf("Failed to Marshal podgroup %s with error: %v", pg.Name, err)
153+
}
154+
155+
convertedPg := &v1alpha1.PodGroup{}
156+
err = json.Unmarshal(marshalled, convertedPg)
157+
if err != nil {
158+
glog.Errorf("Failed to Unmarshal Data into v1alpha1.PodGroup type with error: %v", err)
159+
}
160+
161+
return convertedPg, nil
162+
}
163+
164+
//ConvertV1Alpha1ToPodGroupInfo converts v1alpha1.PodGroup to api.PodGroup type
165+
func ConvertV1Alpha1ToPodGroupInfo(pg *v1alpha1.PodGroup) (*PodGroup, error) {
166+
marshalled, err := json.Marshal(*pg)
167+
if err != nil {
168+
glog.Errorf("Failed to Marshal podgroup %s with error: %v", pg.Name, err)
169+
}
170+
171+
convertedPg := &PodGroup{}
172+
err = json.Unmarshal(marshalled, convertedPg)
173+
if err != nil {
174+
glog.Errorf("Failed to Unmarshal Data into api.PodGroup type with error: %v", err)
175+
}
176+
convertedPg.Version = PodGroupVersionV1Alpha1
177+
178+
return convertedPg, nil
179+
}
180+
181+
//ConvertPodGroupInfoToV2Alpha converts api.PodGroup type to v1alpha2.PodGroup
182+
func ConvertPodGroupInfoToV2Alpha(pg *PodGroup) (*v1alpha2.PodGroup, error) {
183+
marshalled, err := json.Marshal(*pg)
184+
if err != nil {
185+
glog.Errorf("Failed to Marshal podgroup %s with error: %v", pg.Name, err)
186+
}
187+
188+
convertedPg := &v1alpha2.PodGroup{}
189+
err = json.Unmarshal(marshalled, convertedPg)
190+
if err != nil {
191+
glog.Errorf("Failed to Unmarshal Data into v1alpha2.PodGroup type with error: %v", err)
192+
}
193+
194+
return convertedPg, nil
195+
}
196+
197+
//ConvertV1Alpha2ToPodGroupInfo converts v1alpha2.PodGroup to api.PodGroup type
198+
func ConvertV1Alpha2ToPodGroupInfo(pg *v1alpha2.PodGroup) (*PodGroup, error) {
199+
marshalled, err := json.Marshal(*pg)
200+
if err != nil {
201+
glog.Errorf("Failed to Marshal podgroup %s with error: %v", pg.Name, err)
202+
}
203+
204+
convertedPg := &PodGroup{}
205+
err = json.Unmarshal(marshalled, convertedPg)
206+
if err != nil {
207+
glog.Errorf("Failed to Unmarshal Data into api.PodGroup type with error: %v", err)
208+
}
209+
convertedPg.Version = PodGroupVersionV1Alpha2
210+
211+
return convertedPg, nil
212+
}

0 commit comments

Comments
 (0)