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

Volume size #253

Merged
merged 7 commits into from
Apr 15, 2021
Merged

Volume size #253

merged 7 commits into from
Apr 15, 2021

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Mar 8, 2021

What type of PR is this?
/kind feature

What this PR does / why we need it:

More complete storage capacity simulation.

Does this PR introduce a user-facing change?:

The hostpath driver now has a configurable fixed maximum volume size. It reports the minimum of that and the remaining capacity as `GetCapacityResponse.MaximumVolumeSize`. `GetCapacityResponse.MinimumVolumeSize` is always zero.

Fixes: #274

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Mar 8, 2021
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 8, 2021
@pohly pohly force-pushed the volume-size branch 2 times, most recently from 56397e3 to 13f8c54 Compare March 9, 2021 09:50
@pohly pohly changed the title Volume size WIP: Volume size Mar 10, 2021
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 10, 2021
@pohly pohly changed the title WIP: Volume size Volume size Mar 10, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 10, 2021
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 18, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 19, 2021
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 7, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 8, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pohly

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 8, 2021
@pohly
Copy link
Contributor Author

pohly commented Apr 8, 2021

@avalluri I took some of your commits from PR #269, added some fixes and rewrote the capacity tracking as I mentioned there.

Can you perhaps review this PR?

@pohly
Copy link
Contributor Author

pohly commented Apr 8, 2021

/test pull-kubernetes-csi-csi-driver-host-path-distributed-on-kubernetes-master

This job is relevant because that is where the driver gets deployed with capacity tracking. It's still experimental and therefore not enabled by default.

@pohly
Copy link
Contributor Author

pohly commented Apr 8, 2021

/test pull-kubernetes-csi-csi-driver-host-path-distributed-on-kubernetes-master

@avalluri
Copy link
Contributor

avalluri commented Apr 8, 2021

/lgtm

@k8s-ci-robot
Copy link
Contributor

@avalluri: changing LGTM is restricted to collaborators

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@avalluri
Copy link
Contributor

avalluri commented Apr 8, 2021

Can you perhaps review this PR?

Looks good to me.

@verult
Copy link
Contributor

verult commented Apr 8, 2021

/assign

Copy link
Contributor

@verult verult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise! Sorry for the delay

@@ -50,24 +50,27 @@ func (c Capacity) Set(arg string) error {
}

