-
Notifications
You must be signed in to change notification settings - Fork 214
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
Volume size #253
Conversation
56397e3
to
13f8c54
Compare
[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 |
/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. |
/test pull-kubernetes-csi-csi-driver-host-path-distributed-on-kubernetes-master |
/lgtm |
@avalluri: changing LGTM is restricted to collaborators In response to this:
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. |
Looks good to me. |
/assign |
There was a problem hiding this 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{} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
cmd/hostpathplugin/main.go
Outdated
// Set by the build process | ||
version = "" | ||
) | ||
|
||
func main() { | ||
var cfg hostpath.Config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor!
cmd/hostpathplugin/main.go
Outdated
@@ -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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/hostpath/capacity.go
Outdated
// 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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
/lgtm 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. |
@verult please take another look, I pushed the updated commits. |
/test pull-kubernetes-csi-csi-driver-host-path-distributed-on-kubernetes-master |
/lgtm Keeping hold in case you want to address the nit |
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().
Less code this way...
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.
/hold cancel |
/lgtm |
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
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?:
Fixes: #274