sigs.k8s.io/kueue@v0.6.2/pkg/util/equality/podset.go (about) 1 /* 2 Copyright 2023 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 equality 18 19 import ( 20 corev1 "k8s.io/api/core/v1" 21 "k8s.io/apimachinery/pkg/api/equality" 22 "k8s.io/utils/ptr" 23 24 kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1" 25 ) 26 27 // TODO: Revisit this, maybe we should extend the check to everything that could potentially impact 28 // the workload scheduling (priority, nodeSelectors(when suspended), tolerations and maybe more) 29 func comparePodTemplate(a, b *corev1.PodSpec) bool { 30 if !equality.Semantic.DeepEqual(a.Tolerations, b.Tolerations) { 31 return false 32 } 33 if !equality.Semantic.DeepEqual(a.InitContainers, b.InitContainers) { 34 return false 35 } 36 return equality.Semantic.DeepEqual(a.Containers, b.Containers) 37 } 38 39 func ComparePodSets(a, b *kueue.PodSet) bool { 40 if a.Count != b.Count { 41 return false 42 } 43 if ptr.Deref(a.MinCount, -1) != ptr.Deref(b.MinCount, -1) { 44 return false 45 } 46 47 return comparePodTemplate(&a.Template.Spec, &b.Template.Spec) 48 } 49 50 func ComparePodSetSlices(a, b []kueue.PodSet) bool { 51 if len(a) != len(b) { 52 return false 53 } 54 for i := range a { 55 if !ComparePodSets(&a[i], &b[i]) { 56 return false 57 } 58 } 59 return true 60 }