Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (localpv): CSIStorageClass shows zero if SC "poolname" includes dataset path #393

Merged
merged 3 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/unreleased/392-zero-cap-nonroot-ds
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes GetCapacity in pkg/driver/controller.go to report the ZFS pool
capacity even when using a child dataset at the storage class' poolname
attribute.
27 changes: 26 additions & 1 deletion pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,34 @@ func (cs *controller) GetCapacity(
}

zfsNodesCache := cs.zfsNodeInformer.GetIndexer()

params := req.GetParameters()

poolParam := helpers.GetInsensitiveParameter(&params, "poolname")

// The "poolname" parameter can either be the name of a ZFS pool
// (e.g. "zpool"), or a path to a child dataset (e.g. "zpool/k8s/localpv").
//
// We parse the "poolname" parameter so the name of the ZFS pool and the
// path to the dataset is available separately.
//
// The dataset path is not used now. It could be used later to query the
// capacity of the child dataset, which could be smaller than the capacity
// of the whole pool.
//
// This is necessary because capacity calculation currently only works with
// ZFS pool names. This is why it always returns the capacitry of the whole
// pool, even if the child dataset given as the "poolname" parameter has a
// smaller capacity than the whole pool.
poolname, _ := func() (string, string) {
poolParamSliced := strings.SplitN(poolParam, "/", 2)
if len(poolParamSliced) == 2 {
return poolParamSliced[0], poolParamSliced[1]
} else {
return poolParamSliced[0], ""
}
}()

var availableCapacity int64
for _, nodeName := range nodeNames {
v, exists, err := zfsNodesCache.GetByKey(zfs.OpenEBSNamespace + "/" + nodeName)
Expand All @@ -892,7 +917,7 @@ func (cs *controller) GetCapacity(
// See https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/1472-storage-capacity-tracking#available-capacity-vs-maximum-volume-size &
// https://github.com/container-storage-interface/spec/issues/432 for more details
for _, zpool := range zfsNode.Pools {
if zpool.Name != poolParam {
if zpool.Name != poolname {
continue
}
freeCapacity := zpool.Free.Value()
Expand Down