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

e2e: refactor cluster setup in env #1941

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

parikshithb
Copy link
Member

@parikshithb parikshithb commented Mar 18, 2025

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

@parikshithb parikshithb removed the request for review from raghavendra-talur March 18, 2025 14:29
@parikshithb parikshithb marked this pull request as draft March 18, 2025 14:42
@nirs
Copy link
Member

nirs commented Mar 18, 2025

@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]>
@parikshithb parikshithb marked this pull request as ready for review March 21, 2025 08:42
@parikshithb parikshithb reopened this Mar 21, 2025
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)
Copy link
Member

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,
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Much nicer like this.

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.

e2e: refactor New function in env
2 participants