diff --git a/pkg/cli/admin/upgrade/recommend/examples_test.go b/pkg/cli/admin/upgrade/recommend/examples_test.go index 96f9ff7ce2..0129d31aee 100644 --- a/pkg/cli/admin/upgrade/recommend/examples_test.go +++ b/pkg/cli/admin/upgrade/recommend/examples_test.go @@ -91,7 +91,6 @@ func TestExamples(t *testing.T) { if err := opts.Complete(nil, nil, nil); err != nil { t.Fatalf("Error when completing options: %v", err) } - opts.precheckEnabled = true var stdout, stderr bytes.Buffer opts.Out = &stdout diff --git a/pkg/cli/admin/upgrade/recommend/recommend.go b/pkg/cli/admin/upgrade/recommend/recommend.go index 0a39bc1994..89c54ea00f 100644 --- a/pkg/cli/admin/upgrade/recommend/recommend.go +++ b/pkg/cli/admin/upgrade/recommend/recommend.go @@ -76,7 +76,6 @@ type options struct { mockData mockData showOutdatedReleases bool - precheckEnabled bool // quiet configures the verbosity of output. When 'quiet' is true and 'version' is set, only print unaccepted issue names. quiet bool @@ -134,8 +133,6 @@ func (o *options) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string } } - o.precheckEnabled = true - return nil } @@ -188,47 +185,45 @@ func (o *options) Run(ctx context.Context) error { issues.Insert(string(configv1.OperatorProgressing)) } - if o.precheckEnabled { - conditions, err := o.precheck(ctx) - if err != nil { - if !o.quiet { - fmt.Fprintf(o.Out, "Failed to check for at least some preconditions: %v\n", err) - } - issues.Insert("FailedToCompletePrecheck") - } - var happyConditions []string - var acceptedConditions []string - var unhappyConditions []string - for _, condition := range conditions { - if condition.Status == metav1.ConditionTrue { - happyConditions = append(happyConditions, fmt.Sprintf("%s (%s)", condition.Type, condition.Reason)) + conditions, err := o.precheck(ctx) + if err != nil { + if !o.quiet { + fmt.Fprintf(o.Out, "Failed to check for at least some preconditions: %v\n", err) + } + issues.Insert("FailedToCompletePrecheck") + } + var happyConditions []string + var acceptedConditions []string + var unhappyConditions []string + for _, condition := range conditions { + if condition.Status == metav1.ConditionTrue { + happyConditions = append(happyConditions, fmt.Sprintf("%s (%s)", condition.Type, condition.Reason)) + } else { + issues.Insert(condition.acceptanceName) + if accept.Has(condition.acceptanceName) { + acceptedConditions = append(acceptedConditions, condition.Type) } else { - issues.Insert(condition.acceptanceName) - if accept.Has(condition.acceptanceName) { - acceptedConditions = append(acceptedConditions, condition.Type) - } else { - unhappyConditions = append(unhappyConditions, condition.Type) - } + unhappyConditions = append(unhappyConditions, condition.Type) } } + } - if !o.quiet { - if len(happyConditions) > 0 { - sort.Strings(happyConditions) - fmt.Fprintf(o.Out, "The following conditions found no cause for concern in updating this cluster to later releases: %s\n\n", strings.Join(happyConditions, ", ")) - } - if len(acceptedConditions) > 0 { - sort.Strings(acceptedConditions) - fmt.Fprintf(o.Out, "The following conditions found cause for concern in updating this cluster to later releases, but were explicitly accepted via --accept: %s\n\n", strings.Join(acceptedConditions, ", ")) - } - if len(unhappyConditions) > 0 { - sort.Strings(unhappyConditions) - fmt.Fprintf(o.Out, "The following conditions found cause for concern in updating this cluster to later releases: %s\n\n", strings.Join(unhappyConditions, ", ")) + if !o.quiet { + if len(happyConditions) > 0 { + sort.Strings(happyConditions) + fmt.Fprintf(o.Out, "The following conditions found no cause for concern in updating this cluster to later releases: %s\n\n", strings.Join(happyConditions, ", ")) + } + if len(acceptedConditions) > 0 { + sort.Strings(acceptedConditions) + fmt.Fprintf(o.Out, "The following conditions found cause for concern in updating this cluster to later releases, but were explicitly accepted via --accept: %s\n\n", strings.Join(acceptedConditions, ", ")) + } + if len(unhappyConditions) > 0 { + sort.Strings(unhappyConditions) + fmt.Fprintf(o.Out, "The following conditions found cause for concern in updating this cluster to later releases: %s\n\n", strings.Join(unhappyConditions, ", ")) - for _, c := range conditions { - if c.Status != metav1.ConditionTrue { - fmt.Fprintf(o.Out, "%s=%s:\n\n Reason: %s\n Message: %s\n\n", c.Type, c.Status, c.Reason, strings.ReplaceAll(c.Message, "\n", "\n ")) - } + for _, c := range conditions { + if c.Status != metav1.ConditionTrue { + fmt.Fprintf(o.Out, "%s=%s:\n\n Reason: %s\n Message: %s\n\n", c.Type, c.Status, c.Reason, strings.ReplaceAll(c.Message, "\n", "\n ")) } } }