@@ -18,7 +18,6 @@ package core
1818
1919import (
2020 "fmt"
21- "strconv"
2221 "sync"
2322 "time"
2423
@@ -113,31 +112,38 @@ func (gang *Gang) tryInitByPodConfig(pod *v1.Pod, args *config.CoschedulingArgs)
113112 }
114113 gang .MinRequiredNumber = minRequiredNumber
115114
116- totalChildrenNum , err := strconv . ParseInt (pod . Annotations [ extension . AnnotationGangTotalNum ], 10 , 32 )
115+ totalChildrenNum , err := extension . GetGangTotalNum (pod )
117116 if err != nil {
118- klog .V ( 4 ). ErrorS (err , "pod's annotation totalNumber illegal" ,
117+ klog .ErrorS (err , "pod's annotation totalNumber illegal" ,
119118 "gangName" , gang .Name , "value" , pod .Annotations [extension .AnnotationGangTotalNum ])
120- totalChildrenNum = int64 (minRequiredNumber )
121- } else if totalChildrenNum != 0 && totalChildrenNum < int64 (minRequiredNumber ) {
122-
123- klog .V (4 ).Infof ("pod's annotation totalNumber cannot less than minRequiredNumber, gangName: %v, totalNumber: %v,minRequiredNumber: %v" ,
119+ totalChildrenNum = minRequiredNumber
120+ } else if totalChildrenNum == 0 {
121+ totalChildrenNum = minRequiredNumber
122+ } else if totalChildrenNum < minRequiredNumber {
123+ klog .Errorf ("pod's annotation totalNumber cannot less than minRequiredNumber, gangName: %v, totalNumber: %v,minRequiredNumber: %v" ,
124124 gang .Name , pod .Annotations [extension .AnnotationGangTotalNum ], minRequiredNumber )
125- totalChildrenNum = int64 ( minRequiredNumber )
125+ totalChildrenNum = minRequiredNumber
126126 }
127- gang .TotalChildrenNum = int ( totalChildrenNum )
127+ gang .TotalChildrenNum = totalChildrenNum
128128
129129 mode := pod .Annotations [extension .AnnotationGangMode ]
130+ if mode == "" {
131+ mode = extension .GangModeStrict
132+ }
130133 if mode != extension .GangModeStrict && mode != extension .GangModeNonStrict {
131- klog .V ( 4 ). Infof ("pod's annotation GangModeAnnotation illegal, gangName: %v, value: %v" ,
134+ klog .Errorf ("pod's annotation GangModeAnnotation illegal, gangName: %v, value: %v" ,
132135 gang .Name , pod .Annotations [extension .AnnotationGangMode ])
133136 mode = extension .GangModeStrict
134137 }
135138 gang .Mode = mode
136139
137- matchPolicy := util .GetGangMatchPolicyByPod (pod )
140+ matchPolicy := extension .GetGangMatchPolicy (pod )
141+ if matchPolicy == "" {
142+ matchPolicy = extension .GangMatchPolicyOnceSatisfied
143+ }
138144 if matchPolicy != extension .GangMatchPolicyOnlyWaiting && matchPolicy != extension .GangMatchPolicyWaitingAndRunning &&
139145 matchPolicy != extension .GangMatchPolicyOnceSatisfied {
140- klog .V ( 4 ). Infof ("pod's annotation AnnotationGangMatchPolicy illegal, gangName: %v, value: %v" ,
146+ klog .Errorf ("pod's annotation AnnotationGangMatchPolicy illegal, gangName: %v, value: %v" ,
141147 gang .Name , matchPolicy )
142148 matchPolicy = extension .GangMatchPolicyOnceSatisfied
143149 }
@@ -146,17 +152,20 @@ func (gang *Gang) tryInitByPodConfig(pod *v1.Pod, args *config.CoschedulingArgs)
146152 // here we assume that Coscheduling's CreateTime equal with the pod's CreateTime
147153 gang .CreateTime = pod .CreationTimestamp .Time
148154
149- waitTime , err := time .ParseDuration (pod .Annotations [extension .AnnotationGangWaitTime ])
150- if err != nil || waitTime <= 0 {
151- klog .V (4 ).ErrorS (err , "pod's annotation GangWaitTimeAnnotation illegal" ,
155+ waitTime , err := extension .GetGangWaitTime (pod )
156+ if waitTime == 0 {
157+ waitTime = args .DefaultTimeout .Duration
158+ }
159+ if err != nil || waitTime < 0 {
160+ klog .ErrorS (err , "pod's annotation GangWaitTimeAnnotation illegal" ,
152161 "gangName" , gang .Name , "value" , pod .Annotations [extension .AnnotationGangWaitTime ])
153162 waitTime = args .DefaultTimeout .Duration
154163 }
155164 gang .WaitTime = waitTime
156165
157166 groupSlice , err := util .StringToGangGroupSlice (pod .Annotations [extension .AnnotationGangGroups ])
158167 if err != nil {
159- klog .V ( 4 ). ErrorS (err , "pod's annotation GangGroupsAnnotation illegal" ,
168+ klog .ErrorS (err , "pod's annotation GangGroupsAnnotation illegal" ,
160169 "gangName" , gang .Name , "value" , pod .Annotations [extension .AnnotationGangGroups ])
161170 }
162171 if len (groupSlice ) == 0 {
@@ -167,9 +176,10 @@ func (gang *Gang) tryInitByPodConfig(pod *v1.Pod, args *config.CoschedulingArgs)
167176
168177 gang .NetworkTopologySpec , err = extension .GetNetworkTopologySpec (pod )
169178 if err != nil {
170- klog .V ( 4 ). ErrorS (err , "pod's annotation AnnotationGangNetworkTopologySpec illegal" ,
179+ klog .ErrorS (err , "pod's annotation AnnotationGangNetworkTopologySpec illegal" ,
171180 "gangName" , gang .Name , "value" , pod .Annotations [extension .AnnotationGangNetworkTopologySpec ])
172181 }
182+
173183 gang .GangFrom = GangFromPodAnnotation
174184 gang .HasGangInit = true
175185
@@ -182,33 +192,41 @@ func (gang *Gang) tryInitByPodConfig(pod *v1.Pod, args *config.CoschedulingArgs)
182192func (gang * Gang ) tryInitByPodGroup (pg * v1alpha1.PodGroup , args * config.CoschedulingArgs ) {
183193 gang .lock .Lock ()
184194 defer gang .lock .Unlock ()
185- minRequiredNumber := pg .Spec .MinMember
186- gang .MinRequiredNumber = int ( minRequiredNumber )
195+ minRequiredNumber := int ( pg .Spec .MinMember )
196+ gang .MinRequiredNumber = minRequiredNumber
187197
188- totalChildrenNum , err := strconv . ParseInt (pg . Annotations [ extension . AnnotationGangTotalNum ], 10 , 32 )
198+ totalChildrenNum , err := extension . GetGangTotalNum (pg )
189199 if err != nil {
190- klog .V ( 4 ). ErrorS (err , "podGroup's annotation totalNumber illegal" ,
200+ klog .ErrorS (err , "podGroup's annotation totalNumber illegal" ,
191201 "gangName" , gang .Name , "value" , pg .Annotations [extension .AnnotationGangTotalNum ])
192- totalChildrenNum = int64 (minRequiredNumber )
193- } else if totalChildrenNum != 0 && totalChildrenNum < int64 (minRequiredNumber ) {
194- klog .V (4 ).Infof ("podGroup's annotation totalNumber cannot less than minRequiredNumber, gangName:%v, totalNumber: %v,minRequiredNumber: %v" ,
202+ totalChildrenNum = minRequiredNumber
203+ } else if totalChildrenNum == 0 {
204+ totalChildrenNum = minRequiredNumber
205+ } else if totalChildrenNum < minRequiredNumber {
206+ klog .Errorf ("podGroup's annotation totalNumber cannot less than minRequiredNumber, gangName:%v, totalNumber: %v,minRequiredNumber: %v" ,
195207 gang .Name , pg .Annotations [extension .AnnotationGangTotalNum ], minRequiredNumber )
196- totalChildrenNum = int64 ( minRequiredNumber )
208+ totalChildrenNum = minRequiredNumber
197209 }
198- gang .TotalChildrenNum = int ( totalChildrenNum )
210+ gang .TotalChildrenNum = totalChildrenNum
199211
200212 mode := pg .Annotations [extension .AnnotationGangMode ]
213+ if mode == "" {
214+ mode = extension .GangModeStrict
215+ }
201216 if mode != extension .GangModeStrict && mode != extension .GangModeNonStrict {
202- klog .V ( 4 ). Infof ("podGroup's annotation GangModeAnnotation illegal, gangName: %v, value: %v" ,
217+ klog .Errorf ("podGroup's annotation GangModeAnnotation illegal, gangName: %v, value: %v" ,
203218 gang .Name , pg .Annotations [extension .AnnotationGangMode ])
204219 mode = extension .GangModeStrict
205220 }
206221 gang .Mode = mode
207222
208- matchPolicy := pg .Annotations [extension .AnnotationGangMatchPolicy ]
223+ matchPolicy := extension .GetGangMatchPolicy (pg )
224+ if matchPolicy == "" {
225+ matchPolicy = extension .GangMatchPolicyOnceSatisfied
226+ }
209227 if matchPolicy != extension .GangMatchPolicyOnlyWaiting && matchPolicy != extension .GangMatchPolicyWaitingAndRunning &&
210228 matchPolicy != extension .GangMatchPolicyOnceSatisfied {
211- klog .V ( 4 ). Infof ("podGroup's annotation AnnotationGangMatchPolicy illegal, gangName: %v, value: %v" ,
229+ klog .Errorf ("podGroup's annotation AnnotationGangMatchPolicy illegal, gangName: %v, value: %v" ,
212230 gang .Name , matchPolicy )
213231 matchPolicy = extension .GangMatchPolicyOnceSatisfied
214232 }
@@ -222,7 +240,7 @@ func (gang *Gang) tryInitByPodGroup(pg *v1alpha1.PodGroup, args *config.Coschedu
222240
223241 groupSlice , err := util .StringToGangGroupSlice (pg .Annotations [extension .AnnotationGangGroups ])
224242 if err != nil {
225- klog .V ( 4 ). ErrorS (err , "podGroup's annotation GangGroupsAnnotation illegal" ,
243+ klog .ErrorS (err , "podGroup's annotation GangGroupsAnnotation illegal" ,
226244 "gangName" , gang .Name , "value" , pg .Annotations [extension .AnnotationGangGroups ])
227245 }
228246 if len (groupSlice ) == 0 {
@@ -233,7 +251,7 @@ func (gang *Gang) tryInitByPodGroup(pg *v1alpha1.PodGroup, args *config.Coschedu
233251
234252 gang .NetworkTopologySpec , err = extension .GetNetworkTopologySpec (pg )
235253 if err != nil {
236- klog .V ( 4 ). ErrorS (err , "podGroup's annotation AnnotationGangNetworkTopologySpec illegal" ,
254+ klog .ErrorS (err , "podGroup's annotation AnnotationGangNetworkTopologySpec illegal" ,
237255 "gangName" , gang .Name , "value" , pg .Annotations [extension .AnnotationGangNetworkTopologySpec ])
238256 }
239257
0 commit comments