Add cluster helper functions for improved condition management #52
Add cluster helper functions for improved condition management #52yoursanonymous wants to merge 3 commits intovolcano-sh:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @yoursanonymous! It looks like this is your first PR to volcano-sh/volcano-global 🎉 |
Summary of ChangesHello @yoursanonymous, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors cluster condition checking by introducing helper functions GetClusterCondition and IsClusterReady, which improves code reuse and clarity. The changes are logical and well-tested. I've identified a few minor areas for improvement regarding code style and a small bug in one of the new tests.
pkg/utils/cluster_test.go
Outdated
| }, | ||
| }, | ||
| ready:false, | ||
| message: "Cluster <not-ready-cluster> is not ready, reason: NetworkUnavailable, message: Network is down", |
There was a problem hiding this comment.
The expected error message has a space between Cluster and <not-ready-cluster>, but the implementation in CheckClusterReady produces a message without this space (Cluster<not-ready-cluster>...). This will cause the test to fail. The expected message should be updated to match the actual output for consistency and to ensure the test passes.
| message: "Cluster <not-ready-cluster> is not ready, reason: NetworkUnavailable, message: Network is down", | |
| message: "Cluster<not-ready-cluster> is not ready, reason: NetworkUnavailable, message: Network is down", |
pkg/utils/cluster.go
Outdated
| } | ||
|
|
||
| func IsClusterReady(cluster *clusterv1alpha1.Cluster) bool { | ||
| condition:=GetClusterCondition(cluster, string(clusterv1alpha1.ClusterConditionReady)) |
There was a problem hiding this comment.
The explicit type conversion string(clusterv1alpha1.ClusterConditionReady) is redundant. The type clusterv1alpha1.ClusterConditionType is an alias for string, so it can be used directly where a string is expected. Removing the conversion makes the code slightly cleaner and more idiomatic.
| condition:=GetClusterCondition(cluster, string(clusterv1alpha1.ClusterConditionReady)) | |
| condition:=GetClusterCondition(cluster, clusterv1alpha1.ClusterConditionReady) |
pkg/utils/cluster.go
Outdated
| } | ||
|
|
||
| func CheckClusterReady(cluster *clusterv1alpha1.Cluster) (bool, string) { | ||
| condition:=GetClusterCondition(cluster, string(clusterv1alpha1.ClusterConditionReady)) |
There was a problem hiding this comment.
Similar to the comment on IsClusterReady, the explicit type conversion string(clusterv1alpha1.ClusterConditionReady) is redundant here as well and can be removed for better readability.
| condition:=GetClusterCondition(cluster, string(clusterv1alpha1.ClusterConditionReady)) | |
| condition:=GetClusterCondition(cluster, clusterv1alpha1.ClusterConditionReady) |
pkg/utils/cluster_test.go
Outdated
| ) | ||
|
|
||
| func TestGetClusterCondition(t *testing.T) { | ||
| readyType := string(clusterv1alpha1.ClusterConditionReady) |
There was a problem hiding this comment.
The explicit type conversion to string is not necessary here. clusterv1alpha1.ClusterConditionReady can be used directly. This also makes it consistent with how readyType is defined in TestIsClusterReady and TestCheckClusterReady within this same file.
| readyType := string(clusterv1alpha1.ClusterConditionReady) | |
| readyType := clusterv1alpha1.ClusterConditionReady |
Signed-off-by: vinayak sharma <vinayaks0111@gmail.com>
|
@JesseStutler , Can you please review this pull request. |
This PR adds reusable helper functions to pkg/utils/cluster.go to simplify cluster condition checks and reduce code duplication.