Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace DeepEqual to Diff compare on scheduler-binding #109662

Merged
merged 1 commit into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/scheduler/framework/plugins/volumebinding/binder.go
Expand Up @@ -508,6 +508,7 @@ func (b *volumeBinder) bindAPIUpdate(ctx context.Context, pod *v1.Pod, bindings
klog.V(4).InfoS("Updating PersistentVolume: binding to claim failed", "PV", klog.KObj(binding.pv), "PVC", klog.KObj(binding.pvc), "err", err)
return err
}

klog.V(4).InfoS("Updating PersistentVolume: bound to claim", "PV", klog.KObj(binding.pv), "PVC", klog.KObj(binding.pvc))
// Save updated object from apiserver for later checking.
binding.pv = newPV
Expand All @@ -520,8 +521,10 @@ func (b *volumeBinder) bindAPIUpdate(ctx context.Context, pod *v1.Pod, bindings
klog.V(5).InfoS("Updating claims objects to trigger volume provisioning", "pod", klog.KObj(pod), "PVC", klog.KObj(claim))
newClaim, err := b.kubeClient.CoreV1().PersistentVolumeClaims(claim.Namespace).Update(ctx, claim, metav1.UpdateOptions{})
if err != nil {
klog.V(4).InfoS("Updating PersistentVolumeClaim: binding to volume failed", "PVC", klog.KObj(claim), "err", err)
return err
}

// Save updated object from apiserver for later checking.
claimsToProvision[i] = newClaim
lastProcessedProvisioning++
Expand Down
24 changes: 12 additions & 12 deletions pkg/scheduler/framework/plugins/volumebinding/binder_test.go
Expand Up @@ -20,17 +20,17 @@ import (
"context"
"fmt"
"os"
"reflect"
"sort"
"testing"
"time"

"github.com/google/go-cmp/cmp"

v1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
utilfeature "k8s.io/apiserver/pkg/util/feature"
Expand Down Expand Up @@ -433,13 +433,13 @@ func (env *testEnv) validatePodCache(t *testing.T, node string, pod *v1.Pod, pod
} else {
for i := 0; i < aLen; i++ {
// Validate PV
if !reflect.DeepEqual(expectedBindings[i].pv, bindings[i].pv) {
t.Errorf("binding.pv doesn't match [A-expected, B-got]: %s", diff.ObjectDiff(expectedBindings[i].pv, bindings[i].pv))
if diff := cmp.Diff(expectedBindings[i].pv, bindings[i].pv); diff != "" {
t.Errorf("binding.pv doesn't match (-want, +got):\n%s", diff)
}

// Validate PVC
if !reflect.DeepEqual(expectedBindings[i].pvc, bindings[i].pvc) {
t.Errorf("binding.pvc doesn't match [A-expected, B-got]: %s", diff.ObjectDiff(expectedBindings[i].pvc, bindings[i].pvc))
if diff := cmp.Diff(expectedBindings[i].pvc, bindings[i].pvc); diff != "" {
t.Errorf("binding.pvc doesn't match (-want, +got):\n%s", diff)
}
}
}
Expand All @@ -454,8 +454,8 @@ func (env *testEnv) validatePodCache(t *testing.T, node string, pod *v1.Pod, pod
t.Error("expected empty provisionings, got nil")
} else {
for i := 0; i < aLen; i++ {
if !reflect.DeepEqual(expectedProvisionings[i], provisionedClaims[i]) {
t.Errorf("provisioned claims doesn't match [A-expected, B-got]: %s", diff.ObjectDiff(expectedProvisionings[i], provisionedClaims[i]))
if diff := cmp.Diff(expectedProvisionings[i], provisionedClaims[i]); diff != "" {
t.Errorf("provisioned claims doesn't match (-want, +got):\n%s", diff)
}
}
}
Expand Down Expand Up @@ -540,8 +540,8 @@ func (env *testEnv) validateBind(
// Cache may be overridden by API object with higher version, compare but ignore resource version.
newCachedPV := cachedPV.DeepCopy()
newCachedPV.ResourceVersion = pv.ResourceVersion
if !reflect.DeepEqual(newCachedPV, pv) {
t.Errorf("cached PV check failed [A-expected, B-got]:\n%s", diff.ObjectDiff(pv, cachedPV))
if diff := cmp.Diff(pv, newCachedPV); diff != "" {
t.Errorf("cached PV check failed (-want, +got):\n%s", diff)
}
}

Expand All @@ -567,8 +567,8 @@ func (env *testEnv) validateProvision(
// Cache may be overridden by API object with higher version, compare but ignore resource version.
newCachedPVC := cachedPVC.DeepCopy()
newCachedPVC.ResourceVersion = pvc.ResourceVersion
if !reflect.DeepEqual(newCachedPVC, pvc) {
t.Errorf("cached PVC check failed [A-expected, B-got]:\n%s", diff.ObjectDiff(pvc, cachedPVC))
if diff := cmp.Diff(pvc, newCachedPVC); diff != "" {
t.Errorf("cached PVC check failed (-want, +got):\n%s", diff)
}
}

Expand Down