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
60 changes: 60 additions & 0 deletions pkg/cli/admin/upgrade/recommend/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"fmt"
"strings"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
routev1 "github.com/openshift/api/route/v1"
routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"

"github.com/openshift/oc/pkg/cli/admin/inspectalerts"
"github.com/openshift/oc/pkg/cli/admin/upgrade/status"
Expand All @@ -20,6 +23,12 @@ import (
// and Unknown when we do not have enough information to make a
// happy-or-sad determination.
func (o *options) alerts(ctx context.Context) ([]acceptableCondition, error) {
if skip, err := o.alertsEvaluatedByCVO(ctx); err != nil {
klog.Warningf("An error occured while determining if the CVO is evaluating alerts, so the client will check. %v", err)
} else if skip {
return nil, nil
Comment on lines +26 to +29

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the warning typo.

“occured” should be “occurred.”

🤖 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/alerts.go` around lines 26 - 29, Correct the
spelling in the warning message within the alertsEvaluatedByCVO call handling,
changing “occured” to “occurred” without altering the surrounding control flow
or logging behavior.

}

var alertsBytes []byte
if o.mockData.alertsPath != "" {
if len(o.mockData.alerts) == 0 {
Expand Down Expand Up @@ -251,3 +260,54 @@ func (o *options) alerts(ctx context.Context) ([]acceptableCondition, error) {

return conditions, nil
}

// alertsEvaluatedByCVO makes API calls to determine if we need to do client-side alert checking
func (o *options) alertsEvaluatedByCVO(ctx context.Context) (bool, error) {
featureGates := o.mockData.featureGate
infrastructure := o.mockData.infrastructure
cv := o.mockData.clusterVersion
if cv == nil {
var err error
featureGates, err = o.Client.ConfigV1().FeatureGates().Get(ctx, "cluster", metav1.GetOptions{})
if err != nil {
return false, err
}

infrastructure, err = o.Client.ConfigV1().Infrastructures().Get(ctx, "cluster", metav1.GetOptions{})
if err != nil {
return false, err
}

cv, err = o.Client.ConfigV1().ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
if err != nil {
return false, err
}
}

// if the AcceptRisks feature gate is enabled AND oc is not running against a hosted cluster,
// the CVO is handling alerts and will generate the Recommended condition if needed
return isAcceptRisksEnabled(featureGates, cv.Status.Desired.Version) && !isHostedCluster(infrastructure), nil
}

// isAcceptRisksEnabled checks to see if the 'ClusterUpdateAcceptRisks' feature gate is enabled
// if so, return true to skip client-side alert checking
func isAcceptRisksEnabled(featureGate *configv1.FeatureGate, clusterVersion string) bool {
if featureGate == nil {
return false
}

for _, versionedGates := range featureGate.Status.FeatureGates {
if versionedGates.Version == clusterVersion {
for _, enabledGate := range versionedGates.Enabled {
if enabledGate.Name == features.FeatureGateClusterUpdateAcceptRisks {
return true
}
}
}
}
return false
}

func isHostedCluster(i *configv1.Infrastructure) bool {
return i != nil && i.Status.ControlPlaneTopology == configv1.ExternalTopologyMode
}
132 changes: 132 additions & 0 deletions pkg/cli/admin/upgrade/recommend/alerts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package recommend

import (
"testing"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
)

func TestIsAcceptRisksEnabled(t *testing.T) {

for _, testCase := range []struct {
name string
featureGateConfig *configv1.FeatureGate
expected bool
}{
{
name: "no feature gates",
},
{
name: "ClusterUpdateAcceptRisks feature gate is enabled",
featureGateConfig: &configv1.FeatureGate{
Status: configv1.FeatureGateStatus{
FeatureGates: []configv1.FeatureGateDetails{
{
Version: "4.22.0",
Enabled: []configv1.FeatureGateAttributes{
{
Name: features.FeatureGateClusterUpdateAcceptRisks,
},
},
},
},
},
},
expected: true,
},
{
name: "ClusterUpdateAcceptRisks feature gate is explicitly disabled",
featureGateConfig: &configv1.FeatureGate{
Status: configv1.FeatureGateStatus{
FeatureGates: []configv1.FeatureGateDetails{
{
Version: "4.22.0",
Disabled: []configv1.FeatureGateAttributes{
{
Name: features.FeatureGateClusterUpdateAcceptRisks,
},
},
},
},
},
},
},
{
name: "ClusterUpdateAcceptRisks feature gate is not explicitly enabled or disabled",
featureGateConfig: &configv1.FeatureGate{
Status: configv1.FeatureGateStatus{
FeatureGates: []configv1.FeatureGateDetails{
{
Version: "4.22.0",
Enabled: []configv1.FeatureGateAttributes{},
Disabled: []configv1.FeatureGateAttributes{},
},
},
},
},
},
{
name: "ClusterUpdateAcceptRisks feature gate is enabled for a different cluster version",
featureGateConfig: &configv1.FeatureGate{
Status: configv1.FeatureGateStatus{
FeatureGates: []configv1.FeatureGateDetails{
{
Version: "4.21.0",
Enabled: []configv1.FeatureGateAttributes{
{
Name: features.FeatureGateClusterUpdateAcceptRisks,
},
},
},
},
},
},
},
} {
t.Run(testCase.name, func(t *testing.T) {
actual := isAcceptRisksEnabled(testCase.featureGateConfig, "4.22.0")

if actual != testCase.expected {
t.Errorf("%v != %v", actual, testCase.expected)
}
})
}
}

func TestIsHypershiftEnabled(t *testing.T) {
for _, testCase := range []struct {
name string
infrastructure *configv1.Infrastructure
expected bool
}{
{
name: "no infrastructure",
},
{
name: "hypershift enabled",
infrastructure: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
ControlPlaneTopology: configv1.ExternalTopologyMode,
},
},
expected: true,
},
{
name: "hypershift not enabled",
infrastructure: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
ControlPlaneTopology: configv1.HighlyAvailableTopologyMode,
},
},
},
} {
t.Run(testCase.name, func(t *testing.T) {
actual := isHostedCluster(testCase.infrastructure)

if actual != testCase.expected {
t.Errorf("%v != %v", actual, testCase.expected)
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"status": "success",
"data": {
"alerts": [
{
"labels": {
"alertname": "ClusterNotUpgradeable",
"condition": "Upgradeable",
"endpoint": "metrics",
"name": "version",
"namespace": "openshift-cluster-version",
"severity": "info"
},
"annotations": {
"description": "In most cases, you will still be able to apply patch releases. Reason MultipleReasons. For more information refer to 'oc adm upgrade' or https://console-openshift-console.apps.ci-ln-h13idik-72292.gcp-2.ci.openshift.org/settings/cluster/.",
"summary": "One or more cluster operators have been blocking minor or major version cluster updates for at least an hour."
},
"state": "firing",
"activeAt": "2026-07-13T18:15:08.114207953Z",
"value": "0e+00",
"partialResponseStrategy": "WARN"
},
{
"labels": {
"alertname": "OpenShiftUpdateRiskMightApply",
"namespace": "openshift-cluster-version",
"reason": "Alert:firing",
"risk": "TestAlert",
"severity": "warning"
},
"annotations": {
"description": "The conditional update risk TestAlert might apply to the cluster because of Alert:firing, and the cluster update to a version exposed to the risk is not recommended. For more information refer to 'oc adm upgrade'.",
"runbook_url": "https://github.com/openshift/runbooks/blob/master/alerts/cluster-version-operator/OpenShiftUpdateRiskMightApply.md",
"summary": "The cluster might have been exposed to the conditional update risk for 15 minutes."
},
"state": "pending",
"activeAt": "2026-07-13T20:02:36.835802807Z",
"value": "1e+00",
"partialResponseStrategy": "WARN"
},
{
"labels": {
"alertname": "InsightsRecommendationActive",
"container": "insights-operator",
"description": "Enabling the **TechPreviewNoUpgrade** feature set on your cluster\ncan not be undone and prevents minor version updates. Please do\nnot enable this feature set on production clusters.\n",
"endpoint": "https",
"info_link": "https://console.redhat.com/openshift/insights/advisor/clusters/82c88454-3cfc-4233-8e10-34f5c3ff67c0?first=ccx_rules_ocp.external.rules.upgrade_is_blocked_due_to_tpfg%7CTECH_PREVIEW_NO_UPGRADE_FEATURE_SET_IS_ENABLED",
"instance": "10.130.0.27:8443",
"job": "metrics",
"namespace": "openshift-insights",
"pod": "insights-operator-584747df49-5x462",
"service": "metrics",
"severity": "info",
"total_risk": "Important"
},
"annotations": {
"description": "Insights recommendation \"Enabling the **TechPreviewNoUpgrade** feature set on your cluster\ncan not be undone and prevents minor version updates. Please do\nnot enable this feature set on production clusters.\n\" with total risk \"Important\" was detected on the cluster. More information is available at https://console.redhat.com/openshift/insights/advisor/clusters/82c88454-3cfc-4233-8e10-34f5c3ff67c0?first=ccx_rules_ocp.external.rules.upgrade_is_blocked_due_to_tpfg%7CTECH_PREVIEW_NO_UPGRADE_FEATURE_SET_IS_ENABLED.",
"summary": "An Insights recommendation is active for this cluster."
},
"state": "firing",
"activeAt": "2026-07-13T18:17:18.129623987Z",
"value": "1e+00",
"partialResponseStrategy": "WARN"
},
{
"labels": {
"alertname": "TechPreviewNoUpgrade",
"container": "kube-apiserver-operator",
"endpoint": "https",
"instance": "10.130.0.42:8443",
"job": "kube-apiserver-operator",
"name": "TechPreviewNoUpgrade",
"namespace": "openshift-kube-apiserver-operator",
"pod": "kube-apiserver-operator-7d998989dd-gscdp",
"service": "metrics",
"severity": "warning"
},
"annotations": {
"description": "Cluster has enabled Technology Preview features that cannot be undone and will prevent upgrades. The TechPreviewNoUpgrade feature set is not recommended on production clusters.",
"summary": "Cluster has enabled tech preview features that will prevent upgrades."
},
"state": "firing",
"activeAt": "2026-07-13T18:17:52.119686422Z",
"value": "0e+00",
"partialResponseStrategy": "WARN"
},
{
"labels": {
"alertname": "Watchdog",
"namespace": "openshift-monitoring",
"severity": "none"
},
"annotations": {
"description": "This is an alert meant to ensure that the entire alerting pipeline is functional.\nThis alert is always firing, therefore it should always be firing in Alertmanager\nand always fire against a receiver. There are integrations with various notification\nmechanisms that send a notification when this alert is not firing. For example the\n\"DeadMansSnitch\" integration in PagerDuty.\n",
"summary": "An alert that should always be firing to certify that Alertmanager is working properly."
},
"state": "firing",
"activeAt": "2026-07-13T18:14:54.631104668Z",
"value": "1e+00",
"partialResponseStrategy": "WARN"
},
{
"labels": {
"alertname": "TargetDown",
"job": "check-endpoints",
"namespace": "openshift-apiserver",
"service": "check-endpoints",
"severity": "warning"
},
"annotations": {
"description": "100% of the check-endpoints/check-endpoints targets in openshift-apiserver namespace have been unreachable for more than 15 minutes. This may be a symptom of network connectivity issues, down nodes, or failures within these components. Assess the health of the infrastructure and nodes running these targets and then contact support.",
"runbook_url": "https://github.com/openshift/runbooks/blob/master/alerts/cluster-monitoring-operator/TargetDown.md",
"summary": "Some targets were not reachable from the monitoring server for an extended period of time."
},
"state": "firing",
"activeAt": "2026-07-13T18:15:42.660370292Z",
"value": "1e+02",
"partialResponseStrategy": "WARN"
},
{
"labels": {
"alertname": "AlertmanagerReceiversNotConfigured",
"namespace": "openshift-monitoring",
"severity": "warning"
},
"annotations": {
"description": "Alerts are not configured to be sent to a notification system, meaning that you may not be notified in a timely fashion when important failures occur. Check the OpenShift documentation to learn how to configure notifications with Alertmanager.",
"summary": "Receivers (notification integrations) are not configured on Alertmanager"
},
"state": "firing",
"activeAt": "2026-07-13T18:17:24.167429387Z",
"value": "0e+00",
"partialResponseStrategy": "WARN"
},
{
"labels": {
"alertname": "TestAlert",
"openShiftUpdatePrecheck": "true",
"severity": "warning"
},
"annotations": {
"description": "Test alert for updates",
"summary": "Test alert for updates"
},
"state": "firing",
"activeAt": "2026-07-13T19:05:17.879901206Z",
"value": "1e+00",
"partialResponseStrategy": "WARN"
}
]
}
}
Loading