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

Change the order of Validate() and Complete() for oc set volume #19169

Merged
merged 1 commit into from
Apr 12, 2018
Merged

Conversation

nak3
Copy link
Contributor

@nak3 nak3 commented Mar 31, 2018

When oc set volum was run, cli proceeds
Validate()->Complete(). This order is different from any other
cli implementations. Currently there are no isseus, but this may
effect future implementation so fix it now.

@openshift-ci-robot openshift-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 31, 2018
@mfojtik
Copy link
Contributor

mfojtik commented Apr 3, 2018

/sig master
/assign maszulik

@openshift-ci-robot
Copy link

@mfojtik: GitHub didn't allow me to assign the following users: maszulik.

Note that only openshift members and repo collaborators can be assigned.

In response to this:

/sig master
/assign maszulik

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.

@@ -411,9 +415,6 @@ func (v *VolumeOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, out,
}
v.AddOpts.ClaimSize = q.String()
}
if len(v.AddOpts.DefaultMode) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's actually good piece of code that should be left here. Removing it from here you're creating two places where you're setting the default mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@soltysh Thank you. But if DefaultMode was set here, other storage type (emptydir,hostpath ..) will be broken with current validation check. You can refer to the eror
Is it OK to change them? I think codes under func (a *AddVolumeOptions) Validate(isAddOp bool) need a big change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to fix it as necessary, but ensure you don't create duplicate code paths.

@@ -307,7 +307,9 @@ func (a *AddVolumeOptions) Validate(isAddOp bool) error {
if len(a.SecretName) == 0 {
return errors.New("must provide --secret-name for --type=secret")
}
if len(a.DefaultMode) > 0 {
if len(a.DefaultMode) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert previous version.

@@ -316,7 +318,9 @@ func (a *AddVolumeOptions) Validate(isAddOp bool) error {
if len(a.ConfigMapName) == 0 {
return errors.New("must provide --configmap-name for --type=configmap")
}
if len(a.DefaultMode) > 0 {
if len(a.DefaultMode) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@openshift-ci-robot openshift-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 4, 2018
@nak3
Copy link
Contributor Author

nak3 commented Apr 7, 2018

/retest

@nak3
Copy link
Contributor Author

nak3 commented Apr 7, 2018

@soltysh Thank you. Updated.

case numOps == 0:
v.List = true
case numOps > 1:
return errors.New("you may only specify one operation at a time")
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a validation error; keeping it in Validate seems right to me

Copy link
Contributor

Choose a reason for hiding this comment

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

hm, since numOps is used to set the value of v.List to true, I'd be okay with still moving this to Validate and having that field completed there - still better than having all of the other completion logic that was in that method before. @soltysh for an opinion

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave this as is. I don't think we need to enforce every check be only in Validate.

// In case of volume source ignore the default volume type
if len(v.AddOpts.Source) > 0 {
v.AddOpts.Type = ""
if len(a.Source) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

since Validate used to be called first, and this block was called in Complete, move this block to the end of this method

v.AddOpts.CreateClaim = true
if len(v.AddOpts.ClaimName) == 0 {
v.AddOpts.ClaimName = names.SimpleNameGenerator.GenerateName("pvc-")
if len(a.ClaimSize) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

same with this block

case "":
default:
return errors.New("--claim-mode must be one of ReadWriteOnce (rwo), ReadWriteMany (rwm), or ReadOnlyMany (rom)")
}

if len(a.Type) == 0 {
if len(a.ClaimName) > 0 || len(a.ClaimSize) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please turn this into a switch, should make it a bit easier to read:

if len(a.Type) == 0 {
	switch {
	case len(a.ClaimName) > 0 || len(a.ClaimSize) > 0:
		a.Type = "persistentvolumeclaim"
		a.TypeChanged = true
	case len(a.SecretName) > 0:
		a.Type = "secret"
		a.TypeChanged = true
	case len(a.ConfigMapName) > 0:
		a.Type = "configmap"
		a.TypeChanged = true
	case len(a.Path) > 0:
		a.Type = "hostpath"
		a.TypeChanged = true
	default:
		a.Type = "emptydir"
	}
}

@juanvallejo
Copy link
Contributor

Overall, the changes look good.
A few comments regarding the calling order of a few things.

Please squash commits

@nak3
Copy link
Contributor Author

nak3 commented Apr 9, 2018

/test cmd

@nak3
Copy link
Contributor Author

nak3 commented Apr 9, 2018

/test cmd

mmm... cmd test failed, but it should not related to this change.

@nak3
Copy link
Contributor Author

nak3 commented Apr 10, 2018

/test cmd

@nak3
Copy link
Contributor Author

nak3 commented Apr 10, 2018

@juanvallejo @soltysh Thank you! Updated & Squashed.

@juanvallejo
Copy link
Contributor

/test gcp

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 12, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nak3, soltysh

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 12, 2018
@soltysh
Copy link
Contributor

soltysh commented Apr 12, 2018

/retest

@openshift-merge-robot openshift-merge-robot merged commit f83dfd7 into openshift:master Apr 12, 2018
@nak3 nak3 deleted the set-volume branch April 13, 2018 12:57
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. lgtm Indicates that a PR is ready to be merged. sig/master size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants