manually revert #109877
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -32,7 +31,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/informers"
|
||||
@@ -63,9 +61,6 @@ var (
|
||||
boundPVCNode1a = makeTestPVC("unbound-pvc", "1G", "", pvcBound, "pv-node1a", "1", &waitClass)
|
||||
immediateUnboundPVC = makeTestPVC("immediate-unbound-pvc", "1G", "", pvcUnbound, "", "1", &immediateClass)
|
||||
immediateBoundPVC = makeTestPVC("immediate-bound-pvc", "1G", "", pvcBound, "pv-bound-immediate", "1", &immediateClass)
|
||||
localPreboundPVC1a = makeTestPVC("local-prebound-pvc-1a", "1G", "", pvcPrebound, "local-pv-node1a", "1", &waitClass)
|
||||
localPreboundPVC1b = makeTestPVC("local-prebound-pvc-1b", "1G", "", pvcPrebound, "local-pv-node1b", "1", &waitClass)
|
||||
localPreboundPVC2a = makeTestPVC("local-prebound-pvc-2a", "1G", "", pvcPrebound, "local-pv-node2a", "1", &waitClass)
|
||||
|
||||
// PVCs for dynamic provisioning
|
||||
provisionedPVC = makeTestPVC("provisioned-pvc", "1Gi", "", pvcUnbound, "", "1", &waitClassWithProvisioner)
|
||||
@@ -97,9 +92,6 @@ var (
|
||||
pvNode1bBoundHigherVersion = makeTestPV("pv-node1b", "node1", "10G", "2", unboundPVC2, waitClass)
|
||||
pvBoundImmediate = makeTestPV("pv-bound-immediate", "node1", "1G", "1", immediateBoundPVC, immediateClass)
|
||||
pvBoundImmediateNode2 = makeTestPV("pv-bound-immediate", "node2", "1G", "1", immediateBoundPVC, immediateClass)
|
||||
localPVNode1a = makeLocalPV("local-pv-node1a", "node1", "5G", "1", nil, waitClass)
|
||||
localPVNode1b = makeLocalPV("local-pv-node1b", "node1", "10G", "1", nil, waitClass)
|
||||
localPVNode2a = makeLocalPV("local-pv-node2a", "node2", "5G", "1", nil, waitClass)
|
||||
|
||||
// PVs for CSI migration
|
||||
migrationPVBound = makeTestPVForCSIMigration(zone1Labels, boundMigrationPVC, true)
|
||||
@@ -709,12 +701,6 @@ func makeTestPVForCSIMigration(labels map[string]string, pvc *v1.PersistentVolum
|
||||
return pv
|
||||
}
|
||||
|
||||
func makeLocalPV(name, node, capacity, version string, boundToPVC *v1.PersistentVolumeClaim, className string) *v1.PersistentVolume {
|
||||
pv := makeTestPV(name, node, capacity, version, boundToPVC, className)
|
||||
pv.Spec.NodeAffinity.Required.NodeSelectorTerms[0].MatchExpressions[0].Key = v1.LabelHostname
|
||||
return pv
|
||||
}
|
||||
|
||||
func pvcSetSelectedNode(pvc *v1.PersistentVolumeClaim, node string) *v1.PersistentVolumeClaim {
|
||||
newPVC := pvc.DeepCopy()
|
||||
metav1.SetMetaDataAnnotation(&newPVC.ObjectMeta, volume.AnnSelectedNode, node)
|
||||
@@ -2326,130 +2312,3 @@ func TestCapacity(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEligibleNodes(t *testing.T) {
|
||||
type scenarioType struct {
|
||||
// Inputs
|
||||
pvcs []*v1.PersistentVolumeClaim
|
||||
pvs []*v1.PersistentVolume
|
||||
nodes []*v1.Node
|
||||
|
||||
// Expected return values
|
||||
eligibleNodes sets.Set[string]
|
||||
}
|
||||
|
||||
scenarios := map[string]scenarioType{
|
||||
"no-bound-claims": {},
|
||||
"no-nodes-found": {
|
||||
pvcs: []*v1.PersistentVolumeClaim{
|
||||
preboundPVC,
|
||||
preboundPVCNode1a,
|
||||
},
|
||||
},
|
||||
"pv-not-found": {
|
||||
pvcs: []*v1.PersistentVolumeClaim{
|
||||
preboundPVC,
|
||||
preboundPVCNode1a,
|
||||
},
|
||||
nodes: []*v1.Node{
|
||||
node1,
|
||||
},
|
||||
},
|
||||
"node-affinity-mismatch": {
|
||||
pvcs: []*v1.PersistentVolumeClaim{
|
||||
preboundPVC,
|
||||
preboundPVCNode1a,
|
||||
},
|
||||
pvs: []*v1.PersistentVolume{
|
||||
pvNode1a,
|
||||
},
|
||||
nodes: []*v1.Node{
|
||||
node1,
|
||||
node2,
|
||||
},
|
||||
},
|
||||
"local-pv-with-node-affinity": {
|
||||
pvcs: []*v1.PersistentVolumeClaim{
|
||||
localPreboundPVC1a,
|
||||
localPreboundPVC1b,
|
||||
},
|
||||
pvs: []*v1.PersistentVolume{
|
||||
localPVNode1a,
|
||||
localPVNode1b,
|
||||
},
|
||||
nodes: []*v1.Node{
|
||||
node1,
|
||||
node2,
|
||||
},
|
||||
eligibleNodes: sets.New("node1"),
|
||||
},
|
||||
"multi-local-pv-with-different-nodes": {
|
||||
pvcs: []*v1.PersistentVolumeClaim{
|
||||
localPreboundPVC1a,
|
||||
localPreboundPVC1b,
|
||||
localPreboundPVC2a,
|
||||
},
|
||||
pvs: []*v1.PersistentVolume{
|
||||
localPVNode1a,
|
||||
localPVNode1b,
|
||||
localPVNode2a,
|
||||
},
|
||||
nodes: []*v1.Node{
|
||||
node1,
|
||||
node2,
|
||||
},
|
||||
eligibleNodes: sets.New[string](),
|
||||
},
|
||||
"local-and-non-local-pv": {
|
||||
pvcs: []*v1.PersistentVolumeClaim{
|
||||
localPreboundPVC1a,
|
||||
localPreboundPVC1b,
|
||||
preboundPVC,
|
||||
immediateBoundPVC,
|
||||
},
|
||||
pvs: []*v1.PersistentVolume{
|
||||
localPVNode1a,
|
||||
localPVNode1b,
|
||||
pvNode1a,
|
||||
pvBoundImmediate,
|
||||
pvBoundImmediateNode2,
|
||||
},
|
||||
nodes: []*v1.Node{
|
||||
node1,
|
||||
node2,
|
||||
},
|
||||
eligibleNodes: sets.New("node1"),
|
||||
},
|
||||
}
|
||||
|
||||
run := func(t *testing.T, scenario scenarioType) {
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
// Setup
|
||||
testEnv := newTestBinder(t, ctx)
|
||||
testEnv.initVolumes(scenario.pvs, scenario.pvs)
|
||||
|
||||
testEnv.initNodes(scenario.nodes)
|
||||
testEnv.initClaims(scenario.pvcs, scenario.pvcs)
|
||||
|
||||
// Execute
|
||||
eligibleNodes := testEnv.binder.GetEligibleNodes(logger, scenario.pvcs)
|
||||
|
||||
// Validate
|
||||
if reflect.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)
|
||||
})); compDiff != "" {
|
||||
t.Errorf("Unexpected eligible nodes (-want +got):\n%s", compDiff)
|
||||
}
|
||||
}
|
||||
|
||||
for name, scenario := range scenarios {
|
||||
t.Run(name, func(t *testing.T) { run(t, scenario) })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user