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

refector: refect the pouch's volume module #2379

Merged

Conversation

rudyfly
Copy link
Collaborator

@rudyfly rudyfly commented Oct 29, 2018

Ⅰ. Describe what this PR did

  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

Ⅱ. 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

@codecov
Copy link

codecov bot commented Oct 29, 2018

Codecov Report

Merging #2379 into master will increase coverage by 11.57%.
The diff coverage is 49.37%.

Impacted file tree graph

@@             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
Flag Coverage Δ
#criv1alpha1test 31.55% <3.34%> (-0.07%) ⬇️
#criv1alpha2test 35.53% <25.1%> (-0.21%) ⬇️
#integrationtest 40.1% <41%> (?)
#nodee2etest 32.98% <4.6%> (-0.14%) ⬇️
#unittest 26.58% <22.05%> (+0.04%) ⬆️
Impacted Files Coverage Δ
pkg/errtypes/errors.go 100% <ø> (+38.09%) ⬆️
storage/volume/types/meta/meta.go 0% <ø> (ø) ⬆️
storage/volume/driver/fake_driver.go 50% <0%> (ø) ⬆️
storage/volume/modules/tmpfs/tmpfs.go 12.82% <0%> (-3.31%) ⬇️
storage/quota/prjquota.go 27.51% <0%> (ø) ⬆️
storage/quota/grpquota.go 0% <0%> (ø) ⬆️
pkg/utils/utils.go 83.82% <100%> (+4.03%) ⬆️
storage/volume/types/volume_util.go 85.71% <100%> (+23.21%) ⬆️
storage/volume/modules/local/local.go 76.38% <100%> (+12.75%) ⬆️
storage/quota/quota.go 45.04% <16.12%> (-1.91%) ⬇️
... and 92 more

@pouchrobot pouchrobot added areas/storage kind/bug This is bug report for project size/XL labels Oct 29, 2018
}
volume, err := mgr.VolumeMgr.Get(ctx, name)
if err != nil || volume == nil {
logrus.Errorf("failed to get volume: (%s), err: (%v)", name, err)
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

weird... still not changed

@@ -193,21 +200,25 @@ func (v *Volume) CreateTime() string {

// VolumeID use to define the volume's identity.
type VolumeID struct {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

}
id, err := GetNextQuotaID()
if err != nil {
return 0, errors.Wrapf(err, "failed to get file: (%s) quota id", dir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please remove :

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -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)
Copy link
Collaborator

@allencloud allencloud Oct 29, 2018

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?

@@ -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() {
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have merged them.

@@ -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) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

@allencloud
Copy link
Collaborator

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{
Copy link
Contributor

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.

Copy link
Collaborator Author

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 != "" {
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No need 😄

@zhuangqh
Copy link
Contributor

zhuangqh commented Nov 1, 2018

please also fix this issue #2403 thanks

@rudyfly rudyfly force-pushed the master_remotevolume branch 2 times, most recently from 606c718 to e2af333 Compare November 2, 2018 03:09
@rudyfly
Copy link
Collaborator Author

rudyfly commented Nov 2, 2018

@rudyfly
Copy link
Collaborator Author

rudyfly commented Nov 2, 2018

@allencloud It's hard to change the type of size now, because we have store it into boltdb.

@rudyfly rudyfly force-pushed the master_remotevolume branch 6 times, most recently from 13088e5 to 1469d80 Compare November 7, 2018 07:41
@rudyfly rudyfly changed the title bugfix: fix some volume bugs refector: refect the pouch's volume module Nov 7, 2018
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>
@rudyfly rudyfly force-pushed the master_remotevolume branch from 1469d80 to de46416 Compare November 7, 2018 07:55

// 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 {
Copy link
Contributor

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),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why delete the Selector?

@HusterWan
Copy link
Contributor

Since I still have some comments, but I think them not stuck for merge this PR,
So LGTM, thanks for your works, Boss Ku !

@HusterWan
Copy link
Contributor

lgtm

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Nov 7, 2018
@HusterWan HusterWan merged commit c7a568e into AliyunContainerService:master Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
areas/storage kind/bug This is bug report for project LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants