Skip to content

Commit

Permalink
fix -o panic oc rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Jan 9, 2018
1 parent 96f2f77 commit 6a9c123
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pkg/oc/cli/cmd/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ var (
%[1]s rollback frontend-2
# Perform the rollback manually by piping the JSON of the new config back to %[1]s
%[1]s rollback frontend -o json | %[1]s replace dc/frontend -f -`)
%[1]s rollback frontend -o json | %[1]s replace dc/frontend -f -
# Print the updated deployment configuration in JSON format instead of performing the rollback
%[1]s rollback frontend -o json`)
)

// NewCmdRollback creates a CLI rollback command.
Expand Down Expand Up @@ -86,9 +89,9 @@ func NewCmdRollback(fullName string, f *clientcmd.Factory, out io.Writer) *cobra
cmd.Flags().BoolVar(&opts.IncludeStrategy, "change-strategy", false, "If true, include the previous deployment's strategy in the rollback")
cmd.Flags().BoolVar(&opts.IncludeScalingSettings, "change-scaling-settings", false, "If true, include the previous deployment's replicationController replica count and selector in the rollback")
cmd.Flags().BoolVarP(&opts.DryRun, "dry-run", "d", false, "Instead of performing the rollback, describe what the rollback will look like in human-readable form")
cmd.Flags().StringVarP(&opts.Format, "output", "o", "", "Instead of performing the rollback, print the updated deployment configuration in the specified format (json|yaml|name|template|templatefile)")
cmd.Flags().StringVarP(&opts.Template, "template", "t", "", "Template string or path to template file to use when -o=template or -o=templatefile.")
cmd.MarkFlagFilename("template")

kcmdutil.AddPrinterFlags(cmd)
cmd.Flags().Int64Var(&opts.DesiredVersion, "to-version", 0, "A config version to rollback to. Specifying version 0 is the same as omitting a version (the version will be auto-detected). This option is ignored when specifying a deployment.")

return cmd
Expand Down Expand Up @@ -151,6 +154,8 @@ func (o *RollbackOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, arg

o.out = out

o.Format = kcmdutil.GetFlagString(cmd, "output")

if len(o.Format) > 0 {
o.printer, err = f.PrinterForOptions(kcmdutil.ExtractCmdPrintOptions(cmd, false))
if err != nil {
Expand Down
19 changes: 17 additions & 2 deletions pkg/oc/cli/cmd/rollout/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
kprinters "k8s.io/kubernetes/pkg/printers"

appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
appsclientinternal "github.com/openshift/origin/pkg/apps/generated/internalclientset/typed/apps/internalversion"
Expand All @@ -32,8 +33,11 @@ var (
your image change triggers.`)

rolloutLatestExample = templates.Examples(`
# Start a new rollout based on the latest images defined in the image change triggers.
%[1]s rollout latest dc/nginx`)
# Start a new rollout based on the latest images defined in the image change triggers.
%[1]s rollout latest dc/nginx
# Print the deployment config that would be rolled out in JSON format, without performing the rollout.
%[1]s rollout latest dc/nginx -o json`)
)

// RolloutLatestOptions holds all the options for the `rollout latest` command.
Expand All @@ -50,6 +54,8 @@ type RolloutLatestOptions struct {
appsClient appsclientinternal.DeploymentConfigsGetter
kc kclientset.Interface
baseCommandName string

printer kprinters.ResourcePrinter
}

// NewCmdRolloutLatest implements the oc rollout latest subcommand.
Expand Down Expand Up @@ -122,6 +128,11 @@ func (o *RolloutLatestOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command
o.output = kcmdutil.GetFlagString(cmd, "output")
o.again = kcmdutil.GetFlagBool(cmd, "again")

o.printer, err = f.PrinterForOptions(kcmdutil.ExtractCmdPrintOptions(cmd, false))
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -187,6 +198,10 @@ func (o RolloutLatestOptions) RunRolloutLatest() error {
return nil
}

if len(o.output) > 0 {
return o.printer.PrintObj(dc, o.out)
}

kcmdutil.PrintSuccess(o.mapper, o.output == "name", o.out, info.Mapping.Resource, info.Name, o.DryRun, "rolled out")
return nil
}

0 comments on commit 6a9c123

Please sign in to comment.