diff --git a/pkg/cli/admin/upgrade/recommend/alerts.go b/pkg/cli/admin/upgrade/recommend/alerts.go index f6612f48eb..d51c34a39a 100644 --- a/pkg/cli/admin/upgrade/recommend/alerts.go +++ b/pkg/cli/admin/upgrade/recommend/alerts.go @@ -286,7 +286,7 @@ func (o *options) alertsEvaluatedByCVO(ctx context.Context) (bool, error) { // 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 + return isAcceptRisksEnabled(featureGates, cv.Status.Desired.Version) && !status.IsHostedCluster(infrastructure), nil } // isAcceptRisksEnabled checks to see if the 'ClusterUpdateAcceptRisks' feature gate is enabled @@ -307,7 +307,3 @@ func isAcceptRisksEnabled(featureGate *configv1.FeatureGate, clusterVersion stri } return false } - -func isHostedCluster(i *configv1.Infrastructure) bool { - return i != nil && i.Status.ControlPlaneTopology == configv1.ExternalTopologyMode -} diff --git a/pkg/cli/admin/upgrade/recommend/alerts_test.go b/pkg/cli/admin/upgrade/recommend/alerts_test.go index 6566e9710d..95dd04ed16 100644 --- a/pkg/cli/admin/upgrade/recommend/alerts_test.go +++ b/pkg/cli/admin/upgrade/recommend/alerts_test.go @@ -5,6 +5,7 @@ import ( configv1 "github.com/openshift/api/config/v1" "github.com/openshift/api/features" + "github.com/openshift/oc/pkg/cli/admin/upgrade/status" ) func TestIsAcceptRisksEnabled(t *testing.T) { @@ -122,7 +123,7 @@ func TestIsHypershiftEnabled(t *testing.T) { }, } { t.Run(testCase.name, func(t *testing.T) { - actual := isHostedCluster(testCase.infrastructure) + actual := status.IsHostedCluster(testCase.infrastructure) if actual != testCase.expected { t.Errorf("%v != %v", actual, testCase.expected) diff --git a/pkg/cli/admin/upgrade/status/status.go b/pkg/cli/admin/upgrade/status/status.go index 26f5be1be5..3f34b7fe5b 100644 --- a/pkg/cli/admin/upgrade/status/status.go +++ b/pkg/cli/admin/upgrade/status/status.go @@ -207,6 +207,16 @@ func (o *options) Run(ctx context.Context) error { return fmt.Errorf("no cluster operator information available - you must be connected to an OpenShift version 4 server") } + if o.mockData.cvPath == "" { + infra, err := o.ConfigClient.ConfigV1().Infrastructures().Get(ctx, "cluster", metav1.GetOptions{}) + if err != nil { + return fmt.Errorf("failed to get cluster infrastructure: %w", err) + } + if IsHostedCluster(infra) { + return fmt.Errorf("upgrade status is not supported on Hosted Control Plane (HyperShift) clusters") + } + } + progressing := findClusterOperatorStatusCondition(cv.Status.Conditions, configv1.OperatorProgressing) if progressing == nil { return fmt.Errorf("no current %s info, see `oc describe clusterversion` for more details.\n", configv1.OperatorProgressing) @@ -384,6 +394,11 @@ func findClusterOperatorStatusCondition(conditions []configv1.ClusterOperatorSta return nil } +// IsHostedCluster returns true if the cluster is a Hosted Control Plane (HyperShift) cluster. +func IsHostedCluster(i *configv1.Infrastructure) bool { + return i != nil && i.Status.ControlPlaneTopology == configv1.ExternalTopologyMode +} + func getMCOImagePullSpec(deployment *appsv1.Deployment) string { if deployment == nil { return ""