From 0f724a3911ea744b0c80d90010e303b28ae6b06d Mon Sep 17 00:00:00 2001 From: Martin Gencur Date: Mon, 17 Feb 2025 10:40:50 +0100 Subject: [PATCH 1/2] OCPBUGS-50907 Propagate Reason for Available condition from HCP to HC --- .../controllers/hostedcluster/hostedcluster_controller.go | 1 + 1 file changed, 1 insertion(+) diff --git a/hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go b/hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go index e4da867d2d..751dfde7a8 100644 --- a/hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go +++ b/hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go @@ -3751,6 +3751,7 @@ func computeHostedClusterAvailability(hcluster *hyperv1.HostedCluster, hcp *hype if hcpAvailableCondition != nil { hcpAvailableStatus = hcpAvailableCondition.Status hcpAvailableMessage = hcpAvailableCondition.Message + hcpAvailableReason = hcpAvailableCondition.Reason if hcpAvailableStatus == metav1.ConditionTrue { hcpAvailableReason = hyperv1.AsExpectedReason hcpAvailableMessage = "The hosted control plane is available" From ef2adfd87e6e04f950ccd61035353d5789fd73ce Mon Sep 17 00:00:00 2001 From: Martin Gencur Date: Mon, 17 Feb 2025 11:10:50 +0100 Subject: [PATCH 2/2] Unit test --- .../hostedcluster/hostedcluster_controller_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hypershift-operator/controllers/hostedcluster/hostedcluster_controller_test.go b/hypershift-operator/controllers/hostedcluster/hostedcluster_controller_test.go index 0d557a1ac5..6f5da996e5 100644 --- a/hypershift-operator/controllers/hostedcluster/hostedcluster_controller_test.go +++ b/hypershift-operator/controllers/hostedcluster/hostedcluster_controller_test.go @@ -323,6 +323,7 @@ func TestComputeHostedClusterAvailability(t *testing.T) { ExpectedCondition: metav1.Condition{ Type: string(hyperv1.HostedClusterAvailable), Status: metav1.ConditionFalse, + Reason: hyperv1.WaitingForAvailableReason, }, }, "hosted controlplane with availability false should cause unavailability": { @@ -336,13 +337,18 @@ func TestComputeHostedClusterAvailability(t *testing.T) { Spec: hyperv1.HostedControlPlaneSpec{ReleaseImage: "a"}, Status: hyperv1.HostedControlPlaneStatus{ Conditions: []metav1.Condition{ - {Type: string(hyperv1.HostedControlPlaneAvailable), Status: metav1.ConditionFalse}, + { + Type: string(hyperv1.HostedControlPlaneAvailable), + Status: metav1.ConditionFalse, + Reason: hyperv1.KASLoadBalancerNotReachableReason, + }, }, }, }, ExpectedCondition: metav1.Condition{ Type: string(hyperv1.HostedClusterAvailable), Status: metav1.ConditionFalse, + Reason: hyperv1.KASLoadBalancerNotReachableReason, }, }, "should be available": { @@ -366,6 +372,7 @@ func TestComputeHostedClusterAvailability(t *testing.T) { ExpectedCondition: metav1.Condition{ Type: string(hyperv1.HostedClusterAvailable), Status: metav1.ConditionTrue, + Reason: hyperv1.AsExpectedReason, }, }, } @@ -374,7 +381,6 @@ func TestComputeHostedClusterAvailability(t *testing.T) { actualCondition := computeHostedClusterAvailability(&test.Cluster, test.ControlPlane) // Clear fields irrelevant for diffing actualCondition.ObservedGeneration = 0 - actualCondition.Reason = "" actualCondition.Message = "" if !equality.Semantic.DeepEqual(test.ExpectedCondition, actualCondition) { t.Error(cmp.Diff(test.ExpectedCondition, actualCondition))