mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #75481 from mucahitkurt/refactor/nodeinfomanager-tests
Add expectedCSINode for csiNodeEnabled test cases on nodeinfomanager tests
This commit is contained in:
commit
60638c71bd
@ -45,7 +45,6 @@ go_test(
|
|||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/apis/core/helper:go_default_library",
|
"//pkg/apis/core/helper:go_default_library",
|
||||||
"//pkg/apis/core/v1/helper:go_default_library",
|
|
||||||
"//pkg/features:go_default_library",
|
"//pkg/features:go_default_library",
|
||||||
"//pkg/volume/testing:go_default_library",
|
"//pkg/volume/testing:go_default_library",
|
||||||
"//pkg/volume/util:go_default_library",
|
"//pkg/volume/util:go_default_library",
|
||||||
@ -54,8 +53,8 @@ go_test(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
|
||||||
|
@ -19,6 +19,7 @@ package nodeinfomanager
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -29,7 +30,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
|
||||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing"
|
utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing"
|
||||||
@ -37,7 +37,6 @@ import (
|
|||||||
clienttesting "k8s.io/client-go/testing"
|
clienttesting "k8s.io/client-go/testing"
|
||||||
utiltesting "k8s.io/client-go/util/testing"
|
utiltesting "k8s.io/client-go/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/apis/core/helper"
|
"k8s.io/kubernetes/pkg/apis/core/helper"
|
||||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
volumetest "k8s.io/kubernetes/pkg/volume/testing"
|
volumetest "k8s.io/kubernetes/pkg/volume/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume/util"
|
"k8s.io/kubernetes/pkg/volume/util"
|
||||||
@ -51,10 +50,8 @@ type testcase struct {
|
|||||||
inputNodeID string
|
inputNodeID string
|
||||||
inputTopology map[string]string
|
inputTopology map[string]string
|
||||||
inputVolumeLimit int64
|
inputVolumeLimit int64
|
||||||
expectedNodeIDMap map[string]string
|
expectedNode *v1.Node
|
||||||
expectedTopologyMap map[string]sets.String
|
expectedCSINode *storage.CSINode
|
||||||
expectedLabels map[string]string
|
|
||||||
expectedVolumeLimit int64
|
|
||||||
expectFail bool
|
expectFail bool
|
||||||
hasModified bool
|
hasModified bool
|
||||||
}
|
}
|
||||||
@ -75,13 +72,25 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
inputTopology: map[string]string{
|
inputTopology: map[string]string{
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
},
|
},
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
Labels: labelMap{"com.example.csi/zone": "zoneA"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: []string{"com.example.csi/zone"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
|
||||||
"com.example.csi.driver1": sets.NewString("com.example.csi/zone"),
|
|
||||||
},
|
},
|
||||||
expectedLabels: map[string]string{"com.example.csi/zone": "zoneA"},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pre-existing node info from the same driver",
|
name: "pre-existing node info from the same driver",
|
||||||
@ -106,14 +115,24 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
inputTopology: map[string]string{
|
inputTopology: map[string]string{
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
},
|
},
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
Labels: labelMap{"com.example.csi/zone": "zoneA"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: []string{"com.example.csi/zone"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
|
||||||
"com.example.csi.driver1": sets.NewString("com.example.csi/zone"),
|
|
||||||
},
|
},
|
||||||
expectedLabels: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -134,14 +153,24 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
inputTopology: map[string]string{
|
inputTopology: map[string]string{
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
},
|
},
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
Labels: labelMap{"com.example.csi/zone": "zoneA"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: []string{"com.example.csi/zone"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
|
||||||
"com.example.csi.driver1": sets.NewString("com.example.csi/zone"),
|
|
||||||
},
|
},
|
||||||
expectedLabels: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -166,19 +195,37 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
inputTopology: map[string]string{
|
inputTopology: map[string]string{
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
},
|
},
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
||||||
"net.example.storage.other-driver": "net.example.storage/test-node",
|
"net.example.storage.other-driver": "net.example.storage/test-node",
|
||||||
},
|
})},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
Labels: labelMap{
|
||||||
"com.example.csi.driver1": sets.NewString("com.example.csi/zone"),
|
|
||||||
"net.example.storage.other-driver": sets.NewString("net.example.storage/rack"),
|
|
||||||
},
|
|
||||||
expectedLabels: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
"net.example.storage/rack": "rack1",
|
"net.example.storage/rack": "rack1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "net.example.storage.other-driver",
|
||||||
|
NodeID: "net.example.storage/test-node",
|
||||||
|
TopologyKeys: []string{"net.example.storage/rack"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: []string{"com.example.csi/zone"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "pre-existing node info from the same driver, but different node ID and topology values; labels should conflict",
|
name: "pre-existing node info from the same driver, but different node ID and topology values; labels should conflict",
|
||||||
driverName: "com.example.csi.driver1",
|
driverName: "com.example.csi.driver1",
|
||||||
@ -225,30 +272,53 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
inputTopology: map[string]string{
|
inputTopology: map[string]string{
|
||||||
"com.example.csi/rack": "rack1",
|
"com.example.csi/rack": "rack1",
|
||||||
},
|
},
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"com.example.csi.driver1": "com.example.csi/other-node",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
},
|
Name: "node1",
|
||||||
expectedTopologyMap: map[string]sets.String{
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/other-node"})},
|
||||||
"com.example.csi.driver1": sets.NewString("com.example.csi/rack"),
|
Labels: labelMap{
|
||||||
},
|
|
||||||
expectedLabels: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA",
|
"com.example.csi/zone": "zoneA",
|
||||||
"com.example.csi/rack": "rack1",
|
"com.example.csi/rack": "rack1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/other-node",
|
||||||
|
TopologyKeys: []string{"com.example.csi/rack"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "nil topology, empty node",
|
name: "nil topology, empty node",
|
||||||
driverName: "com.example.csi.driver1",
|
driverName: "com.example.csi.driver1",
|
||||||
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
inputTopology: nil,
|
inputTopology: nil,
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
|
||||||
"com.example.csi.driver1": nil,
|
|
||||||
},
|
},
|
||||||
expectedLabels: nil,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nil topology, pre-existing node info from the same driver",
|
name: "nil topology, pre-existing node info from the same driver",
|
||||||
@ -270,14 +340,26 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
),
|
),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
inputTopology: nil,
|
inputTopology: nil,
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
Labels: labelMap{
|
||||||
|
"com.example.csi/zone": "zoneA",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: nil,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
|
||||||
"com.example.csi.driver1": nil,
|
|
||||||
},
|
},
|
||||||
expectedLabels: map[string]string{
|
|
||||||
"com.example.csi/zone": "zoneA", // old labels are not removed
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -300,18 +382,36 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
),
|
),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
inputTopology: nil,
|
inputTopology: nil,
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
||||||
"net.example.storage.other-driver": "net.example.storage/test-node",
|
"net.example.storage.other-driver": "net.example.storage/test-node",
|
||||||
},
|
})},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
Labels: labelMap{
|
||||||
"net.example.storage.other-driver": sets.NewString("net.example.storage/rack"),
|
|
||||||
"com.example.csi.driver1": nil,
|
|
||||||
},
|
|
||||||
expectedLabels: map[string]string{
|
|
||||||
"net.example.storage/rack": "rack1",
|
"net.example.storage/rack": "rack1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "net.example.storage.other-driver",
|
||||||
|
NodeID: "net.example.storage/test-node",
|
||||||
|
TopologyKeys: []string{"net.example.storage/rack"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "empty node ID",
|
name: "empty node ID",
|
||||||
driverName: "com.example.csi.driver1",
|
driverName: "com.example.csi.driver1",
|
||||||
@ -326,14 +426,32 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
inputVolumeLimit: 10,
|
inputVolumeLimit: 10,
|
||||||
inputTopology: nil,
|
inputTopology: nil,
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
expectedVolumeLimit: 10,
|
expectedNode: &v1.Node{
|
||||||
expectedNodeIDMap: map[string]string{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
},
|
||||||
|
Status: v1.NodeStatus{
|
||||||
|
Capacity: v1.ResourceList{
|
||||||
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi.driver1")): *resource.NewQuantity(10, resource.DecimalSI),
|
||||||
|
},
|
||||||
|
Allocatable: v1.ResourceList{
|
||||||
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi.driver1")): *resource.NewQuantity(10, resource.DecimalSI),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
|
||||||
"com.example.csi.driver1": nil,
|
|
||||||
},
|
},
|
||||||
expectedLabels: nil,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "node with existing valid max limit",
|
name: "node with existing valid max limit",
|
||||||
@ -348,14 +466,36 @@ func TestInstallCSIDriver(t *testing.T) {
|
|||||||
inputVolumeLimit: 20,
|
inputVolumeLimit: 20,
|
||||||
inputTopology: nil,
|
inputTopology: nil,
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
expectedVolumeLimit: 20,
|
expectedNode: &v1.Node{
|
||||||
expectedNodeIDMap: map[string]string{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
},
|
||||||
|
Status: v1.NodeStatus{
|
||||||
|
Capacity: v1.ResourceList{
|
||||||
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi.driver1")): *resource.NewQuantity(20, resource.DecimalSI),
|
||||||
|
v1.ResourceCPU: *resource.NewScaledQuantity(4, -3),
|
||||||
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi/driver1")): *resource.NewQuantity(10, resource.DecimalSI),
|
||||||
|
},
|
||||||
|
Allocatable: v1.ResourceList{
|
||||||
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi.driver1")): *resource.NewQuantity(20, resource.DecimalSI),
|
||||||
|
v1.ResourceCPU: *resource.NewScaledQuantity(4, -3),
|
||||||
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi/driver1")): *resource.NewQuantity(10, resource.DecimalSI),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "com.example.csi.driver1",
|
||||||
|
NodeID: "com.example.csi/csi-node1",
|
||||||
|
TopologyKeys: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
|
||||||
"com.example.csi.driver1": nil,
|
|
||||||
},
|
},
|
||||||
expectedLabels: nil,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,8 +511,11 @@ func TestInstallCSIDriverCSINodeInfoDisabled(t *testing.T) {
|
|||||||
driverName: "com.example.csi.driver1",
|
driverName: "com.example.csi.driver1",
|
||||||
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -384,8 +527,11 @@ func TestInstallCSIDriverCSINodeInfoDisabled(t *testing.T) {
|
|||||||
},
|
},
|
||||||
nil /* labels */, nil /*capacity*/),
|
nil /* labels */, nil /*capacity*/),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"com.example.csi.driver1": "com.example.csi/csi-node1"})},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -397,9 +543,14 @@ func TestInstallCSIDriverCSINodeInfoDisabled(t *testing.T) {
|
|||||||
},
|
},
|
||||||
nil /* labels */, nil /*capacity*/),
|
nil /* labels */, nil /*capacity*/),
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{
|
||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
||||||
"net.example.storage.other-driver": "net.example.storage/test-node",
|
"net.example.storage.other-driver": "net.example.storage/test-node",
|
||||||
|
})},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -414,8 +565,15 @@ func TestUninstallCSIDriver(t *testing.T) {
|
|||||||
name: "empty node and empty CSINode",
|
name: "empty node and empty CSINode",
|
||||||
driverName: "com.example.csi.driver1",
|
driverName: "com.example.csi.driver1",
|
||||||
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
||||||
expectedNodeIDMap: nil,
|
expectedNode: &v1.Node{
|
||||||
expectedLabels: nil,
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pre-existing node info from the same driver",
|
name: "pre-existing node info from the same driver",
|
||||||
@ -435,8 +593,16 @@ func TestUninstallCSIDriver(t *testing.T) {
|
|||||||
"com.example.csi.driver1": {"com.example.csi/zone"},
|
"com.example.csi.driver1": {"com.example.csi/zone"},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
expectedNodeIDMap: nil,
|
expectedNode: &v1.Node{
|
||||||
expectedLabels: map[string]string{"com.example.csi/zone": "zoneA"},
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Labels: labelMap{"com.example.csi/zone": "zoneA"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{},
|
||||||
|
},
|
||||||
hasModified: true,
|
hasModified: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -457,13 +623,25 @@ func TestUninstallCSIDriver(t *testing.T) {
|
|||||||
"net.example.storage.other-driver": {"net.example.storage/zone"},
|
"net.example.storage.other-driver": {"net.example.storage/zone"},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"net.example.storage.other-driver": "net.example.storage/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"net.example.storage.other-driver": "net.example.storage/csi-node1"})},
|
||||||
|
Labels: labelMap{"net.example.storage/zone": "zoneA"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{
|
||||||
|
Drivers: []storage.CSINodeDriver{
|
||||||
|
{
|
||||||
|
Name: "net.example.storage.other-driver",
|
||||||
|
NodeID: "net.example.storage/csi-node1",
|
||||||
|
TopologyKeys: []string{"net.example.storage/zone"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedTopologyMap: map[string]sets.String{
|
|
||||||
"net.example.storage.other-driver": sets.NewString("net.example.storage/zone"),
|
|
||||||
},
|
},
|
||||||
expectedLabels: map[string]string{"net.example.storage/zone": "zoneA"},
|
|
||||||
hasModified: false,
|
hasModified: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -474,8 +652,15 @@ func TestUninstallCSIDriver(t *testing.T) {
|
|||||||
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
"com.example.csi.driver1": "com.example.csi/csi-node1",
|
||||||
},
|
},
|
||||||
nil /* labels */, nil /*capacity*/),
|
nil /* labels */, nil /*capacity*/),
|
||||||
expectedNodeIDMap: nil,
|
expectedNode: &v1.Node{
|
||||||
expectedLabels: nil,
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pre-existing info about a different driver in node, but empty CSINode",
|
name: "pre-existing info about a different driver in node, but empty CSINode",
|
||||||
@ -484,10 +669,16 @@ func TestUninstallCSIDriver(t *testing.T) {
|
|||||||
"net.example.storage.other-driver": "net.example.storage/csi-node1",
|
"net.example.storage.other-driver": "net.example.storage/csi-node1",
|
||||||
},
|
},
|
||||||
nil /* labels */, nil /*capacity*/),
|
nil /* labels */, nil /*capacity*/),
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"net.example.storage.other-driver": "net.example.storage/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"net.example.storage.other-driver": "net.example.storage/csi-node1"})},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{},
|
||||||
},
|
},
|
||||||
expectedLabels: nil,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "new node with valid max limit",
|
name: "new node with valid max limit",
|
||||||
@ -500,9 +691,27 @@ func TestUninstallCSIDriver(t *testing.T) {
|
|||||||
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi/driver1")): *resource.NewQuantity(10, resource.DecimalSI),
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi/driver1")): *resource.NewQuantity(10, resource.DecimalSI),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
expectedNode: &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
},
|
||||||
|
Status: v1.NodeStatus{
|
||||||
|
Capacity: v1.ResourceList{
|
||||||
|
v1.ResourceCPU: *resource.NewScaledQuantity(4, -3),
|
||||||
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi/driver1")): *resource.NewQuantity(10, resource.DecimalSI),
|
||||||
|
},
|
||||||
|
Allocatable: v1.ResourceList{
|
||||||
|
v1.ResourceCPU: *resource.NewScaledQuantity(4, -3),
|
||||||
|
v1.ResourceName(util.GetCSIAttachLimitKey("com.example.csi/driver1")): *resource.NewQuantity(10, resource.DecimalSI),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCSINode: &storage.CSINode{
|
||||||
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
|
Spec: storage.CSINodeSpec{},
|
||||||
|
},
|
||||||
inputTopology: nil,
|
inputTopology: nil,
|
||||||
inputNodeID: "com.example.csi/csi-node1",
|
inputNodeID: "com.example.csi/csi-node1",
|
||||||
expectedVolumeLimit: 0,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,7 +726,11 @@ func TestUninstallCSIDriverCSINodeInfoDisabled(t *testing.T) {
|
|||||||
name: "empty node",
|
name: "empty node",
|
||||||
driverName: "com.example.csi/driver1",
|
driverName: "com.example.csi/driver1",
|
||||||
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
existingNode: generateNode(nil /* nodeIDs */, nil /* labels */, nil /*capacity*/),
|
||||||
expectedNodeIDMap: nil,
|
expectedNode: &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pre-existing node info from the same driver",
|
name: "pre-existing node info from the same driver",
|
||||||
@ -527,7 +740,11 @@ func TestUninstallCSIDriverCSINodeInfoDisabled(t *testing.T) {
|
|||||||
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
"com.example.csi/driver1": "com.example.csi/csi-node1",
|
||||||
},
|
},
|
||||||
nil /* labels */, nil /*capacity*/),
|
nil /* labels */, nil /*capacity*/),
|
||||||
expectedNodeIDMap: nil,
|
expectedNode: &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pre-existing node info from different driver",
|
name: "pre-existing node info from different driver",
|
||||||
@ -537,8 +754,11 @@ func TestUninstallCSIDriverCSINodeInfoDisabled(t *testing.T) {
|
|||||||
"net.example.storage/other-driver": "net.example.storage/csi-node1",
|
"net.example.storage/other-driver": "net.example.storage/csi-node1",
|
||||||
},
|
},
|
||||||
nil /* labels */, nil /*capacity*/),
|
nil /* labels */, nil /*capacity*/),
|
||||||
expectedNodeIDMap: map[string]string{
|
expectedNode: &v1.Node{
|
||||||
"net.example.storage/other-driver": "net.example.storage/csi-node1",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
Annotations: map[string]string{annotationKeyNodeID: marshall(nodeIDMap{"net.example.storage/other-driver": "net.example.storage/csi-node1"})},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -770,6 +990,17 @@ func TestInstallCSIDriverExistingAnnotation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getClientSet(existingNode *v1.Node, existingCSINode *storage.CSINode) *fake.Clientset {
|
||||||
|
objects := []runtime.Object{}
|
||||||
|
if existingNode != nil {
|
||||||
|
objects = append(objects, existingNode)
|
||||||
|
}
|
||||||
|
if existingCSINode != nil {
|
||||||
|
objects = append(objects, existingCSINode)
|
||||||
|
}
|
||||||
|
return fake.NewSimpleClientset(objects...)
|
||||||
|
}
|
||||||
|
|
||||||
func test(t *testing.T, addNodeInfo bool, csiNodeInfoEnabled bool, testcases []testcase) {
|
func test(t *testing.T, addNodeInfo bool, csiNodeInfoEnabled bool, testcases []testcase) {
|
||||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSINodeInfo, csiNodeInfoEnabled)()
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSINodeInfo, csiNodeInfoEnabled)()
|
||||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.AttachVolumeLimit, true)()
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.AttachVolumeLimit, true)()
|
||||||
@ -779,16 +1010,7 @@ func test(t *testing.T, addNodeInfo bool, csiNodeInfoEnabled bool, testcases []t
|
|||||||
|
|
||||||
//// Arrange
|
//// Arrange
|
||||||
nodeName := tc.existingNode.Name
|
nodeName := tc.existingNode.Name
|
||||||
var client *fake.Clientset
|
client := getClientSet(tc.existingNode, tc.existingCSINode)
|
||||||
if tc.existingCSINode != nil && tc.existingNode != nil {
|
|
||||||
client = fake.NewSimpleClientset(tc.existingNode, tc.existingCSINode)
|
|
||||||
} else if tc.existingCSINode != nil && tc.existingNode == nil {
|
|
||||||
client = fake.NewSimpleClientset(tc.existingCSINode)
|
|
||||||
} else if tc.existingCSINode == nil && tc.existingNode != nil {
|
|
||||||
client = fake.NewSimpleClientset(tc.existingNode)
|
|
||||||
} else {
|
|
||||||
client = fake.NewSimpleClientset()
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpDir, err := utiltesting.MkTmpdir("nodeinfomanager-test")
|
tmpDir, err := utiltesting.MkTmpdir("nodeinfomanager-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -837,44 +1059,11 @@ func test(t *testing.T, addNodeInfo bool, csiNodeInfoEnabled bool, testcases []t
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are testing max volume limits
|
if !helper.Semantic.DeepEqual(node, tc.expectedNode) {
|
||||||
attachLimit := getVolumeLimit(node, tc.driverName)
|
t.Errorf("expected Node %v; got: %v", tc.expectedNode, node)
|
||||||
if attachLimit != tc.expectedVolumeLimit {
|
|
||||||
t.Errorf("expected volume limit to be %d got %d", tc.expectedVolumeLimit, attachLimit)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node ID annotation
|
|
||||||
foundInNode := false
|
|
||||||
annNodeID, ok := node.Annotations[annotationKeyNodeID]
|
|
||||||
if ok {
|
|
||||||
if tc.expectedNodeIDMap == nil {
|
|
||||||
t.Errorf("expected annotation %q to not exist, but got: %q", annotationKeyNodeID, annNodeID)
|
|
||||||
} else {
|
|
||||||
var actualNodeIDs map[string]string
|
|
||||||
err = json.Unmarshal([]byte(annNodeID), &actualNodeIDs)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("expected no error when parsing annotation %q, but got error: %v", annotationKeyNodeID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !helper.Semantic.DeepEqual(actualNodeIDs, tc.expectedNodeIDMap) {
|
|
||||||
t.Errorf("expected annotation %v; got: %v", tc.expectedNodeIDMap, actualNodeIDs)
|
|
||||||
} else {
|
|
||||||
foundInNode = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if tc.expectedNodeIDMap != nil {
|
|
||||||
t.Errorf("expected annotation %q, but got none", annotationKeyNodeID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if csiNodeInfoEnabled {
|
if csiNodeInfoEnabled {
|
||||||
// Topology labels
|
|
||||||
if !helper.Semantic.DeepEqual(node.Labels, tc.expectedLabels) {
|
|
||||||
t.Errorf("expected topology labels to be %v; got: %v", tc.expectedLabels, node.Labels)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CSINode validation
|
// CSINode validation
|
||||||
nodeInfo, err := client.StorageV1beta1().CSINodes().Get(nodeName, metav1.GetOptions{})
|
nodeInfo, err := client.StorageV1beta1().CSINodes().Get(nodeName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -883,27 +1072,8 @@ func test(t *testing.T, addNodeInfo bool, csiNodeInfoEnabled bool, testcases []t
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !helper.Semantic.DeepEqual(nodeInfo, tc.expectedCSINode) {
|
||||||
// Extract node IDs and topology keys
|
t.Errorf("expected CSINode %v; got: %v", tc.expectedCSINode, nodeInfo)
|
||||||
|
|
||||||
actualNodeIDs := make(map[string]string)
|
|
||||||
actualTopologyKeys := make(map[string]sets.String)
|
|
||||||
for _, driver := range nodeInfo.Spec.Drivers {
|
|
||||||
actualNodeIDs[driver.Name] = driver.NodeID
|
|
||||||
actualTopologyKeys[driver.Name] = sets.NewString(driver.TopologyKeys...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node IDs
|
|
||||||
// No need to check if Node ID found in Node if it was present in the NodeID
|
|
||||||
if !foundInNode {
|
|
||||||
if !helper.Semantic.DeepEqual(actualNodeIDs, tc.expectedNodeIDMap) {
|
|
||||||
t.Errorf("expected node IDs %v from CSINode; got: %v", tc.expectedNodeIDMap, actualNodeIDs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Topology keys
|
|
||||||
if !helper.Semantic.DeepEqual(actualTopologyKeys, tc.expectedTopologyMap) {
|
|
||||||
t.Errorf("expected topology keys %v from CSINode; got: %v", tc.expectedTopologyMap, actualTopologyKeys)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !addNodeInfo && tc.existingCSINode != nil && tc.existingNode != nil {
|
if !addNodeInfo && tc.existingCSINode != nil && tc.existingNode != nil {
|
||||||
@ -918,19 +1088,6 @@ func test(t *testing.T, addNodeInfo bool, csiNodeInfoEnabled bool, testcases []t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVolumeLimit(node *v1.Node, driverName string) int64 {
|
|
||||||
volumeLimits := map[v1.ResourceName]int64{}
|
|
||||||
nodeAllocatables := node.Status.Allocatable
|
|
||||||
for k, v := range nodeAllocatables {
|
|
||||||
if v1helper.IsAttachableVolumeResourceName(k) {
|
|
||||||
volumeLimits[k] = v.Value()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attachKey := v1.ResourceName(util.GetCSIAttachLimitKey(driverName))
|
|
||||||
attachLimit := volumeLimits[attachKey]
|
|
||||||
return attachLimit
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateNode(nodeIDs, labels map[string]string, capacity map[v1.ResourceName]resource.Quantity) *v1.Node {
|
func generateNode(nodeIDs, labels map[string]string, capacity map[v1.ResourceName]resource.Quantity) *v1.Node {
|
||||||
var annotations map[string]string
|
var annotations map[string]string
|
||||||
if len(nodeIDs) > 0 {
|
if len(nodeIDs) > 0 {
|
||||||
@ -952,7 +1109,12 @@ func generateNode(nodeIDs, labels map[string]string, capacity map[v1.ResourceNam
|
|||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateCSINode(nodeIDs map[string]string, topologyKeys map[string][]string) *storage.CSINode {
|
func marshall(nodeIDs nodeIDMap) string {
|
||||||
|
b, _ := json.Marshal(nodeIDs)
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateCSINode(nodeIDs nodeIDMap, topologyKeys topologyKeyMap) *storage.CSINode {
|
||||||
nodeDrivers := []storage.CSINodeDriver{}
|
nodeDrivers := []storage.CSINodeDriver{}
|
||||||
for k, nodeID := range nodeIDs {
|
for k, nodeID := range nodeIDs {
|
||||||
dspec := storage.CSINodeDriver{
|
dspec := storage.CSINodeDriver{
|
||||||
@ -964,16 +1126,28 @@ func generateCSINode(nodeIDs map[string]string, topologyKeys map[string][]string
|
|||||||
}
|
}
|
||||||
nodeDrivers = append(nodeDrivers, dspec)
|
nodeDrivers = append(nodeDrivers, dspec)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &storage.CSINode{
|
return &storage.CSINode{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: getCSINodeObjectMeta(),
|
||||||
Name: "node1",
|
|
||||||
},
|
|
||||||
Spec: storage.CSINodeSpec{
|
Spec: storage.CSINodeSpec{
|
||||||
Drivers: nodeDrivers,
|
Drivers: nodeDrivers,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCSINodeObjectMeta() metav1.ObjectMeta {
|
||||||
|
return metav1.ObjectMeta{
|
||||||
|
Name: "node1",
|
||||||
|
OwnerReferences: []metav1.OwnerReference{
|
||||||
|
{
|
||||||
|
APIVersion: nodeKind.Version,
|
||||||
|
Kind: nodeKind.Kind,
|
||||||
|
Name: "node1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func applyNodeStatusPatch(originalNode *v1.Node, patch []byte) (*v1.Node, error) {
|
func applyNodeStatusPatch(originalNode *v1.Node, patch []byte) (*v1.Node, error) {
|
||||||
original, err := json.Marshal(originalNode)
|
original, err := json.Marshal(originalNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user