Relax csiNodeIDMaxLength to longer limit

Update csiNodeIDMaxLength to 192 bytes
This commit is contained in:
Jiawei Wang
2021-02-03 22:16:19 -08:00
parent 5b3333a262
commit 1e16615fb0
4 changed files with 83 additions and 23 deletions

View File

@@ -46,6 +46,12 @@ var (
},
},
}
longerIDValidateOption = CSINodeValidationOptions{
AllowLongNodeID: true,
}
shorterIDValidationOption = CSINodeValidationOptions{
AllowLongNodeID: false,
}
)
func TestValidateStorageClass(t *testing.T) {
@@ -1026,8 +1032,9 @@ func TestValidateAllowedTopologies(t *testing.T) {
func TestCSINodeValidation(t *testing.T) {
driverName := "driver-name"
driverName2 := "1io.kubernetes-storage-2-csi-driver3"
longName := "my-a-b-c-d-c-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-ABCDEFGHIJKLMNOPQRSTUVWXYZ-driver"
longName := "my-a-b-c-d-c-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-ABCDEFGHIJKLMNOPQRSTUVWXYZ-driver" // 88 chars
nodeID := "nodeA"
longID := longName + longName // 176 chars
successCases := []storage.CSINode{
{
// driver name: dot only
@@ -1217,10 +1224,29 @@ func TestCSINodeValidation(t *testing.T) {
}
for _, csiNode := range successCases {
if errs := ValidateCSINode(&csiNode); len(errs) != 0 {
if errs := ValidateCSINode(&csiNode, shorterIDValidationOption); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
}
nodeIDCase := storage.CSINode{
// node ID length > 128 but < 192
ObjectMeta: metav1.ObjectMeta{Name: "foo7"},
Spec: storage.CSINodeSpec{
Drivers: []storage.CSINodeDriver{
{
Name: driverName,
NodeID: longID,
TopologyKeys: []string{"company.com/zone1", "company.com/zone2"},
},
},
},
}
if errs := ValidateCSINode(&nodeIDCase, longerIDValidateOption); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
errorCases := []storage.CSINode{
{
// Empty driver name
@@ -1414,10 +1440,11 @@ func TestCSINodeValidation(t *testing.T) {
},
},
},
nodeIDCase,
}
for _, csiNode := range errorCases {
if errs := ValidateCSINode(&csiNode); len(errs) == 0 {
if errs := ValidateCSINode(&csiNode, shorterIDValidationOption); len(errs) == 0 {
t.Errorf("Expected failure for test: %v", csiNode)
}
}
@@ -1528,7 +1555,7 @@ func TestCSINodeUpdateValidation(t *testing.T) {
}
for _, csiNode := range successCases {
if errs := ValidateCSINodeUpdate(&csiNode, &old); len(errs) != 0 {
if errs := ValidateCSINodeUpdate(&csiNode, &old, shorterIDValidationOption); len(errs) != 0 {
t.Errorf("expected success: %+v", errs)
}
}
@@ -1651,7 +1678,7 @@ func TestCSINodeUpdateValidation(t *testing.T) {
}
for _, csiNode := range errorCases {
if errs := ValidateCSINodeUpdate(&csiNode, &old); len(errs) == 0 {
if errs := ValidateCSINodeUpdate(&csiNode, &old, shorterIDValidationOption); len(errs) == 0 {
t.Errorf("Expected failure for test: %+v", csiNode)
}
}