Skip to content

Commit

Permalink
Bug 1989504: Do not require override when clearing unkown channel
Browse files Browse the repository at this point in the history
Add more detailed information to help info and output messages. And
make a change to not require --allow-explicit-channel when clearing
an unkown channel. More info is in this bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1989504
  • Loading branch information
shellyyang1989 committed Aug 4, 2021
1 parent 1557476 commit c129c1b
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions pkg/cli/admin/upgrade/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ func New(f kcmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command
This command will set or clear the update channel, which impacts the list of updates
recommended for the cluster.
If there is a list of acceptable channels and the desired channel is not in that list,
you must pass --allow-explicit-channel to allow channel change to proceed.
If desired channel is empty, the command will clear the update channel. If there is a list of
acceptable channels and the current update channel is in that list, you must pass --allow-explicit-channel to allow channel clear to
proceed.
If desired channel is not empty, the command will set the update channel to it. If there is a list of
acceptable channels and the desired channel is not in that list, you must pass --allow-explicit-channel
to allow channel change to proceed.
`),
Run: func(cmd *cobra.Command, args []string) {
kcmdutil.CheckErr(o.Complete(f, cmd, args))
Expand Down Expand Up @@ -86,31 +91,38 @@ func (o *Options) Run() error {

if o.Channel == cv.Spec.Channel {
if cv.Spec.Channel == "" {
fmt.Fprint(o.Out, "info: Cluster channel is already clear\n")
fmt.Fprint(o.Out, "info: Cluster channel is already clear (no change)\n")
} else {
fmt.Fprintf(o.Out, "info: Cluster is already in %s\n", cv.Spec.Channel)
fmt.Fprintf(o.Out, "info: Cluster is already in %s (no change)\n", cv.Spec.Channel)
}
return nil
}

if len(cv.Status.Desired.Channels) > 0 {
found := false
found, known := false, false
for _, channel := range cv.Status.Desired.Channels {
if channel == o.Channel {
found = true
}
if channel == cv.Spec.Channel {
known = true
}
if found && known {
break
}
}
if !found {
if o.Channel == "" {
if known && !o.AllowExplicitChannel {
return fmt.Errorf("You are requesting to clear the update channel. The current channel %q is one of the available channels, you must pass --allow-explicit-channel to continue\n", cv.Spec.Channel)
}
} else if !found {
if !o.AllowExplicitChannel {
return fmt.Errorf("the requested channel %q is not one of the available channels (%s), you must pass --allow-explicit-channel to continue\n", o.Channel, strings.Join(cv.Status.Desired.Channels, ", "))
}
if o.Channel != "" {
fmt.Fprintf(o.ErrOut, "warning: The requested channel %q is not one of the available channels (%s). You have used --allow-explicit-channel to proceed anyway.\n", o.Channel, strings.Join(cv.Status.Desired.Channels, ", "))
}
fmt.Fprintf(o.ErrOut, "warning: The requested channel %q is not one of the available channels (%s). You have used --allow-explicit-channel to proceed anyway. Setting the update channel to %q.\n", o.Channel, strings.Join(cv.Status.Desired.Channels, ", "), o.Channel)
}
} else if o.Channel != "" {
fmt.Fprintf(o.ErrOut, "warning: No channels known to be compatible with the current version %q; unable to validate %q.\n", cv.Status.Desired.Version, o.Channel)
fmt.Fprintf(o.ErrOut, "warning: No channels known to be compatible with the current version %q; unable to validate %q. Setting the update channel to %q anyway.\n", cv.Status.Desired.Version, o.Channel, o.Channel)
}

if o.Channel == "" {
Expand Down

0 comments on commit c129c1b

Please sign in to comment.