-
Notifications
You must be signed in to change notification settings - Fork 950
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
refector: refect the pouch's volume module #2379
refector: refect the pouch's volume module #2379
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2379 +/- ##
===========================================
+ Coverage 57.26% 68.83% +11.57%
===========================================
Files 277 276 -1
Lines 18227 18252 +25
===========================================
+ Hits 10437 12564 +2127
+ Misses 6582 4271 -2311
- Partials 1208 1417 +209
|
daemon/mgr/container_storage.go
Outdated
} | ||
volume, err := mgr.VolumeMgr.Get(ctx, name) | ||
if err != nil || volume == nil { | ||
logrus.Errorf("failed to get volume: (%s), err: (%v)", name, err) |
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.
Could you use the same way to construct log and error message?
I found that in L178, you use logrus.Errorf("failed to bind volume(%s): %v", name, err)
, but here logrus.Errorf("failed to get volume: (%s), err: (%v)", name, err)
.
How about that?
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
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.
weird... still not changed
storage/volume/types/volume.go
Outdated
@@ -193,21 +200,25 @@ func (v *Volume) CreateTime() string { | |||
|
|||
// VolumeID use to define the volume's identity. | |||
type VolumeID struct { |
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.
Could we change the name of VolumeID?It is so strange.
Is this that this VolumeID will be stored in some legacy db?
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.
I have change the name to VolumeContext
.
storage/quota/quota.go
Outdated
} | ||
id, err := GetNextQuotaID() | ||
if err != nil { | ||
return 0, errors.Wrapf(err, "failed to get file: (%s) quota id", dir) |
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.
please remove :
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
storage/quota/quota.go
Outdated
@@ -181,18 +196,20 @@ func GetDefaultQuota(quotas map[string]string) string { | |||
func SetRootfsDiskQuota(basefs, size string, quotaID uint32) (uint32, error) { | |||
overlayMountInfo, err := getOverlayMountInfo(basefs) | |||
if err != nil { | |||
return 0, fmt.Errorf("failed to get overlay mount info: %v", err) | |||
return 0, errors.Wrapf(err, "failed to get overlay:(%s) mount info", basefs) |
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.
please remove :
and could you fix that in all of the pull request?
daemon/mgr/volume.go
Outdated
@@ -83,6 +83,9 @@ func (vm *VolumeManager) Create(ctx context.Context, name, driver string, option | |||
|
|||
v, err := vm.core.CreateVolume(id) | |||
if err != nil { | |||
if e, ok := err.(*volerr.CoreError); ok && e.IsVolumeExisted() { |
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.
Could we have a way to combine pkg/errtypes
and storage/volume/error
into one?
Or extract the common part? @rudyfly
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.
I have merged them.
0fccb7f
to
6823770
Compare
6823770
to
847943c
Compare
storage/volume/core.go
Outdated
@@ -159,43 +159,43 @@ func (c *Core) getVolumeDriver(id types.VolumeID) (*types.Volume, driver.Driver, | |||
} | |||
|
|||
// existVolume return 'true' if volume be found and not errors. | |||
func (c *Core) existVolume(id types.VolumeID) (bool, error) { | |||
_, err := c.getVolume(id) | |||
func (c *Core) existVolume(id types.VolumeContext) (*types.Volume, bool, 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.
I am wondering if it is necessary to update the return parameter of this function. I saw that you added an instance of *types.Volume
in the function.
When I searched the code, I found that this is used in core.CreateVolume
, and this *types.Volume
is only used when the input volume ID exists, then you returned the volume.
I think with the change, you break the primitives of this function.
As an encapsulated package, we should make the function to be focused as much as possible. when checking if it exists, the main part is the returned boolean, if the returned error is necessary, it is ok.
But when we return a Volume instance, it combines two actions into a single one, to break the purity of this function existVolume
.
If the caller need the types.Volume
instance when it is already exists, please let it use another function to get it, like core.GetVolumes(...)
.
WDYT? @rudyfly
In addition, would you mind changing function name into isVolumeExist
?
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.
good idea, I fix it.
For user's input size, Size, opt.Size or others, could we first convert them into bytes which is a type of integer. So all the value dealing is all about integer rather rather string. When to the lower part where we must to convert them into string, then we do the convertion. Otherwise the string dealing all along the path may lead to some unreadability or some potential bugs. WDYT? @rudyfly |
Options: map[string]string{}, | ||
Selectors: map[string]string{}, | ||
Labels: map[string]string{}, | ||
id := types.VolumeContext{ |
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.
change VolumeID
to VolumeContext
, feel better.
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.
🐶
func (v *Volume) Size() string { | ||
return v.Spec.Size | ||
if v.Spec.Size != "" { |
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.
Can we add some verification for the Size
in API interface?
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.
No need 😄
please also fix this issue #2403 thanks |
606c718
to
e2af333
Compare
@allencloud It's hard to change the type of |
e2af333
to
660386b
Compare
660386b
to
ca90c83
Compare
ca90c83
to
592572d
Compare
13088e5
to
1469d80
Compare
1. don't return error when create volume is exist. 2. Refect the `VolumeID` to `VolumeContext`. 3. remove unuse field `Selectors` in `VolumeContext`. 4. set directory's quota id after check the limit of device. 5. get volume's size in `Extra` field. 6. add more options to set volume's size, you also can use "-o size=10g" or "-o Size=10g" or "-o opt.Size=10g" to set volume's size. 7. merge volume's error into `pkg/errtypes` 8. remove unuse package `pkg/serializer` Signed-off-by: Rudy Zhang <rudyflyzhang@gmail.com>
1469d80
to
de46416
Compare
|
||
// ToStringMap changes the map[string]interface{} to map[string]string, | ||
// If the interface is not string, it will be ignore. | ||
func ToStringMap(in map[string]interface{}) map[string]string { |
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.
feel weird, enough though I can not figure out a more proper solution.
@@ -45,9 +30,8 @@ func NewVolumeFromID(mountPath, size string, id VolumeID) *Volume { | |||
ModifyTimestamp: &now, | |||
}, | |||
Spec: &VolumeSpec{ | |||
Backend: id.Driver, | |||
Extra: id.Options, | |||
Selector: make(Selector, 0), |
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.
Why delete the Selector
?
Since I still have some comments, but I think them not stuck for merge this PR, |
lgtm |
Ⅰ. Describe what this PR did
VolumeID
toVolumeContext
.Selectors
inVolumeContext
.Extra
field."-o Size=10g" or "-o opt.Size=10g" to set volume's size.
pkg/errtypes
pkg/serializer
Ⅱ. Does this pull request fix one issue?
NONE
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
Added
TestToStringMap
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews
Signed-off-by: Rudy Zhang rudyflyzhang@gmail.com