Repository: clusternet/clusternet
Pull request #743 (2023-10-09 09:32:57)

ready clusters should have conditions
<!--  Thanks for sending a pull request!

-->

#### What type of PR is this?
kind/bug

#### What this PR does / why we need it:

#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #

#### Special notes for your reviewer:


codecov-commenter: ## [Codecov](https://app.codecov.io/gh/clusternet/clusternet/pull/743?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clusternet) Report
All modified lines are covered by tests :white_check_mark:
> Comparison is base [(`e2ffa5f`)](https://app.codecov.io/gh/clusternet/clusternet/commit/e2ffa5fa54a7e81045fbef497d0dfd68a4bcc7f6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clusternet) 13.60% compared to head [(`556759d`)](https://app.codecov.io/gh/clusternet/clusternet/pull/743?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clusternet) 13.00%.
> Report is 108 commits behind head on main.

:exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #743      +/-   ##
==========================================
- Coverage   13.60%   13.00%   -0.60%     
==========================================
  Files          66       76      +10     
  Lines        7492     8720    +1228     
==========================================
+ Hits         1019     1134     +115     
- Misses       6391     7502    +1111     
- Partials       82       84       +2     
```


[see 51 files with indirect coverage changes](https://app.codecov.io/gh/clusternet/clusternet/pull/743/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clusternet)


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/clusternet/clusternet/pull/743?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clusternet).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clusternet).


Patch:
diff --git a/pkg/utils/deployer.go b/pkg/utils/deployer.go
index e2b3162..c2727a6 100644
--- a/pkg/utils/deployer.go
+++ b/pkg/utils/deployer.go
@@ -799,13 +799,19 @@ func IsClusterLost(clusterID, namespace string, clusterLister clusterlisters.Man
 		return true
 	}
 
+	// short-circuit
+	// in case the conditions are not updated yet
+	if len(mcls[0].Status.Conditions) == 0 {
+		return false
+	}
+
 	return !ClusterHasReadyCondition(mcls[0])
 }
 
 func ClusterHasReadyCondition(mc *clusterapi.ManagedCluster) bool {
 	// in case the conditions are not updated yet
 	if len(mc.Status.Conditions) == 0 {
-		return true
+		return false
 	}
 
 	for _, condition := range mc.Status.Conditions {


Test patch:
diff --git a/pkg/utils/deployer_test.go b/pkg/utils/deployer_test.go
index 5e6ca9a..e29f46e 100644
--- a/pkg/utils/deployer_test.go
+++ b/pkg/utils/deployer_test.go
@@ -250,7 +250,7 @@ func TestClusterHasReadyCondition(t *testing.T) {
 				ObjectMeta: metav1.ObjectMeta{},
 				Spec:       clusterapi.ManagedClusterSpec{},
 			},
-			clusterReady: true,
+			clusterReady: false,
 		},
 		{
 			mc: &clusterapi.ManagedCluster{