// We overwrite any previous value.
c[parts[0]] = quantity
if *c == nil {
*c = Capacity{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c is still set to hostpath.Capacity{} before flag declaration, so *c is never nil. Did you mean to remove that line?

This is a bit risky: if c is nil then *c == nil results in a panic. It's easy for others working on this code to make a mistake.

Pre-allocating memory for an empty map might be better comparing to opening up risks for panics? Although do you happen to know how much memory it eats up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-allocating memory for an empty map might be better comparing to opening up risks for panics?

That's what I did earlier in

c := hostpath.Capacity{}

Then someone else removed that line without realizing that it is needed, leading to a panic when setting the parameter. It would be nicer if a default-initialized Capacity (= nil map instead of map[string]resource.Quantity{}) just worked, which is what I am trying to achieve here.

if c is nil then *c == nil results in a panic. It's easy for others working on this code to make a mistake.

How can c be nil? Someone would have to explicitly declare a pointer to a Capacity and then call Set for that pointer. That is not something that I would expect to work unless explicitly documented for a type, so I think panicking in that case is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok thanks for the context! nit: add a comment for the rationale in case anyone in the future wonders why this is done.

How can c be nil? Someone would have to explicitly declare a pointer to a Capacity and then call Set for that pointer. That is not something that I would expect to work unless explicitly documented for a type, so I think panicking in that case is fine.
That's true, ack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Please review and LGTM.

// Set by the build process
version = ""
)

func main() {
var cfg hostpath.Config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor!

@@ -55,6 +55,7 @@ func main() {
// The proxy-endpoint option is intended to used by the Kubernetes E2E test suite
// for proxying incoming calls to the embedded mock CSI driver.
proxyEndpoint := flag.String("proxy-endpoint", "", "Instead of running the CSI driver code, just proxy connections from csiEndpoint to the given listening socket.")
flag.Int64Var(&cfg.MaxVolumeSize, "maxvolumesize", 1024*1024*1024*1024, "maximum size of volumes in bytes")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Keep cfg flags together

nit: name it "max-volume-size" to be consistent with word delineation in other flags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if hp.config.Capacity.Enabled() {
kind := req.GetParameters()[storageKind]
quantity := hp.config.Capacity.Check(kind)
available = quantity.Value()
}
maxVolumeSize := hp.config.MaxVolumeSize
if maxVolumeSize < available {
maxVolumeSize = available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding was the intention of MaxVolumeSize is that the underlying storage system may not be able to provision a volume as large as all available capacity (for example due to fragmentation). Should we allow for ability to emulate the case where maxVolumeSize < available then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean if maxVolumeSize > available? If so, consider logging available and the previous maxVolumeSize to let the user know maxVolumeSize got truncated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison is indeed backwards. I really wish Go had a min(a,b) template function 😢

Fixed. I did not add a log message for this though, because the result should be obvious also without it.

// Alloc reserves a certain amount of bytes. Errors are
// usable as result of gRPC calls. Empty kind means
// that any large enough one is fine.
func (c *Capacity) Alloc(kind string, size int64) (actualKind string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole commit is pretty great! Much simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should have done it like that from the start. Oh well.

@verult
Copy link
Contributor

verult commented Apr 15, 2021

/lgtm
/hold

Since this PR is blocking a few other ones, please feel free to cancel the hold and address the remaining comments in a separate PR if needed.

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Apr 15, 2021
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 15, 2021
@pohly
Copy link
Contributor Author

pohly commented Apr 15, 2021

@verult please take another look, I pushed the updated commits.

@pohly
Copy link
Contributor Author

pohly commented Apr 15, 2021

/test pull-kubernetes-csi-csi-driver-host-path-distributed-on-kubernetes-master

@verult
Copy link
Contributor

verult commented Apr 15, 2021

/lgtm

Keeping hold in case you want to address the nit

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 15, 2021
pohly and others added 7 commits April 15, 2021 20:22
The map had to be allocated in advance for Set(). By using a pointer
receiver the Set function itself can allocate the map if (and only if)
needed.
Introduced new Config structure to hold driver configuration, this way it is
convenient to pass them to NewHostPathDriver().
The new spec version makes it possible to report maximum volume size.
Maximum volume size is now configurable, with 1TiB as
default. Previously, that value was hard-coded. The
GetCapacityResponse always includes a value for MaximumVolumeSize
which is the minimum of that fixed size and available capacity.

MinimumVolumeSize is always set to zero, for the sake of completeness.
The previous approach of adapting remaining capacity while adding or
removing volumes was unnecessarily complex. When we accept that we
need to sum up allocated space repeatedly, the remaining code becomes
simpler.
The introduction of sed had input/output backwards.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 15, 2021
@pohly
Copy link
Contributor Author

pohly commented Apr 15, 2021

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 15, 2021
@verult
Copy link
Contributor

verult commented Apr 15, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 15, 2021
@k8s-ci-robot k8s-ci-robot merged commit 85a7174 into kubernetes-csi:master Apr 15, 2021
humblec added a commit to humblec/csi-driver-host-path that referenced this pull request May 24, 2024
4967685 Merge pull request kubernetes-csi#254 from bells17/add-github-actions
d9bd160 Update skip list in codespell GitHub Action
adb3af9 Merge pull request kubernetes-csi#252 from bells17/update-go-version
f5aebfc Add GitHub Actions workflows
b82ee38 Merge pull request kubernetes-csi#253 from bells17/fix-typo
c317456 Fix typo
0a78505 Bump to Go 1.22.3
edd89ad Merge pull request kubernetes-csi#251 from jsafrane/add-logcheck
043fd09 Add test-logcheck target
d7535ae Merge pull request kubernetes-csi#250 from jsafrane/go-1.22
b52e7ad Update go to 1.22.2
14fdb6f Merge pull request kubernetes-csi#247 from msau42/prow
9b4352e Update release playbook
c7bb972 Fix release notes script to use fixed tags
463a0e9 Add script to update specific go modules

git-subtree-dir: release-tools
git-subtree-split: 4967685
TerryHowe pushed a commit to TerryHowe/csi-driver-host-path that referenced this pull request Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

distributed-on-master failing
4 participants