@@ -3,13 +3,14 @@ package clustersynchro
33import (
44 "context"
55 "fmt"
6+ "net"
67 "sync"
78 "sync/atomic"
9+ "time"
810
911 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1012 "k8s.io/apimachinery/pkg/runtime/schema"
1113 "k8s.io/apimachinery/pkg/util/wait"
12- "k8s.io/client-go/kubernetes"
1314 "k8s.io/client-go/rest"
1415 "k8s.io/klog/v2"
1516
@@ -18,6 +19,8 @@ import (
1819 "github.com/clusterpedia-io/clusterpedia/pkg/storage"
1920 "github.com/clusterpedia-io/clusterpedia/pkg/storageconfig"
2021 "github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/clustersynchro/informer"
22+ "github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/features"
23+ clusterpediafeature "github.com/clusterpedia-io/clusterpedia/pkg/utils/feature"
2124)
2225
2326type ClusterSynchro struct {
@@ -27,7 +30,7 @@ type ClusterSynchro struct {
2730 ClusterStatusUpdater ClusterStatusUpdater
2831
2932 storage storage.StorageFactory
30- clusterclient kubernetes. Interface
33+ healthChecker * healthChecker
3134 dynamicDiscovery discovery.DynamicDiscoveryInterface
3235 listerWatcherFactory informer.DynamicListerWatcherFactory
3336
@@ -64,11 +67,6 @@ type ClusterStatusUpdater interface {
6467type RetryableError error
6568
6669func New (name string , config * rest.Config , storage storage.StorageFactory , updater ClusterStatusUpdater ) (* ClusterSynchro , error ) {
67- clusterclient , err := kubernetes .NewForConfig (config )
68- if err != nil {
69- return nil , fmt .Errorf ("failed to create a cluster client: %w" , err )
70- }
71-
7270 dynamicDiscovery , err := discovery .NewDynamicDiscoveryManager (name , config )
7371 if err != nil {
7472 return nil , RetryableError (fmt .Errorf ("failed to create dynamic discovery manager: %w" , err ))
@@ -84,13 +82,25 @@ func New(name string, config *rest.Config, storage storage.StorageFactory, updat
8482 return nil , fmt .Errorf ("failed to create lister watcher factory: %w" , err )
8583 }
8684
85+ checkerConfig := * config
86+ if clusterpediafeature .FeatureGate .Enabled (features .HealthCheckerWithStandaloneTCP ) {
87+ checkerConfig .Dial = (& net.Dialer {
88+ Timeout : 30 * time .Second ,
89+ KeepAlive : 30 * time .Second ,
90+ }).DialContext
91+ }
92+ healthChecker , err := newHealthChecker (& checkerConfig )
93+ if err != nil {
94+ return nil , fmt .Errorf ("failed to create a cluster health checker: %w" , err )
95+ }
96+
8797 synchro := & ClusterSynchro {
8898 name : name ,
8999 RESTConfig : config ,
90100 ClusterStatusUpdater : updater ,
91101 storage : storage ,
92102
93- clusterclient : clusterclient ,
103+ healthChecker : healthChecker ,
94104 dynamicDiscovery : dynamicDiscovery ,
95105 listerWatcherFactory : listWatchFactory ,
96106
0 commit comments