Skip to content
Open
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
6 changes: 1 addition & 5 deletions pkg/cli/admin/upgrade/recommend/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion pkg/cli/admin/upgrade/recommend/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions pkg/cli/admin/upgrade/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since there is already

func isHostedCluster(i *configv1.Infrastructure) bool {
	return i != nil && i.Status.ControlPlaneTopology == configv1.ExternalTopologyMode
}

in alerts.go, can we put that helper into a shared package and use that wherever necessary?

}

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)
Expand Down Expand Up @@ -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 ""
Expand Down