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

🌱 Remove redundant GetRESTConfig in KCP Management.GetWorkloadCluster #9448

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions controlplane/kubeadm/internal/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,11 @@ func (m *Management) GetWorkloadCluster(ctx context.Context, clusterKey client.O
restConfig = rest.CopyConfig(restConfig)
restConfig.Timeout = 30 * time.Second

if m.Tracker == nil {
Copy link
Member Author

@sbueringer sbueringer Sep 18, 2023

Choose a reason for hiding this comment

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

I think this nil check is pretty useless. If it would be a problem it would panic in l.108 at the moment. And if it wouldn't, our e2e tests would never be green if we always return an error

return nil, errors.New("Cannot get WorkloadCluster: No remote Cluster Cache")
}

c, err := m.Tracker.GetClient(ctx, clusterKey)
if err != nil {
return nil, &RemoteClusterConnectionError{Name: clusterKey.String(), Err: err}
}

clientConfig, err := m.Tracker.GetRESTConfig(ctx, clusterKey)
if err != nil {
return nil, &RemoteClusterConnectionError{Name: clusterKey.String(), Err: err}
}

// Make sure we use the same CA and Host as the client.
// Note: This has to be done to be able to communicate directly on self-hosted clusters.
restConfig.CAData = clientConfig.CAData
restConfig.CAFile = clientConfig.CAFile
restConfig.Host = clientConfig.Host

// Retrieves the etcd CA key Pair
Copy link
Member Author

@sbueringer sbueringer Sep 18, 2023

Choose a reason for hiding this comment

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

This only made sense with the old code. Since we moved to CCT there is no reason to call GetRESTConfig twice.

Old code:

func (m *Management) GetWorkloadCluster(ctx context.Context, clusterKey client.ObjectKey) (WorkloadCluster, error) {
	// TODO(chuckha): Inject this dependency.
	// TODO(chuckha): memoize this function. The workload client only exists as long as a reconciliation loop.
	restConfig, err := remote.RESTConfig(ctx, KubeadmControlPlaneControllerName, m.Client, clusterKey)
	if err != nil {
		return nil, err
	}
	restConfig.Timeout = 30 * time.Second

	if m.Tracker == nil {
		return nil, errors.New("Cannot get WorkloadCluster: No remote Cluster Cache")
	}

	c, err := m.Tracker.GetClient(ctx, clusterKey)
	if err != nil {
		return nil, err
	}

	clientConfig, err := m.Tracker.GetRESTConfig(ctx, clusterKey)
	if err != nil {
		return nil, err
	}

	// Make sure we use the same CA and Host as the client.
	// Note: This has to be done to be able to communicate directly on self-hosted clusters.
	restConfig.CAData = clientConfig.CAData
	restConfig.CAFile = clientConfig.CAFile
	restConfig.Host = clientConfig.Host

crtData, keyData, err := m.getEtcdCAKeyPair(ctx, clusterKey)
if err != nil {
Expand Down
Loading