Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Release URL:
Reason: TestAlert
Message: Test alert for updates. https://github.com/openshift/runbooks/tree/master/alerts?runbook=notfound

error: There are issues that apply to this cluster and have not been accepted. `oc adm upgrade accept` can be used to accept them: ConditionalUpdateRisk
error: There are issues that apply to this cluster and have not been accepted. `oc adm upgrade accept` can be used to accept them: TestAlert

42 changes: 33 additions & 9 deletions pkg/cli/admin/upgrade/recommend/recommend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/kubectl/pkg/util/templates"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
configv1client "github.com/openshift/client-go/config/clientset/versioned"
)

Expand Down Expand Up @@ -139,7 +140,7 @@ func (o *options) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string

func (o *options) Run(ctx context.Context) error {
issues := sets.New[string]()
accept := sets.New[string](o.accept...)
accept := sets.New[string]()

var cv *configv1.ClusterVersion
if cv = o.mockData.clusterVersion; cv == nil {
Expand All @@ -153,6 +154,31 @@ func (o *options) Run(ctx context.Context) error {
}
}

cvoChecking, err := o.alertsEvaluatedByCVO(ctx)
if err != nil {
return fmt.Errorf("failed to determine if the Cluster Version Operator is checking alerts: %w", err)
}
if cvoChecking && len(o.accept) > 0 {
return fmt.Errorf("`oc adm upgrade accept` is used to accept when the feature gate %s is enabled", features.FeatureGateClusterUpdateAcceptRisks)
}

if cvoChecking {
for _, risk := range cv.Status.ConditionalUpdateRisks {
for _, condition := range risk.Conditions {
if condition.Type == "Applies" && condition.Status != metav1.ConditionFalse {
issues.Insert(risk.Name)
}
}
Comment on lines +166 to +171

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu
file="pkg/cli/admin/upgrade/recommend/recommend.go"
printf '%s\n' '--- imports and target logic ---'
sed -n '1,210p' "$file"
printf '%s\n' '--- requested-update blocking logic ---'
sed -n '330,390p' "$file"
printf '%s\n' '--- related condition handling and tests ---'
rg -n -C 4 'ConditionalUpdateRisks|FindStatusCondition|issues|Applies' --glob '*.go' .

Repository: openshift/oc

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -eu
file="pkg/cli/admin/upgrade/recommend/recommend.go"
printf '%s\n' '--- target source ---'
sed -n '1,190p' "$file"
printf '%s\n' '--- blocking source ---'
sed -n '340,380p' "$file"
printf '%s\n' '--- repository references, excluding vendor ---'
rg -n -C 5 'ConditionalUpdateRisks|FindStatusCondition|issues|Applies' --glob '*.go' --glob '!vendor/**' --glob '!**/*_generated.go' .
printf '%s\n' '--- FindStatusCondition implementation ---'
rg -n -C 8 'func FindStatusCondition' vendor/k8s.io/apimachinery

Repository: openshift/oc

Length of output: 50368


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- exact FindStatusCondition implementation ---'
rg -n -C 12 '^func FindStatusCondition' vendor/k8s.io/apimachinery/pkg/api/meta
printf '%s\n' '--- ConditionalUpdateRisk API definitions and documentation ---'
rg -n -C 10 'ConditionalUpdateRisk|ConditionalUpdateRisks|AcceptRisks' vendor/github.com/openshift/api/config
printf '%s\n' '--- recommend package tests and fixtures ---'
find pkg/cli/admin/upgrade/recommend -maxdepth 2 -type f -print
rg -n -C 8 'ConditionalUpdateRisks|Applies|accept|unaccepted' pkg/cli/admin/upgrade/recommend --glob '*_test.go' --glob '*.yaml' --glob '*.json' || true
printf '%s\n' '--- standalone condition-selection probe ---'
python3 - <<'PY'
from pathlib import Path
source = Path("vendor/k8s.io/apimachinery/pkg/api/meta/meta.go").read_text()
start = source.index("func FindStatusCondition")
end = source.find("\n}", start) + 2
print(source[start:end])
PY

Repository: openshift/oc

Length of output: 50368


Add only risks with Applies=True.

meta.FindStatusCondition matches the condition type without checking its status. Check c.Status == metav1.ConditionTrue before inserting the risk, or False and Unknown risks can block the requested update.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/cli/admin/upgrade/recommend/recommend.go` around lines 167 - 170, Update
the ConditionalUpdateRisks loop in the recommendation logic to insert a risk
only when the “Applies” condition exists and its Status equals
metav1.ConditionTrue. Preserve the existing risk.Name insertion and exclude
False or Unknown conditions.

}
if cv.Spec.DesiredUpdate != nil {
for _, risk := range cv.Spec.DesiredUpdate.AcceptRisks {
accept.Insert(risk.Name)
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} else {
accept = accept.Insert(o.accept...)
}

if c := findClusterOperatorStatusCondition(cv.Status.Conditions, clusterStatusFailing); c != nil {
if c.Status != configv1.ConditionFalse {
acceptContext := ""
Expand Down Expand Up @@ -329,23 +355,21 @@ func (o *options) Run(ctx context.Context) error {
} else {
if !o.quiet {
reason := c.Reason
if accept.Has("ConditionalUpdateRisk") {
if !cvoChecking && accept.Has("ConditionalUpdateRisk") {
reason = fmt.Sprintf("accepted %s via ConditionalUpdateRisk", c.Reason)
}
fmt.Fprintf(o.Out, "Update to %s %s=%s:\nImage: %s\nRelease URL: %s\nReason: %s\nMessage: %s\n", update.Release.Version, c.Type, c.Status, update.Release.Image, update.Release.URL, reason, strings.ReplaceAll(c.Message, "\n", "\n "))
}
issues.Insert("ConditionalUpdateRisk")
if !cvoChecking {
issues.Insert("ConditionalUpdateRisk")
}
}
unaccepted := issues.Difference(accept)
if unaccepted.Len() > 0 {
if cvoChecking, err := o.alertsEvaluatedByCVO(ctx); cvoChecking {
if err != nil {
return fmt.Errorf("failed to determine if CVO is checking alerts: %v", err)
}
if cvoChecking {
return fmt.Errorf("There are issues that apply to this cluster and have not been accepted. `oc adm upgrade accept` can be used to accept them: %s\n", strings.Join(sets.List(unaccepted), ","))
} else {
return fmt.Errorf("issues that apply to this cluster but which were not included in --accept: %s", strings.Join(sets.List(unaccepted), ","))
}
return fmt.Errorf("issues that apply to this cluster but which were not included in --accept: %s", strings.Join(sets.List(unaccepted), ","))
} else if issues.Len() > 0 && !o.quiet {
fmt.Fprintf(o.Out, "Update to %s has no known issues relevant to this cluster other than the accepted %s.\n", update.Release.Version, strings.Join(sets.List(issues), ","))
}
Expand Down