Skip to content

Commit f842879

Browse files
authored
Merge pull request #344 from gnufied/fix-host-path-expansion-options
Fix options for volume expansion
2 parents 1625193 + c7685ed commit f842879

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

cmd/hostpathplugin/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ func main() {
5555
flag.BoolVar(&cfg.CheckVolumeLifecycle, "check-volume-lifecycle", false, "Can be used to turn some violations of the volume lifecycle into warnings instead of failing the incorrect gRPC call. Disabled by default because of https://github.com/kubernetes/kubernetes/issues/101911.")
5656
flag.Int64Var(&cfg.MaxVolumeSize, "max-volume-size", 1024*1024*1024*1024, "maximum size of volumes in bytes (inclusive)")
5757
flag.BoolVar(&cfg.EnableTopology, "enable-topology", true, "Enables PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS capability.")
58-
flag.BoolVar(&cfg.EnableVolumeExpansion, "node-expand-required", true, "Enables NodeServiceCapability_RPC_EXPAND_VOLUME capacity.")
58+
flag.BoolVar(&cfg.EnableVolumeExpansion, "node-expand-required", true, "Enables volume expansion capability of the plugin(Deprecated). Please use enable-volume-expansion flag.")
59+
60+
flag.BoolVar(&cfg.EnableVolumeExpansion, "enable-volume-expansion", true, "Enables volume expansion feature.")
61+
flag.BoolVar(&cfg.DisableControllerExpansion, "disable-controller-expansion", false, "Disables Controller volume expansion capability.")
62+
flag.BoolVar(&cfg.DisableNodeExpansion, "disable-node-expansion", false, "Disables Node volume expansion capability.")
63+
flag.Int64Var(&cfg.MaxVolumeExpansionSizeNode, "max-volume-size-node", 0, "Maximum allowed size of volume when expanded on the node. Defaults to same size as max-volume-size.")
64+
5965
flag.Int64Var(&cfg.AttachLimit, "attach-limit", 0, "Maximum number of attachable volumes on a node. Zero refers to no limit.")
6066
showVersion := flag.Bool("version", false, "Show version.")
6167
// The proxy-endpoint option is intended to used by the Kubernetes E2E test suite
@@ -97,6 +103,10 @@ func main() {
97103
return
98104
}
99105

106+
if cfg.MaxVolumeExpansionSizeNode == 0 {
107+
cfg.MaxVolumeExpansionSizeNode = cfg.MaxVolumeSize
108+
}
109+
100110
driver, err := hostpath.NewHostPathDriver(cfg)
101111
if err != nil {
102112
fmt.Printf("Failed to initialize driver: %s", err.Error())

pkg/hostpath/controllerserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ func (hp *hostPath) getControllerServiceCapabilities() []*csi.ControllerServiceC
799799
csi.ControllerServiceCapability_RPC_VOLUME_CONDITION,
800800
csi.ControllerServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
801801
}
802-
if hp.config.EnableVolumeExpansion {
802+
if hp.config.EnableVolumeExpansion && !hp.config.DisableControllerExpansion {
803803
cl = append(cl, csi.ControllerServiceCapability_RPC_EXPAND_VOLUME)
804804
}
805805
if hp.config.EnableAttach {

pkg/hostpath/hostpath.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,25 @@ type hostPath struct {
5959
}
6060

6161
type Config struct {
62-
DriverName string
63-
Endpoint string
64-
ProxyEndpoint string
65-
NodeID string
66-
VendorVersion string
67-
StateDir string
68-
MaxVolumesPerNode int64
69-
MaxVolumeSize int64
70-
AttachLimit int64
71-
Capacity Capacity
72-
Ephemeral bool
73-
ShowVersion bool
74-
EnableAttach bool
75-
EnableTopology bool
76-
EnableVolumeExpansion bool
77-
CheckVolumeLifecycle bool
62+
DriverName string
63+
Endpoint string
64+
ProxyEndpoint string
65+
NodeID string
66+
VendorVersion string
67+
StateDir string
68+
MaxVolumesPerNode int64
69+
MaxVolumeSize int64
70+
AttachLimit int64
71+
Capacity Capacity
72+
Ephemeral bool
73+
ShowVersion bool
74+
EnableAttach bool
75+
EnableTopology bool
76+
EnableVolumeExpansion bool
77+
DisableControllerExpansion bool
78+
DisableNodeExpansion bool
79+
MaxVolumeExpansionSizeNode int64
80+
CheckVolumeLifecycle bool
7881
}
7982

8083
var (

pkg/hostpath/nodeserver.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func (hp *hostPath) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCap
390390
},
391391
},
392392
}
393-
if hp.config.EnableVolumeExpansion {
393+
if hp.config.EnableVolumeExpansion && !hp.config.DisableNodeExpansion {
394394
caps = append(caps, &csi.NodeServiceCapability{
395395
Type: &csi.NodeServiceCapability_Rpc{
396396
Rpc: &csi.NodeServiceCapability_RPC{
@@ -480,6 +480,15 @@ func (hp *hostPath) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVol
480480
return nil, status.Error(codes.InvalidArgument, "Volume path not provided")
481481
}
482482

483+
capRange := req.GetCapacityRange()
484+
if capRange == nil {
485+
return nil, status.Error(codes.InvalidArgument, "Capacity range not provided")
486+
}
487+
capacity := int64(capRange.GetRequiredBytes())
488+
if capacity > hp.config.MaxVolumeExpansionSizeNode {
489+
return nil, status.Errorf(codes.OutOfRange, "Requested capacity %d exceeds maximum allowed %d", capacity, hp.config.MaxVolumeExpansionSizeNode)
490+
}
491+
483492
info, err := os.Stat(volPath)
484493
if err != nil {
485494
return nil, status.Errorf(codes.InvalidArgument, "Could not get file information from %s: %v", volPath, err)

0 commit comments

Comments
 (0)