Fix installDriverToCSINode(): we should not skip CSINode update if Allocatable.Count changed

This commit is contained in:
Maxim Patlasov 2022-12-15 19:26:10 -08:00
parent 3f6738b8e6
commit fcf89f66a9
2 changed files with 12 additions and 2 deletions

View File

@ -505,6 +505,15 @@ func setMigrationAnnotation(migratedPlugins map[string](func() bool), nodeInfo *
return true
}
// Returns true if and only if new maxAttachLimit doesn't require CSINode update
func keepAllocatableCount(driverInfoSpec storagev1.CSINodeDriver, maxAttachLimit int64) bool {
if maxAttachLimit == 0 {
return driverInfoSpec.Allocatable == nil || driverInfoSpec.Allocatable.Count == nil
}
return driverInfoSpec.Allocatable != nil && driverInfoSpec.Allocatable.Count != nil && int64(*driverInfoSpec.Allocatable.Count) == maxAttachLimit
}
func (nim *nodeInfoManager) installDriverToCSINode(
nodeInfo *storagev1.CSINode,
driverName string,
@ -528,7 +537,8 @@ func (nim *nodeInfoManager) installDriverToCSINode(
for _, driverInfoSpec := range nodeInfo.Spec.Drivers {
if driverInfoSpec.Name == driverName {
if driverInfoSpec.NodeID == driverNodeID &&
sets.NewString(driverInfoSpec.TopologyKeys...).Equal(topologyKeys) {
sets.NewString(driverInfoSpec.TopologyKeys...).Equal(topologyKeys) &&
keepAllocatableCount(driverInfoSpec, maxAttachLimit) {
specModified = false
}
} else {

View File

@ -593,7 +593,7 @@ func TestInstallCSIDriver(t *testing.T) {
Name: "com.example.csi.driver1",
NodeID: "com.example.csi/csi-node1",
TopologyKeys: nil,
Allocatable: generateVolumeLimits(10),
Allocatable: generateVolumeLimits(20),
},
},
},