Skip to content

fix -o panic oc rollback #18040

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions contrib/completions/bash/oc
Original file line number Diff line number Diff line change
Expand Up @@ -15784,6 +15784,8 @@ _oc_rollback()
flags_with_completion=()
flags_completion=()

flags+=("--allow-missing-template-keys")
local_nonpersistent_flags+=("--allow-missing-template-keys")
flags+=("--change-scaling-settings")
local_nonpersistent_flags+=("--change-scaling-settings")
flags+=("--change-strategy")
Expand All @@ -15793,15 +15795,23 @@ _oc_rollback()
flags+=("--dry-run")
flags+=("-d")
local_nonpersistent_flags+=("--dry-run")
flags+=("--no-headers")
local_nonpersistent_flags+=("--no-headers")
flags+=("--output=")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--output-version=")
local_nonpersistent_flags+=("--output-version=")
flags+=("--show-all")
flags+=("-a")
local_nonpersistent_flags+=("--show-all")
flags+=("--show-labels")
local_nonpersistent_flags+=("--show-labels")
flags+=("--sort-by=")
local_nonpersistent_flags+=("--sort-by=")
flags+=("--template=")
flags_with_completion+=("--template")
flags_completion+=("_filedir")
two_word_flags+=("-t")
flags_with_completion+=("-t")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--template=")
flags+=("--to-version=")
local_nonpersistent_flags+=("--to-version=")
Expand Down
16 changes: 13 additions & 3 deletions contrib/completions/zsh/oc
Original file line number Diff line number Diff line change
Expand Up @@ -15926,6 +15926,8 @@ _oc_rollback()
flags_with_completion=()
flags_completion=()

flags+=("--allow-missing-template-keys")
local_nonpersistent_flags+=("--allow-missing-template-keys")
flags+=("--change-scaling-settings")
local_nonpersistent_flags+=("--change-scaling-settings")
flags+=("--change-strategy")
Expand All @@ -15935,15 +15937,23 @@ _oc_rollback()
flags+=("--dry-run")
flags+=("-d")
local_nonpersistent_flags+=("--dry-run")
flags+=("--no-headers")
local_nonpersistent_flags+=("--no-headers")
flags+=("--output=")
two_word_flags+=("-o")
local_nonpersistent_flags+=("--output=")
flags+=("--output-version=")
local_nonpersistent_flags+=("--output-version=")
flags+=("--show-all")
flags+=("-a")
local_nonpersistent_flags+=("--show-all")
flags+=("--show-labels")
local_nonpersistent_flags+=("--show-labels")
flags+=("--sort-by=")
local_nonpersistent_flags+=("--sort-by=")
flags+=("--template=")
flags_with_completion+=("--template")
flags_completion+=("_filedir")
two_word_flags+=("-t")
flags_with_completion+=("-t")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--template=")
flags+=("--to-version=")
local_nonpersistent_flags+=("--to-version=")
Expand Down
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 rolled out deployment config
%[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,13 @@ func (o *RolloutLatestOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command
o.output = kcmdutil.GetFlagString(cmd, "output")
o.again = kcmdutil.GetFlagBool(cmd, "again")

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

return nil
}

Expand Down Expand Up @@ -185,6 +198,8 @@ func (o RolloutLatestOptions) RunRolloutLatest() error {
if o.output == "revision" {
fmt.Fprintf(o.out, fmt.Sprintf("%d", dc.Status.LatestVersion))
return nil
} else 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")
Expand Down