@@ -203,12 +203,28 @@ func buildOBClusterTopologyResp(ctx context.Context, obcluster *v1alpha1.OBClust
203203 affinities := make ([]modelcommon.AffinitySpec , 0 )
204204 if obzone .Spec .Topology .Affinity != nil {
205205 zoneAffinity := obzone .Spec .Topology .Affinity
206- switch {
207- case zoneAffinity .NodeAffinity != nil :
208- for _ , term := range zoneAffinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms {
209- for _ , req := range term .MatchExpressions {
206+ if zoneAffinity .NodeAffinity != nil {
207+ zn := zoneAffinity .NodeAffinity
208+ if zn .RequiredDuringSchedulingIgnoredDuringExecution != nil {
209+ for _ , term := range zn .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms {
210+ for _ , req := range term .MatchExpressions {
211+ affinities = append (affinities , modelcommon.AffinitySpec {
212+ Type : modelcommon .NodeAffinityType ,
213+ SelectorExpression : modelcommon.SelectorExpression {
214+ Key : req .Key ,
215+ Operator : string (req .Operator ),
216+ Values : req .Values ,
217+ },
218+ })
219+ }
220+ }
221+ }
222+ for _ , term := range zn .PreferredDuringSchedulingIgnoredDuringExecution {
223+ for _ , req := range term .Preference .MatchExpressions {
210224 affinities = append (affinities , modelcommon.AffinitySpec {
211- Type : modelcommon .NodeAffinityType ,
225+ Type : modelcommon .NodeAffinityType ,
226+ Weight : term .Weight ,
227+ Preferred : true ,
212228 SelectorExpression : modelcommon.SelectorExpression {
213229 Key : req .Key ,
214230 Operator : string (req .Operator ),
@@ -217,8 +233,10 @@ func buildOBClusterTopologyResp(ctx context.Context, obcluster *v1alpha1.OBClust
217233 })
218234 }
219235 }
220- case zoneAffinity .PodAffinity != nil :
221- for _ , term := range zoneAffinity .PodAffinity .RequiredDuringSchedulingIgnoredDuringExecution {
236+ }
237+ if zoneAffinity .PodAffinity != nil {
238+ zp := zoneAffinity .PodAffinity
239+ for _ , term := range zp .RequiredDuringSchedulingIgnoredDuringExecution {
222240 for _ , req := range term .LabelSelector .MatchExpressions {
223241 affinities = append (affinities , modelcommon.AffinitySpec {
224242 Type : modelcommon .PodAffinityType ,
@@ -230,8 +248,24 @@ func buildOBClusterTopologyResp(ctx context.Context, obcluster *v1alpha1.OBClust
230248 })
231249 }
232250 }
233- case zoneAffinity .PodAntiAffinity != nil :
234- for _ , term := range zoneAffinity .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution {
251+ for _ , term := range zp .PreferredDuringSchedulingIgnoredDuringExecution {
252+ for _ , req := range term .PodAffinityTerm .LabelSelector .MatchExpressions {
253+ affinities = append (affinities , modelcommon.AffinitySpec {
254+ Type : modelcommon .PodAffinityType ,
255+ Weight : term .Weight ,
256+ Preferred : true ,
257+ SelectorExpression : modelcommon.SelectorExpression {
258+ Key : req .Key ,
259+ Operator : string (req .Operator ),
260+ Values : req .Values ,
261+ },
262+ })
263+ }
264+ }
265+ }
266+ if zoneAffinity .PodAntiAffinity != nil {
267+ zpa := zoneAffinity .PodAntiAffinity
268+ for _ , term := range zpa .RequiredDuringSchedulingIgnoredDuringExecution {
235269 for _ , req := range term .LabelSelector .MatchExpressions {
236270 affinities = append (affinities , modelcommon.AffinitySpec {
237271 Type : modelcommon .PodAntiAffinityType ,
@@ -243,14 +277,33 @@ func buildOBClusterTopologyResp(ctx context.Context, obcluster *v1alpha1.OBClust
243277 })
244278 }
245279 }
280+ for _ , term := range zpa .PreferredDuringSchedulingIgnoredDuringExecution {
281+ for _ , req := range term .PodAffinityTerm .LabelSelector .MatchExpressions {
282+ affinities = append (affinities , modelcommon.AffinitySpec {
283+ Type : modelcommon .PodAntiAffinityType ,
284+ Weight : term .Weight ,
285+ Preferred : true ,
286+ SelectorExpression : modelcommon.SelectorExpression {
287+ Key : req .Key ,
288+ Operator : string (req .Operator ),
289+ Values : req .Values ,
290+ },
291+ })
292+ }
293+ }
246294 }
247295 }
248296
249- tolerations := make ([]modelcommon.KVPair , 0 )
297+ tolerations := make ([]modelcommon.TolerationSpec , 0 )
250298 for _ , toleration := range obzone .Spec .Topology .Tolerations {
251- tolerations = append (tolerations , modelcommon.KVPair {
252- Key : toleration .Key ,
253- Value : toleration .Value ,
299+ tolerations = append (tolerations , modelcommon.TolerationSpec {
300+ KVPair : modelcommon.KVPair {
301+ Key : toleration .Key ,
302+ Value : toleration .Value ,
303+ },
304+ Operator : string (toleration .Operator ),
305+ Effect : string (toleration .Effect ),
306+ TolerationSeconds : toleration .TolerationSeconds ,
254307 })
255308 }
256309 respZone := response.OBZone {
0 commit comments