Skip to content

Commit

Permalink
Merge pull request #12838 from juanvallejo/jvallejo/improve-override-…
Browse files Browse the repository at this point in the history
…flag-description

Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Feb 19, 2017
2 parents d90a085 + 4bcaf11 commit fb6905d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/man/man1/oc-set-volumes.1
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ For descriptions on other volume types, see

.PP
\fB\-\-overwrite\fP=false
If true, replace existing volume source and/or volume mount for the given resource
If true, replace existing volume source with the provided name and/or volume mount for the given resource

.PP
\fB\-\-path\fP=""
Expand Down
2 changes: 1 addition & 1 deletion docs/man/man1/oc-volumes.1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ DEPRECATED: This command has been moved to "oc set volume"

.PP
\fB\-\-overwrite\fP=false
If true, replace existing volume source and/or volume mount for the given resource
If true, replace existing volume source with the provided name and/or volume mount for the given resource

.PP
\fB\-\-path\fP=""
Expand Down
2 changes: 1 addition & 1 deletion docs/man/man1/openshift-cli-set-volumes.1
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ For descriptions on other volume types, see

.PP
\fB\-\-overwrite\fP=false
If true, replace existing volume source and/or volume mount for the given resource
If true, replace existing volume source with the provided name and/or volume mount for the given resource

.PP
\fB\-\-path\fP=""
Expand Down
2 changes: 1 addition & 1 deletion docs/man/man1/openshift-cli-volumes.1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ DEPRECATED: This command has been moved to "openshift cli set volume"

.PP
\fB\-\-overwrite\fP=false
If true, replace existing volume source and/or volume mount for the given resource
If true, replace existing volume source with the provided name and/or volume mount for the given resource

.PP
\fB\-\-path\fP=""
Expand Down
10 changes: 9 additions & 1 deletion pkg/cmd/cli/cmd/set/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func NewCmdVolume(fullName string, f *clientcmd.Factory, out, errOut io.Writer)
cmd.Flags().StringVarP(&addOpts.Type, "type", "t", "", "Type of the volume source for add operation. Supported options: emptyDir, hostPath, secret, configmap, persistentVolumeClaim")
cmd.Flags().StringVarP(&addOpts.MountPath, "mount-path", "m", "", "Mount path inside the container. Optional param for --add or --remove")
cmd.Flags().StringVarP(&addOpts.DefaultMode, "default-mode", "", "", "The default mode bits to create files with. Can be between 0000 and 0777. Defaults to 0644.")
cmd.Flags().BoolVar(&addOpts.Overwrite, "overwrite", false, "If true, replace existing volume source and/or volume mount for the given resource")
cmd.Flags().BoolVar(&addOpts.Overwrite, "overwrite", false, "If true, replace existing volume source with the provided name and/or volume mount for the given resource")
cmd.Flags().StringVar(&addOpts.Path, "path", "", "Host path. Must be provided for hostPath volume type")
cmd.Flags().StringVar(&addOpts.ConfigMapName, "configmap-name", "", "Name of the persisted config map. Must be provided for configmap volume type")
cmd.Flags().StringVar(&addOpts.SecretName, "secret-name", "", "Name of the persisted secret. Must be provided for secret volume type")
Expand Down Expand Up @@ -728,8 +728,10 @@ func (v *VolumeOptions) addVolumeToSpec(spec *kapi.PodSpec, info *resource.Info,
Name: v.Name,
}
setSource := true
vNameFound := false
for i, vol := range spec.Volumes {
if v.Name == vol.Name {
vNameFound = true
if !opts.Overwrite {
return fmt.Errorf("volume '%s' already exists. Use --overwrite to replace", v.Name)
}
Expand All @@ -742,6 +744,12 @@ func (v *VolumeOptions) addVolumeToSpec(spec *kapi.PodSpec, info *resource.Info,
}
}

// if --overwrite was passed, but volume did not previously
// exist, log a warning that no volumes were overwritten
if !vNameFound && opts.Overwrite && len(v.Output) == 0 {
fmt.Fprintf(v.Err, "warning: volume %q did not previously exist and was not overriden. A new volume with this name has been created instead.", v.Name)
}

if setSource {
err := v.setVolumeSource(newVolume)
if err != nil {
Expand Down

0 comments on commit fb6905d

Please sign in to comment.