Skip to content
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

Closed

Conversation

fbm3307
Copy link
Contributor

@fbm3307 fbm3307 commented Mar 14, 2024

This is a Follow-up PR for #359,

Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Merging #372 (ff9924f) into master (c7a4744) will decrease coverage by 0.54%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #372      +/-   ##
==========================================
- Coverage   75.99%   75.46%   -0.54%     
==========================================
  Files          44       44              
  Lines        1683     1683              
==========================================
- Hits         1279     1270       -9     
- Misses        353      362       +9     
  Partials       51       51              
Files Coverage Δ
pkg/cluster/cache.go 82.35% <100.00%> (-17.65%) ⬇️
pkg/cluster/service.go 83.46% <100.00%> (ø)
pkg/status/toolchaincluster.go 88.46% <ø> (ø)

Comment on lines 124 to 126
// 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't forget to remove the GetHostCluster, GetMemberClusters, and the related functions and types - they shouldn't be used anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I see that you wrote

Keeping the GetHostCluster() and GetMemberClusters() for now and delete them once their dependencies are removed in host, member, registration-service .

but let's delete it right away in this PR, so we are sure that we didn't miss any usage anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted it

if !ok {
toolchainClusters := attrs.GetClustersFunc()

if len(toolchainClusters) != 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 🙃

GetClusterFunc func() (*cluster.CachedToolchainCluster, bool)
Period time.Duration
Timeout time.Duration
GetClustersFunc cluster.GetClustersFunc
Copy link
Contributor

@MatousJobanek MatousJobanek Mar 15, 2024

Choose a reason for hiding this comment

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

the purpose and the usage of the ToolchainClusterAttributes type and GetToolchainClusterConditions function doesn't match with the cluster.GetClustersFunc - this is intended to be used for one ToolchainCluster, but for many. I saw that you used

toolchainCluster := toolchainClusters[0]

to get the first one, but you never know if you are supposed to use the first one, second, or third.
I would rather either keep the

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 *cluster.CachedToolchainCluster directly

var Clusters GetClustersFunc = GetClusters

// GetClusters returns the kube clients for all the clusters from the cache of the clusters
func GetClusters(conditions ...Condition) []*CachedToolchainCluster {
Copy link
Contributor

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:

  • GetToolchainClusters
  • GetCachedToolchainClusters

so it's clear which clusters we are talking about

Copy link
Contributor Author

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 to GetToolchainClustersCachedFunc

Signed-off-by: Feny Mehta <[email protected]>
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@fbm3307
Copy link
Contributor Author

fbm3307 commented Mar 19, 2024

Closing this PR as Adding the Common Getcluster Func is not required now

@fbm3307 fbm3307 closed this Mar 19, 2024
@fbm3307 fbm3307 deleted the ks20drptcrtype-2follow branch March 19, 2024 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants