diff --git a/cmd/controller-manager/app/options/options_test.go b/cmd/controller-manager/app/options/options_test.go index 5918d58bf3..f93f0ed7bc 100644 --- a/cmd/controller-manager/app/options/options_test.go +++ b/cmd/controller-manager/app/options/options_test.go @@ -17,11 +17,11 @@ limitations under the License. package options import ( - "reflect" "testing" "time" "github.com/spf13/pflag" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/leaderelection/resourcelock" "k8s.io/component-base/config" @@ -79,7 +79,7 @@ func TestAddFlags(t *testing.T) { WorkerThreadsForGC: 1, } - if !reflect.DeepEqual(expected, s) { + if !equality.Semantic.DeepEqual(expected, s) { t.Errorf("Got different run options than expected.\nGot: %+v\nExpected: %+v\n", s, expected) } diff --git a/cmd/scheduler/app/options/options_test.go b/cmd/scheduler/app/options/options_test.go index d4f699d276..84f3065f71 100644 --- a/cmd/scheduler/app/options/options_test.go +++ b/cmd/scheduler/app/options/options_test.go @@ -17,11 +17,11 @@ limitations under the License. package options import ( - "reflect" "testing" "time" "github.com/spf13/pflag" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/leaderelection/resourcelock" "k8s.io/component-base/config" @@ -78,7 +78,7 @@ func TestAddFlags(t *testing.T) { CacheDumpFileDir: "/tmp", } - if !reflect.DeepEqual(expected, s) { + if !equality.Semantic.DeepEqual(expected, s) { t.Errorf("Got different run options than expected.\nGot: %+v\nExpected: %+v\n", s, expected) } } diff --git a/docs/ut_coverage/UT_coverage_v1.4.0.html b/docs/ut_coverage/UT_coverage_v1.4.0.html index fc639d6654..a341bdf680 100644 --- a/docs/ut_coverage/UT_coverage_v1.4.0.html +++ b/docs/ut_coverage/UT_coverage_v1.4.0.html @@ -4005,7 +4005,7 @@ } minResources := cc.calcPGMinResources(job) - if pg.Spec.MinMember != job.Spec.MinAvailable || !reflect.DeepEqual(pg.Spec.MinResources, minResources) { + if pg.Spec.MinMember != job.Spec.MinAvailable || !equality.Semantic.DeepEqual(pg.Spec.MinResources, minResources) { pg.Spec.MinMember = job.Spec.MinAvailable pg.Spec.MinResources = minResources pgShouldUpdate = true @@ -4269,7 +4269,7 @@ // NOTE: Since we only reconcile job based on Spec, we will ignore other attributes // For Job status, it's used internally and always been updated via our controller. - if reflect.DeepEqual(newJob.Spec, oldJob.Spec) && newJob.Status.State.Phase == oldJob.Status.State.Phase { + if equality.Semantic.DeepEqual(newJob.Spec, oldJob.Spec) && newJob.Status.State.Phase == oldJob.Status.State.Phase { klog.V(6).Infof("Job update event is ignored since no update in 'Spec'.") return } @@ -6097,7 +6097,7 @@ } // ignore update when status does not change - if reflect.DeepEqual(queueStatus, queue.Status) { + if equality.Semantic.DeepEqual(queueStatus, queue.Status) { return nil } @@ -12437,7 +12437,7 @@ newTransitionID := newCond.TransitionID newCond.TransitionID = oldCond.TransitionID - shouldUpdate := !reflect.DeepEqual(&newCond, &oldCond) + shouldUpdate := !equality.Semantic.DeepEqual(&newCond, &oldCond) newCond.LastTransitionTime = newTime newCond.TransitionID = newTransitionID @@ -12455,7 +12455,7 @@ oldCondition := oldStatus.Conditions oldStatus.Conditions = nil - return !reflect.DeepEqual(newStatus, oldStatus) || isPodGroupConditionsUpdated(newCondition, oldCondition) + return !equality.Semantic.DeepEqual(newStatus, oldStatus) || isPodGroupConditionsUpdated(newCondition, oldCondition) } // updateJob update specified job @@ -19010,7 +19010,7 @@ "k8s.io/api/admission/v1beta1" whv1beta1 "k8s.io/api/admissionregistration/v1beta1" v1 "k8s.io/api/core/v1" - apiequality "k8s.io/apimachinery/pkg/api/equality" + apieequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation/field" @@ -19234,7 +19234,7 @@ } } - if !apiequality.Semantic.DeepEqual(new.Spec, old.Spec) { + if !apieequality.Semantic.DeepEqual(new.Spec, old.Spec) { return fmt.Errorf("job updates may not change fields other than `minAvailable`, `tasks[*].replicas under spec`") } diff --git a/docs/ut_coverage/UT_coverage_v1.5.0.html b/docs/ut_coverage/UT_coverage_v1.5.0.html index 65feebce08..1eaaa796fe 100644 --- a/docs/ut_coverage/UT_coverage_v1.5.0.html +++ b/docs/ut_coverage/UT_coverage_v1.5.0.html @@ -4265,7 +4265,7 @@ } minResources := cc.calcPGMinResources(job) - if pg.Spec.MinMember != job.Spec.MinAvailable || !reflect.DeepEqual(pg.Spec.MinResources, minResources) { + if pg.Spec.MinMember != job.Spec.MinAvailable || !equality.Semantic.DeepEqual(pg.Spec.MinResources, minResources) { pg.Spec.MinMember = job.Spec.MinAvailable pg.Spec.MinResources = minResources pgShouldUpdate = true @@ -4537,7 +4537,7 @@ // NOTE: Since we only reconcile job based on Spec, we will ignore other attributes // For Job status, it's used internally and always been updated via our controller. - if reflect.DeepEqual(newJob.Spec, oldJob.Spec) && newJob.Status.State.Phase == oldJob.Status.State.Phase { + if equality.Semantic.DeepEqual(newJob.Spec, oldJob.Spec) && newJob.Status.State.Phase == oldJob.Status.State.Phase { klog.V(6).Infof("Job update event is ignored since no update in 'Spec'.") return } @@ -6584,7 +6584,7 @@ } // ignore update when status does not change - if reflect.DeepEqual(queueStatus, queue.Status) { + if equality.Semantic.DeepEqual(queueStatus, queue.Status) { return nil } @@ -13646,7 +13646,7 @@ newTransitionID := newCond.TransitionID newCond.TransitionID = oldCond.TransitionID - shouldUpdate := !reflect.DeepEqual(&newCond, &oldCond) + shouldUpdate := !equality.Semantic.DeepEqual(&newCond, &oldCond) newCond.LastTransitionTime = newTime newCond.TransitionID = newTransitionID @@ -13664,7 +13664,7 @@ oldCondition := oldStatus.Conditions oldStatus.Conditions = nil - return !reflect.DeepEqual(newStatus, oldStatus) || isPodGroupConditionsUpdated(newCondition, oldCondition) + return !equality.Semantic.DeepEqual(newStatus, oldStatus) || isPodGroupConditionsUpdated(newCondition, oldCondition) } // updateJob update specified job @@ -20285,7 +20285,7 @@ "k8s.io/api/admission/v1beta1" whv1beta1 "k8s.io/api/admissionregistration/v1beta1" v1 "k8s.io/api/core/v1" - apiequality "k8s.io/apimachinery/pkg/api/equality" + apieequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation/field" @@ -20521,7 +20521,7 @@ } } - if !apiequality.Semantic.DeepEqual(new.Spec, old.Spec) { + if !apieequality.Semantic.DeepEqual(new.Spec, old.Spec) { return fmt.Errorf("job updates may not change fields other than `minAvailable`, `tasks[*].replicas under spec`") } diff --git a/pkg/controllers/job/job_controller_actions.go b/pkg/controllers/job/job_controller_actions.go index 2964ec98b0..f0bdc54f36 100644 --- a/pkg/controllers/job/job_controller_actions.go +++ b/pkg/controllers/job/job_controller_actions.go @@ -19,13 +19,13 @@ package job import ( "context" "fmt" - "reflect" "sort" "sync" "sync/atomic" "time" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" quotav1 "k8s.io/apiserver/pkg/quota/v1" @@ -712,7 +712,7 @@ func (cc *jobcontroller) createOrUpdatePodGroup(job *batch.Job) error { } minResources := cc.calcPGMinResources(job) - if pg.Spec.MinMember != job.Spec.MinAvailable || !reflect.DeepEqual(pg.Spec.MinResources, minResources) { + if pg.Spec.MinMember != job.Spec.MinAvailable || !equality.Semantic.DeepEqual(pg.Spec.MinResources, minResources) { pg.Spec.MinMember = job.Spec.MinAvailable pg.Spec.MinResources = minResources pgShouldUpdate = true diff --git a/pkg/controllers/job/job_controller_handler.go b/pkg/controllers/job/job_controller_handler.go index 3f632d508d..6c8f4d34b7 100644 --- a/pkg/controllers/job/job_controller_handler.go +++ b/pkg/controllers/job/job_controller_handler.go @@ -19,10 +19,10 @@ package job import ( "context" "fmt" - "reflect" "strconv" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/cache" @@ -97,7 +97,7 @@ func (cc *jobcontroller) updateJob(oldObj, newObj interface{}) { // NOTE: Since we only reconcile job based on Spec, we will ignore other attributes // For Job status, it's used internally and always been updated via our controller. - if reflect.DeepEqual(newJob.Spec, oldJob.Spec) && newJob.Status.State.Phase == oldJob.Status.State.Phase { + if equality.Semantic.DeepEqual(newJob.Spec, oldJob.Spec) && newJob.Status.State.Phase == oldJob.Status.State.Phase { klog.V(6).Infof("Job update event is ignored since no update in 'Spec'.") return } diff --git a/pkg/controllers/job/plugins/distributed-framework/pytorch/pytorch_test.go b/pkg/controllers/job/plugins/distributed-framework/pytorch/pytorch_test.go index 95abbd4389..ce8a138e31 100644 --- a/pkg/controllers/job/plugins/distributed-framework/pytorch/pytorch_test.go +++ b/pkg/controllers/job/plugins/distributed-framework/pytorch/pytorch_test.go @@ -2,10 +2,10 @@ package pytorch import ( "fmt" - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "volcano.sh/apis/pkg/apis/batch/v1alpha1" @@ -365,7 +365,7 @@ func TestPytorch(t *testing.T) { } } - if !reflect.DeepEqual(testcase.Pod.Spec.Containers[0].Env, testcase.envs) { + if !equality.Semantic.DeepEqual(testcase.Pod.Spec.Containers[0].Env, testcase.envs) { t.Errorf("Case %d (%s): wrong envs, got %v, expected %v", index, testcase.Name, testcase.Pod.Spec.Containers[0].Env, testcase.envs) } }) diff --git a/pkg/controllers/jobflow/jobflow_controller_action_test.go b/pkg/controllers/jobflow/jobflow_controller_action_test.go index 4dc3026516..36f5d03750 100755 --- a/pkg/controllers/jobflow/jobflow_controller_action_test.go +++ b/pkg/controllers/jobflow/jobflow_controller_action_test.go @@ -18,10 +18,10 @@ package jobflow import ( "context" - "reflect" "testing" "time" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/informers" kubeclient "k8s.io/client-go/kubernetes/fake" @@ -186,7 +186,7 @@ func TestSyncJobFlowFunc(t *testing.T) { tt.args.jobFlow.Status.JobStatusList[i].RunningHistories[i2].StartTimestamp = metav1.Time{} } } - if !reflect.DeepEqual(&tt.args.jobFlow.Status, tt.want.jobFlowStatus) { + if !equality.Semantic.DeepEqual(&tt.args.jobFlow.Status, tt.want.jobFlowStatus) { t.Error("not the expected result") } }) @@ -249,7 +249,7 @@ func TestGetRunningHistoriesFunc(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := getRunningHistories(tt.args.jobStatusList, tt.args.job); !reflect.DeepEqual(got, tt.want) { + if got := getRunningHistories(tt.args.jobStatusList, tt.args.job); !equality.Semantic.DeepEqual(got, tt.want) { t.Errorf("getRunningHistories() = %v, want %v", got, tt.want) } }) @@ -409,7 +409,7 @@ func TestGetAllJobStatusFunc(t *testing.T) { got.JobStatusList[0].RunningHistories[0].StartTimestamp = metav1.Time{} got.JobStatusList[1].RunningHistories[0].StartTimestamp = metav1.Time{} } - if !reflect.DeepEqual(got, tt.want) { + if !equality.Semantic.DeepEqual(got, tt.want) { t.Errorf("getAllJobStatus() got = %v, want %v", got, tt.want) } }) @@ -489,13 +489,13 @@ func TestLoadJobTemplateAndSetJobFunc(t *testing.T) { if got := fakeController.loadJobTemplateAndSetJob(tt.args.jobFlow, tt.args.flowName, tt.args.jobName, tt.args.job); got != tt.want.Err { t.Error("Expected loadJobTemplateAndSetJob() return nil, but not nil") } - if !reflect.DeepEqual(tt.args.job.OwnerReferences, tt.want.OwnerReference) { + if !equality.Semantic.DeepEqual(tt.args.job.OwnerReferences, tt.want.OwnerReference) { t.Error("not expected job OwnerReferences") } - if !reflect.DeepEqual(tt.args.job.Annotations, tt.want.Annotations) { + if !equality.Semantic.DeepEqual(tt.args.job.Annotations, tt.want.Annotations) { t.Error("not expected job Annotations") } - if !reflect.DeepEqual(tt.args.job.Labels, tt.want.Labels) { + if !equality.Semantic.DeepEqual(tt.args.job.Labels, tt.want.Labels) { t.Error("not expected job Annotations") } }) diff --git a/pkg/controllers/jobtemplate/jobtemplate_controller_action_test.go b/pkg/controllers/jobtemplate/jobtemplate_controller_action_test.go index 66e72d9737..5a3c259ea1 100755 --- a/pkg/controllers/jobtemplate/jobtemplate_controller_action_test.go +++ b/pkg/controllers/jobtemplate/jobtemplate_controller_action_test.go @@ -18,7 +18,7 @@ package jobtemplate import ( "context" - "reflect" + "k8s.io/apimachinery/pkg/api/equality" "testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -117,7 +117,7 @@ func TestSyncJobTemplateFunc(t *testing.T) { if got := fakeController.syncJobTemplate(tt.args.jobTemplate); got != tt.want.err { t.Error("Expected deleteAllJobsCreateByJobFlow() return nil, but not nil") } - if !reflect.DeepEqual(&tt.args.jobTemplate.Status, tt.want.jobTemplateStatus) { + if !equality.Semantic.DeepEqual(&tt.args.jobTemplate.Status, tt.want.jobTemplateStatus) { t.Error("not the expected result") } }) diff --git a/pkg/controllers/podgroup/pg_controller_test.go b/pkg/controllers/podgroup/pg_controller_test.go index dfb2a0d7c4..580ac3afcb 100644 --- a/pkg/controllers/podgroup/pg_controller_test.go +++ b/pkg/controllers/podgroup/pg_controller_test.go @@ -18,10 +18,10 @@ package podgroup import ( "context" - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/informers" @@ -169,7 +169,7 @@ func TestAddPodGroup(t *testing.T) { t.Errorf("Case %s failed when getting podGroup for %v", testCase.name, err) } - if false == reflect.DeepEqual(pg.OwnerReferences, testCase.expectedPodGroup.OwnerReferences) { + if false == equality.Semantic.DeepEqual(pg.OwnerReferences, testCase.expectedPodGroup.OwnerReferences) { t.Errorf("Case %s failed, expect %v, got %v", testCase.name, testCase.expectedPodGroup, pg) } diff --git a/pkg/controllers/queue/queue_controller_action.go b/pkg/controllers/queue/queue_controller_action.go index d6729231e5..8055bc7981 100644 --- a/pkg/controllers/queue/queue_controller_action.go +++ b/pkg/controllers/queue/queue_controller_action.go @@ -19,9 +19,9 @@ package queue import ( "context" "fmt" - "reflect" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" @@ -75,7 +75,7 @@ func (c *queuecontroller) syncQueue(queue *schedulingv1beta1.Queue, updateStateF } // ignore update when status does not change - if reflect.DeepEqual(queueStatus, queue.Status) { + if equality.Semantic.DeepEqual(queueStatus, queue.Status) { return nil } diff --git a/pkg/scheduler/actions/allocate/allocate_test.go b/pkg/scheduler/actions/allocate/allocate_test.go index fb23ce76da..16ec4545b8 100644 --- a/pkg/scheduler/actions/allocate/allocate_test.go +++ b/pkg/scheduler/actions/allocate/allocate_test.go @@ -25,6 +25,7 @@ import ( "github.com/agiledragon/gomonkey/v2" v1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" @@ -322,10 +323,10 @@ func TestAllocateWithDynamicPVC(t *testing.T) { allocate.Execute(ssn) bindResults := binder.Binds() - if !reflect.DeepEqual(test.expectedBind, bindResults) { + if !equality.Semantic.DeepEqual(test.expectedBind, bindResults) { t.Errorf("expected: %v, got %v ", test.expectedBind, bindResults) } - if !reflect.DeepEqual(test.expectedActions, fakeVolumeBinder.Actions) { + if !equality.Semantic.DeepEqual(test.expectedActions, fakeVolumeBinder.Actions) { t.Errorf("expected: %v, got %v ", test.expectedActions, fakeVolumeBinder.Actions) } fakeVolumeBinder.Actions = make(map[string][]string) diff --git a/pkg/scheduler/api/helpers/helpers_test.go b/pkg/scheduler/api/helpers/helpers_test.go index 676c710409..12f49302e0 100644 --- a/pkg/scheduler/api/helpers/helpers_test.go +++ b/pkg/scheduler/api/helpers/helpers_test.go @@ -1,10 +1,10 @@ package helpers import ( - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "volcano.sh/volcano/pkg/scheduler/api" ) @@ -36,7 +36,7 @@ func TestMax(t *testing.T) { }, } re := Max(l, r) - if !reflect.DeepEqual(expected, re) { + if !equality.Semantic.DeepEqual(expected, re) { t.Errorf("expected: %#v, got: %#v", expected, re) } } diff --git a/pkg/scheduler/api/job_info_test.go b/pkg/scheduler/api/job_info_test.go index 3a83ed508c..fc2ba232e0 100644 --- a/pkg/scheduler/api/job_info_test.go +++ b/pkg/scheduler/api/job_info_test.go @@ -17,11 +17,11 @@ limitations under the License. package api import ( - "reflect" "testing" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -31,7 +31,7 @@ import ( ) func jobInfoEqual(l, r *JobInfo) bool { - return reflect.DeepEqual(l, r) + return equality.Semantic.DeepEqual(l, r) } func TestAddTaskInfo(t *testing.T) { diff --git a/pkg/scheduler/api/pod_info_test.go b/pkg/scheduler/api/pod_info_test.go index 4b02c648df..e192023388 100644 --- a/pkg/scheduler/api/pod_info_test.go +++ b/pkg/scheduler/api/pod_info_test.go @@ -17,11 +17,11 @@ limitations under the License. package api import ( - "reflect" "testing" "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -90,7 +90,7 @@ func TestGetPodResourceRequest(t *testing.T) { for i, test := range tests { req := GetPodResourceRequest(test.pod) - if !reflect.DeepEqual(req, test.expectedResource) { + if !equality.Semantic.DeepEqual(req, test.expectedResource) { t.Errorf("case %d(%s) failed: \n expected %v, \n got: %v \n", i, test.name, test.expectedResource, req) } @@ -183,7 +183,7 @@ func TestGetPodResourceWithoutInitContainers(t *testing.T) { for i, test := range tests { req := GetPodResourceWithoutInitContainers(test.pod) - if !reflect.DeepEqual(req, test.expectedResource) { + if !equality.Semantic.DeepEqual(req, test.expectedResource) { t.Errorf("case %d(%s) failed: \n expected %v, \n got: %v \n", i, test.name, test.expectedResource, req) } diff --git a/pkg/scheduler/api/resource_info_test.go b/pkg/scheduler/api/resource_info_test.go index 0463844bd7..49edc13e09 100644 --- a/pkg/scheduler/api/resource_info_test.go +++ b/pkg/scheduler/api/resource_info_test.go @@ -18,11 +18,11 @@ package api import ( "math" - "reflect" "sort" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" ) @@ -56,7 +56,7 @@ func TestNewResource(t *testing.T) { for _, test := range tests { r := NewResource(test.resourceList) - if !reflect.DeepEqual(test.expected, r) { + if !equality.Semantic.DeepEqual(test.expected, r) { t.Errorf("expected: %#v, got: %#v", test.expected, r) } } @@ -95,7 +95,7 @@ func TestResourceAddScalar(t *testing.T) { for _, test := range tests { test.resource.AddScalar(test.scalarName, test.scalarQuantity) - if !reflect.DeepEqual(test.expected, test.resource) { + if !equality.Semantic.DeepEqual(test.expected, test.resource) { t.Errorf("expected: %#v, got: %#v", test.expected, test.resource) } } @@ -141,7 +141,7 @@ func TestSetMaxResource(t *testing.T) { for _, test := range tests { test.resource1.SetMaxResource(test.resource2) - if !reflect.DeepEqual(test.expected, test.resource1) { + if !equality.Semantic.DeepEqual(test.expected, test.resource1) { t.Errorf("expected: %#v, got: %#v", test.expected, test.resource1) } } @@ -180,7 +180,7 @@ func TestIsZero(t *testing.T) { for _, test := range tests { flag := test.resource.IsZero(test.resourceName) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("expected: %#v, got: %#v", test.expected, flag) } } @@ -243,7 +243,7 @@ func TestAddResource(t *testing.T) { for _, test := range tests { test.resource1.Add(test.resource2) - if !reflect.DeepEqual(test.expected, test.resource1) { + if !equality.Semantic.DeepEqual(test.expected, test.resource1) { t.Errorf("expected: %#v, got: %#v", test.expected, test.resource1) } } @@ -289,7 +289,7 @@ func TestSubResource(t *testing.T) { for _, test := range tests { test.resource1.Sub(test.resource2) - if !reflect.DeepEqual(test.expected, test.resource1) { + if !equality.Semantic.DeepEqual(test.expected, test.resource1) { t.Errorf("expected: %#v, got: %#v", test.expected, test.resource1) } } @@ -450,19 +450,19 @@ func TestDiff(t *testing.T) { for _, test := range testsForDefaultZero { increased, decreased := test.resource1.Diff(test.resource2, Zero) - if !reflect.DeepEqual(test.expectedIncreased, increased) { + if !equality.Semantic.DeepEqual(test.expectedIncreased, increased) { t.Errorf("expected: %#v, got: %#v", test.expectedIncreased, increased) } - if !reflect.DeepEqual(test.expectedDecreased, decreased) { + if !equality.Semantic.DeepEqual(test.expectedDecreased, decreased) { t.Errorf("expected: %#v, got: %#v", test.expectedDecreased, decreased) } } for _, test := range testsForDefaultInfinity { increased, decreased := test.resource1.Diff(test.resource2, Infinity) - if !reflect.DeepEqual(test.expectedIncreased, increased) { + if !equality.Semantic.DeepEqual(test.expectedIncreased, increased) { t.Errorf("expected: %#v, got: %#v", test.expectedIncreased, increased) } - if !reflect.DeepEqual(test.expectedDecreased, decreased) { + if !equality.Semantic.DeepEqual(test.expectedDecreased, decreased) { t.Errorf("expected: %#v, got: %#v", test.expectedDecreased, decreased) } } @@ -577,13 +577,13 @@ func TestLess(t *testing.T) { for caseID, test := range testsForDefaultZero { flag := test.resource1.Less(test.resource2, Zero) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("caseID %d expected: %#v, got: %#v", caseID, test.expected, flag) } } for caseID, test := range testsForDefaultInfinity { flag := test.resource1.Less(test.resource2, Infinity) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("caseID %d expected: %#v, got: %#v", caseID, test.expected, flag) } } @@ -741,13 +741,13 @@ func TestLessEqual(t *testing.T) { for _, test := range testsForDefaultZero { flag := test.resource1.LessEqual(test.resource2, Zero) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("expected: %#v, got: %#v", test.expected, flag) } } for caseID, test := range testsForDefaultInfinity { flag := test.resource1.LessEqual(test.resource2, Infinity) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("caseID %d expected: %#v, got: %#v", caseID, test.expected, flag) } } @@ -897,13 +897,13 @@ func TestLessPartly(t *testing.T) { for caseID, test := range testsForDefaultZero { flag := test.resource1.LessPartly(test.resource2, Zero) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("caseID %d expected: %#v, got: %#v", caseID, test.expected, flag) } } for _, test := range testsForDefaultInfinity { flag := test.resource1.LessPartly(test.resource2, Infinity) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("expected: %#v, got: %#v", test.expected, flag) } } @@ -1053,13 +1053,13 @@ func TestLessEqualPartly(t *testing.T) { for _, test := range testsForDefaultZero { flag := test.resource1.LessEqualPartly(test.resource2, Zero) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("expected: %#v, got: %#v", test.expected, flag) } } for _, test := range testsForDefaultInfinity { flag := test.resource1.LessEqualPartly(test.resource2, Infinity) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("expected: %#v, got: %#v", test.expected, flag) } } @@ -1115,7 +1115,7 @@ func TestEqual(t *testing.T) { for _, test := range tests { flag := test.resource1.Equal(test.resource2, Zero) - if !reflect.DeepEqual(test.expected, flag) { + if !equality.Semantic.DeepEqual(test.expected, flag) { t.Errorf("expected: %#v, got: %#v", test.expected, flag) } } @@ -1198,7 +1198,7 @@ func TestMinDimensionResourceZero(t *testing.T) { for _, test := range tests { test.resource1.MinDimensionResource(test.resource2, Zero) - if !reflect.DeepEqual(test.expected, test.resource1) { + if !equality.Semantic.DeepEqual(test.expected, test.resource1) { t.Errorf("expected: %#v, got: %#v", test.expected, test.resource1) } } @@ -1247,7 +1247,7 @@ func TestMinDimensionResourceInfinity(t *testing.T) { for _, test := range tests { test.resource1.MinDimensionResource(test.resource2, Infinity) - if !reflect.DeepEqual(test.expected, test.resource1) { + if !equality.Semantic.DeepEqual(test.expected, test.resource1) { t.Errorf("expected: %#v, got: %#v", test.expected, test.resource1) } } @@ -1383,7 +1383,7 @@ func TestResource_LessEqualResource(t *testing.T) { _, reason := test.resource1.LessEqualWithResourcesName(test.resource2, Zero) sort.Strings(test.expected) sort.Strings(reason) - if !reflect.DeepEqual(test.expected, reason) { + if !equality.Semantic.DeepEqual(test.expected, reason) { t.Errorf("expected: %#v, got: %#v", test.expected, reason) } } @@ -1391,7 +1391,7 @@ func TestResource_LessEqualResource(t *testing.T) { _, reason := test.resource1.LessEqualWithResourcesName(test.resource2, Infinity) sort.Strings(test.expected) sort.Strings(reason) - if !reflect.DeepEqual(test.expected, reason) { + if !equality.Semantic.DeepEqual(test.expected, reason) { t.Errorf("caseID %d expected: %#v, got: %#v", caseID, test.expected, reason) } } diff --git a/pkg/scheduler/cache/cache_test.go b/pkg/scheduler/cache/cache_test.go index 0e13f91b10..2830b11616 100644 --- a/pkg/scheduler/cache/cache_test.go +++ b/pkg/scheduler/cache/cache_test.go @@ -24,6 +24,7 @@ import ( "time" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" @@ -196,7 +197,7 @@ func TestSchedulerCache_Bind_NodeWithInsufficientResources(t *testing.T) { if err != nil { t.Errorf("expected to find task after failed bind") } - if !reflect.DeepEqual(taskBeforeBind, taskAfterBind) { + if !equality.Semantic.DeepEqual(taskBeforeBind, taskAfterBind) { t.Errorf("expected task to remain the same after failed bind: \n %#v\n %#v", taskBeforeBind, taskAfterBind) } diff --git a/pkg/scheduler/cache/event_handlers.go b/pkg/scheduler/cache/event_handlers.go index f47cd7b4ec..fa9b80de82 100644 --- a/pkg/scheduler/cache/event_handlers.go +++ b/pkg/scheduler/cache/event_handlers.go @@ -20,12 +20,12 @@ import ( "context" "fmt" "math" - "reflect" "strconv" v1 "k8s.io/api/core/v1" schedulingv1 "k8s.io/api/scheduling/v1" sv1 "k8s.io/api/storage/v1" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -644,7 +644,7 @@ func (sc *SchedulerCache) UpdateCSINode(oldObj, newObj interface{}) { if !ok { return } - if reflect.DeepEqual(oldCSINode.Spec, newCSINode.Spec) { + if equality.Semantic.DeepEqual(oldCSINode.Spec, newCSINode.Spec) { return } sc.AddOrUpdateCSINode(newObj) diff --git a/pkg/scheduler/capabilities/volumebinding/binder_test.go b/pkg/scheduler/capabilities/volumebinding/binder_test.go index 4fdcab8cb8..98c5e979aa 100644 --- a/pkg/scheduler/capabilities/volumebinding/binder_test.go +++ b/pkg/scheduler/capabilities/volumebinding/binder_test.go @@ -20,13 +20,13 @@ import ( "context" "fmt" "os" - "reflect" "sort" "testing" "time" "github.com/google/go-cmp/cmp" storagev1beta1 "k8s.io/api/storage/v1beta1" + "k8s.io/apimachinery/pkg/api/equality" storageinformersv1beta1 "k8s.io/client-go/informers/storage/v1beta1" v1 "k8s.io/api/core/v1" @@ -2457,12 +2457,12 @@ func TestGetEligibleNodes(t *testing.T) { eligibleNodes := testEnv.binder.GetEligibleNodes(logger, scenario.pvcs) // Validate - if reflect.DeepEqual(scenario.eligibleNodes, eligibleNodes) { + if equality.Semantic.DeepEqual(scenario.eligibleNodes, eligibleNodes) { fmt.Println("foo") } if compDiff := cmp.Diff(scenario.eligibleNodes, eligibleNodes, cmp.Comparer(func(a, b sets.Set[string]) bool { - return reflect.DeepEqual(a, b) + return equality.Semantic.DeepEqual(a, b) })); compDiff != "" { t.Errorf("Unexpected eligible nodes (-want +got):\n%s", compDiff) } diff --git a/pkg/scheduler/framework/arguments_test.go b/pkg/scheduler/framework/arguments_test.go index f60342d503..dec4b4cdd3 100644 --- a/pkg/scheduler/framework/arguments_test.go +++ b/pkg/scheduler/framework/arguments_test.go @@ -17,9 +17,10 @@ limitations under the License. package framework import ( - "reflect" "testing" + "k8s.io/apimachinery/pkg/api/equality" + "volcano.sh/volcano/pkg/scheduler/conf" ) @@ -181,7 +182,7 @@ func TestGetArgOfActionFromConf(t *testing.T) { for index, c := range cases { arg := GetArgOfActionFromConf(c.configurations, c.action) - if false == reflect.DeepEqual(arg, c.expectedArguments) { + if false == equality.Semantic.DeepEqual(arg, c.expectedArguments) { t.Errorf("index %d, case %s,expected %v, but got %v", index, c.name, c.expectedArguments, arg) } } diff --git a/pkg/scheduler/framework/job_updater.go b/pkg/scheduler/framework/job_updater.go index 2b90b81e6c..80ba52987d 100644 --- a/pkg/scheduler/framework/job_updater.go +++ b/pkg/scheduler/framework/job_updater.go @@ -3,9 +3,9 @@ package framework import ( "context" "math/rand" - "reflect" "time" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" @@ -66,7 +66,7 @@ func isPodGroupConditionsUpdated(newCondition, oldCondition []scheduling.PodGrou newTransitionID := newCond.TransitionID newCond.TransitionID = oldCond.TransitionID - shouldUpdate := !reflect.DeepEqual(&newCond, &oldCond) + shouldUpdate := !equality.Semantic.DeepEqual(&newCond, &oldCond) newCond.LastTransitionTime = newTime newCond.TransitionID = newTransitionID @@ -84,7 +84,7 @@ func isPodGroupStatusUpdated(newStatus, oldStatus scheduling.PodGroupStatus) boo oldCondition := oldStatus.Conditions oldStatus.Conditions = nil - return !reflect.DeepEqual(newStatus, oldStatus) || isPodGroupConditionsUpdated(newCondition, oldCondition) + return !equality.Semantic.DeepEqual(newStatus, oldStatus) || isPodGroupConditionsUpdated(newCondition, oldCondition) } // updateJob update specified job diff --git a/pkg/scheduler/framework/session.go b/pkg/scheduler/framework/session.go index 993238dbbb..eccfbe62f0 100644 --- a/pkg/scheduler/framework/session.go +++ b/pkg/scheduler/framework/session.go @@ -18,9 +18,9 @@ package framework import ( "fmt" - "reflect" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/uuid" @@ -210,7 +210,7 @@ func updateQueueStatus(ssn *Session) { for queueID := range ssn.Queues { // convert api.Resource to v1.ResourceList var queueStatus = util.ConvertRes2ResList(allocatedResources[queueID]).DeepCopy() - if reflect.DeepEqual(ssn.Queues[queueID].Queue.Status.Allocated, queueStatus) { + if equality.Semantic.DeepEqual(ssn.Queues[queueID].Queue.Status.Allocated, queueStatus) { klog.V(5).Infof("Queue <%s> allocated resource keeps equal, no need to update queue status <%v>.", queueID, ssn.Queues[queueID].Queue.Status.Allocated) continue diff --git a/pkg/scheduler/plugins/cdp/cdp_test.go b/pkg/scheduler/plugins/cdp/cdp_test.go index 36f339d4d5..85598d6afa 100644 --- a/pkg/scheduler/plugins/cdp/cdp_test.go +++ b/pkg/scheduler/plugins/cdp/cdp_test.go @@ -17,11 +17,11 @@ limitations under the License. package cdp import ( - "reflect" "testing" "time" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "volcano.sh/apis/pkg/apis/scheduling/v1beta1" @@ -157,7 +157,7 @@ func TestPreemptableFn(t *testing.T) { victims := ssn.Preemptable(&api.TaskInfo{}, preemptees) expectVictims := []*api.TaskInfo{task2, task3} - if !reflect.DeepEqual(victims, expectVictims) { + if !equality.Semantic.DeepEqual(victims, expectVictims) { t.Errorf("stable preempt test not equal! expect victims %v, actual %v", expectVictims, victims) } } diff --git a/pkg/scheduler/plugins/conformance/conformance_test.go b/pkg/scheduler/plugins/conformance/conformance_test.go index 6237884291..58ad290fbd 100644 --- a/pkg/scheduler/plugins/conformance/conformance_test.go +++ b/pkg/scheduler/plugins/conformance/conformance_test.go @@ -1,10 +1,10 @@ package conformance import ( - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "volcano.sh/volcano/pkg/scheduler/api" "volcano.sh/volcano/pkg/scheduler/conf" @@ -56,7 +56,7 @@ func TestConformancePlugin(t *testing.T) { ssn := test.RegisterSession(tiers, nil) defer test.Close() victims := ssn.Preemptable(&api.TaskInfo{}, test.preemptees) - if !reflect.DeepEqual(victims, test.expectVictims) { + if !equality.Semantic.DeepEqual(victims, test.expectVictims) { t.Errorf("case: %s error, expect %v, but get %v", test.Name, test.expectVictims, victims) } }) diff --git a/pkg/scheduler/plugins/drf/hdrf_test.go b/pkg/scheduler/plugins/drf/hdrf_test.go index 69b481f018..83698778f3 100644 --- a/pkg/scheduler/plugins/drf/hdrf_test.go +++ b/pkg/scheduler/plugins/drf/hdrf_test.go @@ -2,10 +2,10 @@ package drf import ( "fmt" - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" schedulingv1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1" "volcano.sh/volcano/cmd/scheduler/app/options" @@ -204,7 +204,7 @@ func TestHDRF(t *testing.T) { defer test.Close() test.Run([]framework.Action{allocate.New()}) for _, job := range ssn.Jobs { - if reflect.DeepEqual(test.expected, job.Allocated) { + if equality.Semantic.DeepEqual(test.expected, job.Allocated) { t.Fatalf("%s: job %s expected resource %s, but got %s", test.Name, job.Name, test.expected[job.Name], job.Allocated) } } diff --git a/pkg/scheduler/plugins/numaaware/policy/policy_best_effort_test.go b/pkg/scheduler/plugins/numaaware/policy/policy_best_effort_test.go index 828258c1a5..c6a4fc9778 100644 --- a/pkg/scheduler/plugins/numaaware/policy/policy_best_effort_test.go +++ b/pkg/scheduler/plugins/numaaware/policy/policy_best_effort_test.go @@ -17,9 +17,9 @@ limitations under the License. package policy import ( - "reflect" "testing" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask" ) @@ -315,7 +315,7 @@ func Test_best_effort_predicate(t *testing.T) { for _, testcase := range testCases { policy := NewPolicyBestEffort([]int{0, 1}) bestHit, _ := policy.Predicate(testcase.providersHints) - if !reflect.DeepEqual(bestHit, testcase.expect) { + if !equality.Semantic.DeepEqual(bestHit, testcase.expect) { t.Errorf("%s failed, expect %v, bestHit= %v\n", testcase.name, testcase.expect, bestHit) } } diff --git a/pkg/scheduler/plugins/numaaware/policy/policy_none_test.go b/pkg/scheduler/plugins/numaaware/policy/policy_none_test.go index ed531006e5..9860bf52e5 100644 --- a/pkg/scheduler/plugins/numaaware/policy/policy_none_test.go +++ b/pkg/scheduler/plugins/numaaware/policy/policy_none_test.go @@ -17,8 +17,9 @@ limitations under the License. package policy import ( - "reflect" "testing" + + "k8s.io/apimachinery/pkg/api/equality" ) func Test_none_predicate(t *testing.T) { @@ -37,7 +38,7 @@ func Test_none_predicate(t *testing.T) { for _, testcase := range testCases { policy := NewPolicyNone([]int{0, 1}) bestHit, _ := policy.Predicate(testcase.providersHints) - if !reflect.DeepEqual(bestHit, testcase.expect) { + if !equality.Semantic.DeepEqual(bestHit, testcase.expect) { t.Errorf("%s failed, expect %v, bestHit= %v\n", testcase.name, testcase.expect, bestHit) } } diff --git a/pkg/scheduler/plugins/numaaware/policy/policy_restricted_test.go b/pkg/scheduler/plugins/numaaware/policy/policy_restricted_test.go index c1054bfa29..2c9be6c1ae 100644 --- a/pkg/scheduler/plugins/numaaware/policy/policy_restricted_test.go +++ b/pkg/scheduler/plugins/numaaware/policy/policy_restricted_test.go @@ -17,9 +17,9 @@ limitations under the License. package policy import ( - "reflect" "testing" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask" ) @@ -315,7 +315,7 @@ func Test_restricted_predicate(t *testing.T) { for _, testcase := range testCases { policy := NewPolicyRestricted([]int{0, 1}) bestHit, _ := policy.Predicate(testcase.providersHints) - if !reflect.DeepEqual(bestHit, testcase.expect) { + if !equality.Semantic.DeepEqual(bestHit, testcase.expect) { t.Errorf("%s failed, expect %v, bestHit= %v\n", testcase.name, testcase.expect, bestHit) } } diff --git a/pkg/scheduler/plugins/numaaware/policy/policy_single_numa_node_test.go b/pkg/scheduler/plugins/numaaware/policy/policy_single_numa_node_test.go index 5b041b9a68..19abd6b144 100644 --- a/pkg/scheduler/plugins/numaaware/policy/policy_single_numa_node_test.go +++ b/pkg/scheduler/plugins/numaaware/policy/policy_single_numa_node_test.go @@ -17,9 +17,9 @@ limitations under the License. package policy import ( - "reflect" "testing" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask" ) @@ -281,7 +281,7 @@ func Test_single_numa_node_predicate(t *testing.T) { for _, testcase := range testCases { policy := NewPolicySingleNumaNode([]int{0, 1}) bestHit, _ := policy.Predicate(testcase.providersHints) - if !reflect.DeepEqual(bestHit, testcase.expect) { + if !equality.Semantic.DeepEqual(bestHit, testcase.expect) { t.Errorf("%s failed, bestHit= %v\n", testcase.name, bestHit) } } diff --git a/pkg/scheduler/plugins/numaaware/provider/cpumanager/cpu_mng_test.go b/pkg/scheduler/plugins/numaaware/provider/cpumanager/cpu_mng_test.go index b176f73289..1e8307eb89 100644 --- a/pkg/scheduler/plugins/numaaware/provider/cpumanager/cpu_mng_test.go +++ b/pkg/scheduler/plugins/numaaware/provider/cpumanager/cpu_mng_test.go @@ -17,10 +17,10 @@ limitations under the License. package cpumanager import ( - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/topology" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask" @@ -200,7 +200,7 @@ func Test_GetTopologyHints(t *testing.T) { for _, testcase := range teseCases { provider := NewProvider() topologyHintmap := provider.GetTopologyHints(&testcase.container, &numaInfo, testcase.resNumaSets) - if !(reflect.DeepEqual(topologyHintmap["cpu"], testcase.expect) || + if !(equality.Semantic.DeepEqual(topologyHintmap["cpu"], testcase.expect) || (len(topologyHintmap["cpu"]) == 0 && len(testcase.expect) == 0)) { t.Errorf("%s failed. topologyHintmap = %v\n", testcase.name, topologyHintmap) } @@ -325,7 +325,7 @@ func Test_Allocate(t *testing.T) { for _, testcase := range teseCases { provider := NewProvider() assignMap := provider.Allocate(&testcase.container, testcase.bestHit, &numaInfo, testcase.resNumaSets) - if !(reflect.DeepEqual(assignMap["cpu"], testcase.expect)) { + if !(equality.Semantic.DeepEqual(assignMap["cpu"], testcase.expect)) { t.Errorf("%s failed.\n", testcase.name) } } diff --git a/pkg/scheduler/plugins/overcommit/overcommit_test.go b/pkg/scheduler/plugins/overcommit/overcommit_test.go index 1700377d05..39e0f309c3 100644 --- a/pkg/scheduler/plugins/overcommit/overcommit_test.go +++ b/pkg/scheduler/plugins/overcommit/overcommit_test.go @@ -1,10 +1,10 @@ package overcommit import ( - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "volcano.sh/apis/pkg/apis/scheduling" schedulingv1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1" @@ -112,7 +112,7 @@ func TestOvercommitPlugin(t *testing.T) { for _, job := range ssn.Jobs { ssn.JobEnqueued(job) isEnqueue := ssn.JobEnqueueable(job) - if !reflect.DeepEqual(test.expectedEnqueueAble, isEnqueue) { + if !equality.Semantic.DeepEqual(test.expectedEnqueueAble, isEnqueue) { t.Errorf("case: %s error, expect %v, but get %v", test.Name, test.expectedEnqueueAble, isEnqueue) } } diff --git a/pkg/scheduler/plugins/pdb/pdb_test.go b/pkg/scheduler/plugins/pdb/pdb_test.go index ebd17030e1..dcfedbdea2 100644 --- a/pkg/scheduler/plugins/pdb/pdb_test.go +++ b/pkg/scheduler/plugins/pdb/pdb_test.go @@ -17,11 +17,11 @@ limitations under the License. package pdb import ( - "reflect" "testing" v1 "k8s.io/api/core/v1" pdbPolicy "k8s.io/api/policy/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes/fake" @@ -135,19 +135,19 @@ func TestPreemptableAndReclaimableFn(t *testing.T) { // (e. test the Preemptable in pdb plugin victims := ssn.Preemptable(&api.TaskInfo{}, test.preemptees) - if !reflect.DeepEqual(test.expectVictims, victims) { + if !equality.Semantic.DeepEqual(test.expectVictims, victims) { t.Errorf("Test of preemptable: test name: %s, expected: %v, got %v ", test.name, test.expectVictims, victims) } // (f. test the Reclaimable in pdb plugin victims = ssn.Reclaimable(&api.TaskInfo{}, test.preemptees) - if !reflect.DeepEqual(test.expectVictims, victims) { + if !equality.Semantic.DeepEqual(test.expectVictims, victims) { t.Errorf("Test of reclaimable: test name: %s, expected: %v, got %v ", test.name, test.expectVictims, victims) } // (g. test the VictimTasks in pdb plugin victimsMap := ssn.VictimTasks(test.preemptees) - if !reflect.DeepEqual(test.expectVictimsMap, victimsMap) { + if !equality.Semantic.DeepEqual(test.expectVictimsMap, victimsMap) { t.Errorf("Test of victimTasks: test name %s, expected: %v, got %v ", test.name, test.expectVictims, victims) } } diff --git a/pkg/scheduler/plugins/proportion/proportion.go b/pkg/scheduler/plugins/proportion/proportion.go index 0f397a4744..831bcb71ef 100644 --- a/pkg/scheduler/plugins/proportion/proportion.go +++ b/pkg/scheduler/plugins/proportion/proportion.go @@ -18,9 +18,9 @@ package proportion import ( "math" - "reflect" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/klog/v2" "volcano.sh/apis/pkg/apis/scheduling" @@ -226,7 +226,7 @@ func (pp *proportionPlugin) OnSessionOpen(ssn *framework.Session) { if attr.request.LessEqual(attr.deserved, api.Zero) { meet[attr.queueID] = struct{}{} klog.V(4).Infof("queue <%s> is meet", attr.name) - } else if reflect.DeepEqual(attr.deserved, oldDeserved) { + } else if equality.Semantic.DeepEqual(attr.deserved, oldDeserved) { meet[attr.queueID] = struct{}{} klog.V(4).Infof("queue <%s> is meet cause of the capability", attr.name) } @@ -244,7 +244,7 @@ func (pp *proportionPlugin) OnSessionOpen(ssn *framework.Session) { remaining.Sub(increasedDeserved).Add(decreasedDeserved) klog.V(4).Infof("Remaining resource is <%s>", remaining) - if remaining.IsEmpty() || reflect.DeepEqual(remaining, oldRemaining) { + if remaining.IsEmpty() || equality.Semantic.DeepEqual(remaining, oldRemaining) { klog.V(4).Infof("Exiting when remaining is empty or no queue has more resource request: <%v>", remaining) break } diff --git a/pkg/scheduler/plugins/resourcequota/resourcequota_test.go b/pkg/scheduler/plugins/resourcequota/resourcequota_test.go index 6f614c8e45..34329a4ded 100644 --- a/pkg/scheduler/plugins/resourcequota/resourcequota_test.go +++ b/pkg/scheduler/plugins/resourcequota/resourcequota_test.go @@ -1,10 +1,10 @@ package resourcequota import ( - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "volcano.sh/apis/pkg/apis/scheduling" schedulingv1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1" @@ -93,7 +93,7 @@ func TestResourceQuotaPlugin(t *testing.T) { defer test.Close() for _, job := range ssn.Jobs { isEnqueue := ssn.JobEnqueueable(job) - if !reflect.DeepEqual(test.expectedEnqueueAble, isEnqueue) { + if !equality.Semantic.DeepEqual(test.expectedEnqueueAble, isEnqueue) { t.Errorf("case: %s error, expect %v, but get %v", test.Name, test.expectedEnqueueAble, isEnqueue) } } diff --git a/pkg/scheduler/plugins/sla/sla_test.go b/pkg/scheduler/plugins/sla/sla_test.go index 57edf3c6f4..6ef50452e8 100644 --- a/pkg/scheduler/plugins/sla/sla_test.go +++ b/pkg/scheduler/plugins/sla/sla_test.go @@ -1,10 +1,10 @@ package sla import ( - "reflect" "testing" "time" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "volcano.sh/apis/pkg/apis/scheduling" @@ -119,11 +119,11 @@ func TestSlaPlugin(t *testing.T) { ssn := test.RegisterSession(tiers, nil) defer test.Close() isOrder := ssn.JobOrderFn(job1, job2) - if !reflect.DeepEqual(test.expectedOrder, isOrder) { + if !equality.Semantic.DeepEqual(test.expectedOrder, isOrder) { t.Errorf("case: %s error, expect %v, but get %v", test.Name, test.expectedOrder, isOrder) } isEnqueue := ssn.JobEnqueueable(job1) - if !reflect.DeepEqual(test.expectedEnqueueAble, isEnqueue) { + if !equality.Semantic.DeepEqual(test.expectedEnqueueAble, isEnqueue) { t.Errorf("case: %s error, expect %v, but get %v", test.Name, test.expectedEnqueueAble, isEnqueue) } }) diff --git a/pkg/scheduler/uthelper/helper.go b/pkg/scheduler/uthelper/helper.go index 306d6822c6..912386f728 100644 --- a/pkg/scheduler/uthelper/helper.go +++ b/pkg/scheduler/uthelper/helper.go @@ -18,11 +18,11 @@ package uthelper import ( "fmt" - "reflect" "time" v1 "k8s.io/api/core/v1" schedulingv1 "k8s.io/api/scheduling/v1" + "k8s.io/apimachinery/pkg/api/equality" "volcano.sh/apis/pkg/apis/scheduling" vcapisv1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1" @@ -228,7 +228,7 @@ func (test *TestCommonStruct) CheckEvict(caseIndex int) error { got[v]++ } - if !reflect.DeepEqual(expect, got) { + if !equality.Semantic.DeepEqual(expect, got) { return fmt.Errorf("case %d(%s) check evict: \nwant: %v\n got: %v ", caseIndex, test.Name, expect, got) } return nil diff --git a/pkg/scheduler/util/scheduler_helper_test.go b/pkg/scheduler/util/scheduler_helper_test.go index ec0ddfada4..cf7aedf76a 100644 --- a/pkg/scheduler/util/scheduler_helper_test.go +++ b/pkg/scheduler/util/scheduler_helper_test.go @@ -17,9 +17,9 @@ limitations under the License. package util import ( - "reflect" "testing" + "k8s.io/apimachinery/pkg/api/equality" "volcano.sh/volcano/cmd/scheduler/app/options" "volcano.sh/volcano/pkg/scheduler/api" ) @@ -53,7 +53,7 @@ func TestSelectBestNode(t *testing.T) { oneOf := func(node *api.NodeInfo, nodes []*api.NodeInfo) bool { for _, v := range nodes { - if reflect.DeepEqual(node, v) { + if equality.Semantic.DeepEqual(node, v) { return true } } diff --git a/pkg/scheduler/util_test.go b/pkg/scheduler/util_test.go index 1aa645103d..2c5b3bbbd6 100644 --- a/pkg/scheduler/util_test.go +++ b/pkg/scheduler/util_test.go @@ -17,9 +17,10 @@ limitations under the License. package scheduler import ( - "reflect" "testing" + "k8s.io/apimachinery/pkg/api/equality" + _ "volcano.sh/volcano/pkg/scheduler/actions" "volcano.sh/volcano/pkg/scheduler/conf" ) @@ -204,11 +205,11 @@ tiers: if err != nil { t.Errorf("Failed to load Scheduler configuration: %v", err) } - if !reflect.DeepEqual(tiers, expectedTiers) { + if !equality.Semantic.DeepEqual(tiers, expectedTiers) { t.Errorf("Failed to set default settings for plugins, expected: %+v, got %+v", expectedTiers, tiers) } - if !reflect.DeepEqual(configurations, expectedConfigurations) { + if !equality.Semantic.DeepEqual(configurations, expectedConfigurations) { t.Errorf("Wrong configuration, expected: %+v, got %+v", expectedConfigurations, configurations) } diff --git a/pkg/webhooks/admission/jobs/validate/util_test.go b/pkg/webhooks/admission/jobs/validate/util_test.go index 26fa0363ab..84fbd23905 100644 --- a/pkg/webhooks/admission/jobs/validate/util_test.go +++ b/pkg/webhooks/admission/jobs/validate/util_test.go @@ -1,9 +1,9 @@ package validate import ( - "reflect" "testing" + "k8s.io/apimachinery/pkg/api/equality" "volcano.sh/apis/pkg/apis/batch/v1alpha1" ) @@ -128,7 +128,7 @@ func TestTopoSort(t *testing.T) { for _, testcase := range testCases { tasks, isDag := topoSort(testcase.job) - if isDag != testcase.isDag || !reflect.DeepEqual(tasks, testcase.sortedTasks) { + if isDag != testcase.isDag || !equality.Semantic.DeepEqual(tasks, testcase.sortedTasks) { t.Errorf("%s failed, expect sortedTasks: %v, got: %v, expected isDag: %v, got: %v", testcase.name, testcase.sortedTasks, tasks, testcase.isDag, isDag) } diff --git a/pkg/webhooks/admission/pods/mutate/mutate_pod_test.go b/pkg/webhooks/admission/pods/mutate/mutate_pod_test.go index f964ee8372..6db37bdae8 100644 --- a/pkg/webhooks/admission/pods/mutate/mutate_pod_test.go +++ b/pkg/webhooks/admission/pods/mutate/mutate_pod_test.go @@ -18,10 +18,10 @@ package mutate import ( "encoding/json" - "reflect" "testing" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" webconfig "volcano.sh/volcano/pkg/webhooks/config" @@ -209,7 +209,7 @@ func TestMutatePods(t *testing.T) { t.Run(testCase.Name, func(t *testing.T) { patchBytes, _ := createPatch(testCase.Pod) expectBytes, _ := json.Marshal(testCase.expect) - if !reflect.DeepEqual(patchBytes, expectBytes) { + if !equality.Semantic.DeepEqual(patchBytes, expectBytes) { t.Errorf("Test case '%s' failed, expect: %v, got: %v", testCase.Name, expectBytes, patchBytes) } diff --git a/pkg/webhooks/admission/queues/mutate/mutate_queue_test.go b/pkg/webhooks/admission/queues/mutate/mutate_queue_test.go index 95117fa319..24f5517869 100644 --- a/pkg/webhooks/admission/queues/mutate/mutate_queue_test.go +++ b/pkg/webhooks/admission/queues/mutate/mutate_queue_test.go @@ -19,11 +19,11 @@ package mutate import ( "encoding/json" "fmt" - "reflect" "strings" "testing" admissionv1 "k8s.io/api/admission/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -216,7 +216,7 @@ func TestMutateQueues(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.Name, func(t *testing.T) { reviewResponse := Queues(testCase.AR) - if !reflect.DeepEqual(reviewResponse, testCase.reviewResponse) { + if !equality.Semantic.DeepEqual(reviewResponse, testCase.reviewResponse) { t.Errorf("Test case '%s' failed, expect: %v, got: %v", testCase.Name, testCase.reviewResponse, reviewResponse) } diff --git a/pkg/webhooks/admission/queues/validate/validate_queue_test.go b/pkg/webhooks/admission/queues/validate/validate_queue_test.go index e6cb1acab4..32eccd27e6 100644 --- a/pkg/webhooks/admission/queues/validate/validate_queue_test.go +++ b/pkg/webhooks/admission/queues/validate/validate_queue_test.go @@ -20,10 +20,10 @@ import ( "context" "encoding/json" "fmt" - "reflect" "testing" admissionv1 "k8s.io/api/admission/v1" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" @@ -904,7 +904,7 @@ func TestAdmitQueues(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.Name, func(t *testing.T) { reviewResponse := AdmitQueues(testCase.AR) - if !reflect.DeepEqual(reviewResponse, testCase.reviewResponse) { + if !equality.Semantic.DeepEqual(reviewResponse, testCase.reviewResponse) { t.Errorf("Test case %s failed, expect %v, got %v", testCase.Name, testCase.reviewResponse, reviewResponse) }