Skip to content

Commit 0934913

Browse files
Merge pull request #18040 from juanvallejo/jvallejo/fix-generic-output-rollback
Automatic merge from submit-queue (batch tested with PRs 18040, 18097, 18098, 18106, 18087). fix -o panic oc rollback Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1532527 Fix panic caused by a missing `no-headers` flag. Add support for `json` format output in `oc rollout dc/...` - previously, it was possible to specify the flag for the command, but it was ignored cc @openshift/cli-review @soltysh
2 parents 793835e + 5428dd7 commit 0934913

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

contrib/completions/bash/oc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15768,6 +15768,8 @@ _oc_rollback()
1576815768
flags_with_completion=()
1576915769
flags_completion=()
1577015770

15771+
flags+=("--allow-missing-template-keys")
15772+
local_nonpersistent_flags+=("--allow-missing-template-keys")
1577115773
flags+=("--change-scaling-settings")
1577215774
local_nonpersistent_flags+=("--change-scaling-settings")
1577315775
flags+=("--change-strategy")
@@ -15777,15 +15779,23 @@ _oc_rollback()
1577715779
flags+=("--dry-run")
1577815780
flags+=("-d")
1577915781
local_nonpersistent_flags+=("--dry-run")
15782+
flags+=("--no-headers")
15783+
local_nonpersistent_flags+=("--no-headers")
1578015784
flags+=("--output=")
1578115785
two_word_flags+=("-o")
1578215786
local_nonpersistent_flags+=("--output=")
15787+
flags+=("--output-version=")
15788+
local_nonpersistent_flags+=("--output-version=")
15789+
flags+=("--show-all")
15790+
flags+=("-a")
15791+
local_nonpersistent_flags+=("--show-all")
15792+
flags+=("--show-labels")
15793+
local_nonpersistent_flags+=("--show-labels")
15794+
flags+=("--sort-by=")
15795+
local_nonpersistent_flags+=("--sort-by=")
1578315796
flags+=("--template=")
1578415797
flags_with_completion+=("--template")
1578515798
flags_completion+=("_filedir")
15786-
two_word_flags+=("-t")
15787-
flags_with_completion+=("-t")
15788-
flags_completion+=("_filedir")
1578915799
local_nonpersistent_flags+=("--template=")
1579015800
flags+=("--to-version=")
1579115801
local_nonpersistent_flags+=("--to-version=")

contrib/completions/zsh/oc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15910,6 +15910,8 @@ _oc_rollback()
1591015910
flags_with_completion=()
1591115911
flags_completion=()
1591215912

15913+
flags+=("--allow-missing-template-keys")
15914+
local_nonpersistent_flags+=("--allow-missing-template-keys")
1591315915
flags+=("--change-scaling-settings")
1591415916
local_nonpersistent_flags+=("--change-scaling-settings")
1591515917
flags+=("--change-strategy")
@@ -15919,15 +15921,23 @@ _oc_rollback()
1591915921
flags+=("--dry-run")
1592015922
flags+=("-d")
1592115923
local_nonpersistent_flags+=("--dry-run")
15924+
flags+=("--no-headers")
15925+
local_nonpersistent_flags+=("--no-headers")
1592215926
flags+=("--output=")
1592315927
two_word_flags+=("-o")
1592415928
local_nonpersistent_flags+=("--output=")
15929+
flags+=("--output-version=")
15930+
local_nonpersistent_flags+=("--output-version=")
15931+
flags+=("--show-all")
15932+
flags+=("-a")
15933+
local_nonpersistent_flags+=("--show-all")
15934+
flags+=("--show-labels")
15935+
local_nonpersistent_flags+=("--show-labels")
15936+
flags+=("--sort-by=")
15937+
local_nonpersistent_flags+=("--sort-by=")
1592515938
flags+=("--template=")
1592615939
flags_with_completion+=("--template")
1592715940
flags_completion+=("_filedir")
15928-
two_word_flags+=("-t")
15929-
flags_with_completion+=("-t")
15930-
flags_completion+=("_filedir")
1593115941
local_nonpersistent_flags+=("--template=")
1593215942
flags+=("--to-version=")
1593315943
local_nonpersistent_flags+=("--to-version=")

pkg/oc/cli/cmd/rollback.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ var (
5656
%[1]s rollback frontend-2
5757
5858
# Perform the rollback manually by piping the JSON of the new config back to %[1]s
59-
%[1]s rollback frontend -o json | %[1]s replace dc/frontend -f -`)
59+
%[1]s rollback frontend -o json | %[1]s replace dc/frontend -f -
60+
61+
# Print the updated deployment configuration in JSON format instead of performing the rollback
62+
%[1]s rollback frontend -o json`)
6063
)
6164

6265
// NewCmdRollback creates a CLI rollback command.
@@ -86,9 +89,9 @@ func NewCmdRollback(fullName string, f *clientcmd.Factory, out io.Writer) *cobra
8689
cmd.Flags().BoolVar(&opts.IncludeStrategy, "change-strategy", false, "If true, include the previous deployment's strategy in the rollback")
8790
cmd.Flags().BoolVar(&opts.IncludeScalingSettings, "change-scaling-settings", false, "If true, include the previous deployment's replicationController replica count and selector in the rollback")
8891
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")
89-
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)")
90-
cmd.Flags().StringVarP(&opts.Template, "template", "t", "", "Template string or path to template file to use when -o=template or -o=templatefile.")
9192
cmd.MarkFlagFilename("template")
93+
94+
kcmdutil.AddPrinterFlags(cmd)
9295
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.")
9396

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

152155
o.out = out
153156

157+
o.Format = kcmdutil.GetFlagString(cmd, "output")
158+
154159
if len(o.Format) > 0 {
155160
o.printer, err = f.PrinterForOptions(kcmdutil.ExtractCmdPrintOptions(cmd, false))
156161
if err != nil {

pkg/oc/cli/cmd/rollout/latest.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
1515
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
1616
"k8s.io/kubernetes/pkg/kubectl/resource"
17+
kprinters "k8s.io/kubernetes/pkg/printers"
1718

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

3435
rolloutLatestExample = templates.Examples(`
35-
# Start a new rollout based on the latest images defined in the image change triggers.
36-
%[1]s rollout latest dc/nginx`)
36+
# Start a new rollout based on the latest images defined in the image change triggers.
37+
%[1]s rollout latest dc/nginx
38+
39+
# Print the rolled out deployment config
40+
%[1]s rollout latest dc/nginx -o json`)
3741
)
3842

3943
// RolloutLatestOptions holds all the options for the `rollout latest` command.
@@ -50,6 +54,8 @@ type RolloutLatestOptions struct {
5054
appsClient appsclientinternal.DeploymentConfigsGetter
5155
kc kclientset.Interface
5256
baseCommandName string
57+
58+
printer kprinters.ResourcePrinter
5359
}
5460

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

131+
if o.output != "revision" {
132+
o.printer, err = f.PrinterForOptions(kcmdutil.ExtractCmdPrintOptions(cmd, false))
133+
if err != nil {
134+
return err
135+
}
136+
}
137+
125138
return nil
126139
}
127140

@@ -185,6 +198,8 @@ func (o RolloutLatestOptions) RunRolloutLatest() error {
185198
if o.output == "revision" {
186199
fmt.Fprintf(o.out, fmt.Sprintf("%d", dc.Status.LatestVersion))
187200
return nil
201+
} else if len(o.output) > 0 {
202+
return o.printer.PrintObj(dc, o.out)
188203
}
189204

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

0 commit comments

Comments
 (0)