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

Clusters Client #1814

Merged
merged 20 commits into from
Mar 30, 2022
Merged

Clusters Client #1814

merged 20 commits into from
Mar 30, 2022

Conversation

luizbafilho
Copy link
Contributor

@luizbafilho luizbafilho commented Mar 28, 2022

Closes: #1777

What changed?
Introduces the Clusters Client, this is an abstraction to help make calls to all the clusters. It is a thin wrapper around the controller-runtime/client that handles the connections to the clusters and when contacting them does it in parallel.

Why?

  • Simplify resources updates and listing

How did you test it?

  • automated and manual tests

Release notes

Documentation Changes

@luizbafilho luizbafilho added the type/enhancement New feature or request label Mar 28, 2022
@luizbafilho luizbafilho changed the title Initial impl Clusters Client Mar 29, 2022
@luizbafilho luizbafilho marked this pull request as ready for review March 29, 2022 18:01
Copy link
Contributor

@jpellizzari jpellizzari left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Callisto13 Callisto13 left a comment

Choose a reason for hiding this comment

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

like this a lot! great work! just a couple of questions/requests

Comment on lines +92 to +94
if len(errs) > 0 {
return fmt.Errorf("failed to list resources: %s", errs)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify: if one of these Lists fails we will return the whole thing as a failure? Is this what we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made myself the same question, and I don't think the end goal would be this, but we need to coordinate with the UI to settle down the best way to handle this "partial success" response.

)

var (
ErrClusterNotFound error = errors.New("cluster not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we turn this into an error type that lets us pass in the cluster name? might be useful for debugging

@@ -157,7 +157,7 @@ func TestBuildConfigWithOptions(t *testing.T) {
}

var (
rfc3339Regexp = `^((\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[\+-]\d{2}:\d{2})$`
rfc3339Regexp = `^((\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[\+-]\d{2}:?\d{2})$`
Copy link
Contributor

Choose a reason for hiding this comment

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

i think balazs fixed this in his last pr, check on main?

Copy link
Contributor Author

@luizbafilho luizbafilho Mar 30, 2022

Choose a reason for hiding this comment

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

just pulled from main

Copy link
Contributor

@yitsushi yitsushi left a comment

Choose a reason for hiding this comment

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

:shipit: :shipit: :shipit: :shipit: :shipit:

}

func (c *clustersClient) Get(ctx context.Context, cluster string, key client.ObjectKey, obj client.Object) error {
client := c.pool.Clients()[cluster]
Copy link
Contributor

@yitsushi yitsushi Mar 30, 2022

Choose a reason for hiding this comment

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

that c.pool.Clients()[cluster] hurts my eyes a bit, totally personal taste. I know it does not fail, but my brain constantly says "it should fail if the key is not defined".

func (cp *clientsPool) Client(name string) (client.Client, error) {
  if c, found := cp.clients[name]; found && c != nil {
    return c, nil
  }

  return ClusterNotFoundError{Cluster: name}
}

client, err := c.pool.Client(cluster)
if err != nil {
  return err
}

Not a blocker at all. That's only extra sugar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, much better, pushing the change

@luizbafilho luizbafilho requested a review from Callisto13 March 30, 2022 13:34
@luizbafilho luizbafilho merged commit f3bf418 into main Mar 30, 2022
@luizbafilho luizbafilho deleted the 1777-single-cluster-client branch March 30, 2022 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle Failures and Parallelization of calls to the Clusters
4 participants