Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

[local-volume] Refactored GetFsAvailableByte to avoid using Frsize in local-volume provisioner #226

Merged
merged 2 commits into from
Jul 24, 2017

Conversation

ianchakeres
Copy link
Contributor

@ianchakeres ianchakeres commented Jul 10, 2017

GetFsAvailableByte now uses the same method as kubernetes/pkg/volume/util/fs.go:FsInfo(path) to calculate available bytes

Fixes: #224
Related to this discussion: #132

After this PR is merged, mac osx (darwin) uses can successfully execute make test on the local-volume provisioner.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 10, 2017
@ianchakeres
Copy link
Contributor Author

@msau42 @ddysher - PTAL.

@ianchakeres ianchakeres changed the title Refactored GetFsAvailableByte to avoid using Frsize in local-volume provisioner [local-volume] Refactored GetFsAvailableByte to avoid using Frsize in local-volume provisioner Jul 10, 2017
func (u *volumeUtil) GetFsAvailableByte(fullPath string) (uint64, error) {
var s unix.Statfs_t
if err := unix.Statfs(fullPath, &s); err != nil {
//largely copied from kubernetes/pkg/volume/util/fs.go:FsInfo(path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we get vendoring/import issues if we call it directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 can we reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had some vendoring issues related to log_dir being defined twice, by glog being imported twice.

For example,
panic: /var/folders/59/yc7_f4fd53nbyw868zqpk78cn7shx9/T/go-build393895106/github.com/kubernetes-incubator/external-storage/local-volume/provisioner/pkg/discovery/_test/discovery.test flag redefined: log_dir

I was able to resolve it by locally executing
glide install --strip-vendor --strip-vcs

by following the instructions here on stack overflow.

I haven't dealt with vendoring before.

Do you know where I'd add the appropriate flags to glide to ensure that dependencies are flattened?

Copy link
Contributor

Choose a reason for hiding this comment

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

@wongma7 can you help Ian import this K8s library

Copy link
Contributor

Choose a reason for hiding this comment

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

we most likely can't (yet) because it imports "k8s.io/kubernetes/pkg/api."

but yes --strip-vendor/-v is the correct flag needed to remove nested dependencies & to flatten everything

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain the limitation?

Copy link
Contributor

Choose a reason for hiding this comment

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

There will only be issues if we use functions from kubernetes/kubernetes/pkg/volume/util/ that accept or return kubernetes/kubernetes/pkg/api types, because we want to work with downstream k8s.io/api types instead.

It seems Fsinfo doesn't have this issue, so we won't run into any compilation errors when vendoring kubernetes/kubernetes/pkg/volume/util/ & using it. But generally we want to solve this issue for long-term so we can make use of existing code #165

Copy link
Contributor

Choose a reason for hiding this comment

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

So here's the steps i would do:

import kubernetes/pkg/volume/util
call util.Fsinfo where GetFsAvailableByte was called before
run glide up -v
run glide-vc --use-lock-file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wongma7 - thanks for the advice. I was able to execute the commands.

PTAL and let me know if the additional files in this commit look good.

@ianchakeres
Copy link
Contributor Author

@msau42 @ddysher @wongma7 - After executing glide commands, I was able to use FsInfo directly. PTAL

If we agree this code looks good, I'll refactor the further (by calling FsInfo directly inside discover.go, currently stashed) and squash some of the commits.

@msau42
Copy link
Contributor

msau42 commented Jul 13, 2017

This is a lot of files to pull into vendor... Should we try moving FsInfo to a higher level package so we can pull in from client-go instead?

@wongma7
Copy link
Contributor

wongma7 commented Jul 13, 2017

What I got is it won't be accepted if we try to put the code into client-go when the code will need to be moved to k8s.io/pkg anyway. So we are left with either vendoring huge amounts of files or copying code as-needed. Either case would be only temporary, ideally. TBH I would prefer we copy code as needed, we are all under the same k8s org&license after all, and it's not like we'll need to manually update the copied code of simple util functions frequently if at all.

And FWIW, from an initial attempt, refactoring pkg/volume/util is near impossible anyway atm, it is heavily tied to pkg/volume and idk how it will be made consumable for k8s.io/pkg or anywhere...

@msau42
Copy link
Contributor

msau42 commented Jul 13, 2017

Ah sorry, I instead of client-go, I meant putting it into k8s.io/pkg. Instead of pulling all of pkg/volume/util, can we just pull out the pieces we need for now?

@ianchakeres ianchakeres force-pushed the replace-frsize branch 2 times, most recently from 99ca77e to db975cf Compare July 14, 2017 01:37
@ianchakeres
Copy link
Contributor Author

@msau42 @wongma7 @ddysher - To handle the immediate issue with Frsize, should we go ahead with the current commit direction (aka pull dependencies into vendor) or revert back to leveraging the unix.Statfs directly?

@wongma7
Copy link
Contributor

wongma7 commented Jul 14, 2017

I'm okay with current direction, don't feel strongly either way. When k8s.io/pkg becomes a thing we can simply change a few import lines, run glide again, and all should be well. And I'd hate for your glide troubles to have been for nothing :)

@msau42
Copy link
Contributor

msau42 commented Jul 14, 2017

Ok sounds good, let's continue with the vendoring direction.

@ianchakeres
Copy link
Contributor Author

@msau42 & @wongma7 ok - I will proceed with vendoring direction.

@ianchakeres
Copy link
Contributor Author

@msau42 @ddysher @wongma7 - PTAL. I squashed my commits and left the vendor commit separate.

GetFsAvailableByte now uses the same method as
kubernetes/pkg/volume/util/fs.go:FsInfo(path)
to calculate available bytes
@msau42
Copy link
Contributor

msau42 commented Jul 17, 2017

/lgtm

@wongma7 can you check out the vendoring changes?

@ddysher
Copy link
Contributor

ddysher commented Jul 18, 2017

LGTM 👍

@wongma7 wongma7 added lgtm Indicates that a PR is ready to be merged. area/local-volume labels Jul 24, 2017
@wongma7 wongma7 merged commit e186f03 into kubernetes-retired:master Jul 24, 2017
cofyc pushed a commit to cofyc/external-storage that referenced this pull request Dec 17, 2018
…size

[local-volume] Refactored GetFsAvailableByte to avoid using Frsize in local-volume provisioner
yangruiray pushed a commit to yangruiray/external-storage that referenced this pull request Jul 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/local-volume cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants