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

fix connection improvement bugs #3914

Merged
merged 4 commits into from
Dec 30, 2024
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
11 changes: 9 additions & 2 deletions pkg/tool/clientmanager/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import (
var kubeClientManagerInstance *KubeClientManager
var once sync.Once

var stopContext = ctrl.SetupSignalHandler()

// TODO: Implement a Zadig-Kubernetes client interface, forbid business code to access these clients directly

type KubeClientManager struct {
Expand Down Expand Up @@ -447,7 +449,7 @@ func (cm *KubeClientManager) getControllerRuntimeCluster(clusterID string) (cont
controllerClient, err := createControllerRuntimeCluster(ctrl.GetConfigOrDie())
if err == nil {
go func() {
if err := controllerClient.Start(ctrl.SetupSignalHandler()); err != nil {
if err := controllerClient.Start(stopContext); err != nil {
log.Errorf("failed to start controller runtime cluster, error: %s", err)
}
}()
Expand All @@ -467,6 +469,10 @@ func (cm *KubeClientManager) getControllerRuntimeCluster(clusterID string) (cont
return nil, fmt.Errorf("cluster %s not found", clusterID)
}

if clusterInfo.Status != setting.Normal {
return nil, fmt.Errorf("unable to connect to cluster: %s, status: %s", clusterInfo.Name, clusterInfo.Status)
}

var cfg *rest.Config

switch clusterInfo.Type {
Expand All @@ -484,10 +490,11 @@ func (cm *KubeClientManager) getControllerRuntimeCluster(clusterID string) (cont
controllerClient, err := createControllerRuntimeCluster(cfg)
if err == nil {
go func() {
if err := controllerClient.Start(ctrl.SetupSignalHandler()); err != nil {
if err := controllerClient.Start(stopContext); err != nil {
log.Errorf("failed to start controller runtime cluster, error: %s", err)
}
}()

if !controllerClient.GetCache().WaitForCacheSync(context.Background()) {
return nil, fmt.Errorf("failed to wait for controller runtime cluster to sync")
}
Expand Down
Loading