-
Notifications
You must be signed in to change notification settings - Fork 60
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
e2e: refactor cluster setup in env #1941
base: main
Are you sure you want to change the base?
Conversation
@parikshithb do we an issue for this? if not create an link it here. |
This change improves structure and reduces code duplication for c1 and c2 by refactoring the New function in env by adding separate helper functions: - `setupHub` to initialize the hub cluster. - `setupManagedClusters` to initialize managed clusters (c1 and c2). Signed-off-by: Parikshith <[email protected]>
52dfc34
to
6daf3f9
Compare
env.Hub.Name = defaultHubClusterName | ||
log.Infof("Cluster \"hub\" name not set, using default name %q", defaultHubClusterName) | ||
if err := setupHub(&env.Hub, config.Clusters["hub"], defaultHubClusterName, log); err != nil { | ||
return nil, fmt.Errorf("failed to setup hub cluster \"hub\": %w", err) |
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.
Can we create the error inside setupHub? It has the context we add here. The context this function can add is "failed to create env".
If we add the context in setupXXX functions, we don't need to repeat it here like we do for the managed clusters.
|
||
func setupHub( | ||
cluster *types.Cluster, clusterConfig types.ClusterConfig, | ||
defaultName string, log *zap.SugaredLogger, |
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.
If we cannot fit the arguments in one line, use one line per argument. Your editor probably provide this formatting option.
if err != nil { | ||
return nil, fmt.Errorf("failed to create clients for c1 cluster: %w", err) | ||
return fmt.Errorf("failed to create client for hub cluster: %w", err) |
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.
This error can come from setupClient, here can can the context of this function ("failed to setup hub").
} | ||
|
||
env.C1.Kubeconfig = config.Clusters["c1"].Kubeconfig | ||
cluster.Kubeconfig = clusterConfig.Kubeconfig |
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.
Much nicer like this.
This change improves structure and reduces code duplication for c1 and c2 by refactoring the New function in env by adding separate helper functions:
setupHub
to initialize the hub cluster.setupManagedClusters
to initialize managed clusters (c1 and c2).Fixes #1950