-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KSPACE-43: Adding common GetClusters func #372
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,24 @@ func GetCachedToolchainCluster(name string) (*CachedToolchainCluster, bool) { | |
return clusterCache.getCachedToolchainCluster(name, true) | ||
} | ||
|
||
// GetClustersFunc a func that returns all the clusters from the cache | ||
type GetClustersFunc func(conditions ...Condition) []*CachedToolchainCluster | ||
|
||
// Clusters the func to retrieve all the clusters | ||
var Clusters GetClustersFunc = GetClusters | ||
|
||
// GetClusters returns the kube clients for all the clusters from the cache of the clusters | ||
func GetClusters(conditions ...Condition) []*CachedToolchainCluster { | ||
clusters := clusterCache.getCachedToolchainClusters(conditions...) | ||
if len(clusters) == 0 { | ||
if clusterCache.refreshCache != nil { | ||
clusterCache.refreshCache() | ||
} | ||
clusters = clusterCache.getCachedToolchainClusters(conditions...) | ||
} | ||
return clusters | ||
} | ||
|
||
// GetHostClusterFunc a func that returns the Host cluster from the cache, | ||
// along with a bool to indicate if there was a match or not | ||
type GetHostClusterFunc func() (*CachedToolchainCluster, bool) | ||
Comment on lines
124
to
126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't forget to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I see that you wrote
but let's delete it right away in this PR, so we are sure that we didn't miss any usage anywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleted it |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,18 +19,20 @@ const ( | |
|
||
// ToolchainClusterAttributes required attributes for obtaining ToolchainCluster status | ||
type ToolchainClusterAttributes struct { | ||
GetClusterFunc func() (*cluster.CachedToolchainCluster, bool) | ||
Period time.Duration | ||
Timeout time.Duration | ||
GetClustersFunc cluster.GetClustersFunc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the purpose and the usage of the toolchainCluster := toolchainClusters[0] to get the first one, but you never know if you are supposed to use the first one, second, or third. GetClusterFunc func() (*cluster.CachedToolchainCluster, bool) in the same format is it was before and let the caller to pass the ToolchainCluster - something like this: attributes := status.ToolchainClusterAttributes{
GetClusterFunc: func() (*cluster.CachedToolchainCluster, bool) {
clusters := cluster.GetClustersFunc()
if len(clusters) != 0 {
return clusters[0], true
}
return nil, false
}, or just change the field so it doesn't take a func but rather a |
||
Period time.Duration | ||
Timeout time.Duration | ||
} | ||
|
||
// GetToolchainClusterConditions uses the provided ToolchainCluster attributes to determine status conditions | ||
func GetToolchainClusterConditions(logger logr.Logger, attrs ToolchainClusterAttributes) []toolchainv1alpha1.Condition { | ||
// look up cluster connection status | ||
toolchainCluster, ok := attrs.GetClusterFunc() | ||
if !ok { | ||
toolchainClusters := attrs.GetClustersFunc() | ||
|
||
if len(toolchainClusters) != 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. originally, there was: if !ok { which is not then same as if len(toolchainClusters) != 1 { when there can be 0...n results 🙃 |
||
return []toolchainv1alpha1.Condition{*NewComponentErrorCondition(toolchainv1alpha1.ToolchainStatusClusterConnectionNotFoundReason, ErrMsgClusterConnectionNotFound)} | ||
} | ||
toolchainCluster := toolchainClusters[0] | ||
|
||
// check conditions of cluster connection | ||
if !cluster.IsReady(toolchainCluster.ClusterStatus) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more thing,
GetClusters
is pretty generic and can be confusing. How about:so it's clear which clusters we are talking about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a function named as
GetCachedToolchainClusters
, but to avoid confusion and for better understanding updating it toGetToolchainClustersCachedFunc