-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
/sig master |
@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:
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. |
pkg/oc/cli/cmd/set/volume.go
Outdated
@@ -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 { |
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.
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.
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.
@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.
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 free to fix it as necessary, but ensure you don't create duplicate code paths.
pkg/oc/cli/cmd/set/volume.go
Outdated
@@ -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 { |
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.
Revert previous version.
pkg/oc/cli/cmd/set/volume.go
Outdated
@@ -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 { |
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.
Ditto.
/retest |
@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") |
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 looks like a validation error; keeping it in Validate seems right to me
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.
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
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.
Let's leave this as is. I don't think we need to enforce every check be only in Validate
.
pkg/oc/cli/cmd/set/volume.go
Outdated
// In case of volume source ignore the default volume type | ||
if len(v.AddOpts.Source) > 0 { | ||
v.AddOpts.Type = "" | ||
if len(a.Source) > 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.
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 { |
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.
same with this block
pkg/oc/cli/cmd/set/volume.go
Outdated
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 { |
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 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"
}
}
Overall, the changes look good. Please squash commits |
/test cmd |
/test cmd mmm... cmd test failed, but it should not related to this change. |
/test cmd |
@juanvallejo @soltysh Thank you! Updated & Squashed. |
/test gcp |
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
/approve
[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 |
/retest |
When
oc set volum
was run, cli proceedsValidate()
->Complete()
. This order is different from any othercli implementations. Currently there are no isseus, but this may
effect future implementation so fix it now.