Skip to content

Commit 43b2f5a

Browse files
authored
Merge pull request kosmos-io#678 from duanmengkk/v0.4.0-0811-4
cherry-pick: add direct sync service feature
2 parents b7325be + 67f5b8c commit 43b2f5a

File tree

6 files changed

+719
-10
lines changed

6 files changed

+719
-10
lines changed

cmd/clustertree/cluster-manager/app/manager.go

+26
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
podcontrollers "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pod"
2525
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pv"
2626
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pvc"
27+
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/svc"
2728
nodeserver "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/node-server"
2829
leafUtils "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/utils"
2930
"github.com/kosmos.io/kosmos/pkg/scheme"
@@ -289,6 +290,31 @@ func run(ctx context.Context, opts *options.Options) error {
289290
}
290291
}
291292

293+
// init direct sync service and endpointslice controller
294+
if opts.DirectClusterService {
295+
simpleSyncServiceController := &svc.SimpleSyncServiceController{
296+
RootClient: mgr.GetClient(),
297+
GlobalLeafManager: globalLeafResourceManager,
298+
GlobalLeafClientManager: globalLeafClientManager,
299+
AutoCreateMCSPrefix: opts.AutoCreateMCSPrefix,
300+
ReservedNamespaces: opts.ReservedNamespaces,
301+
}
302+
if err := simpleSyncServiceController.SetupWithManager(mgr); err != nil {
303+
return fmt.Errorf("error starting %s: %v", svc.SimpleSyncServiceControllerName, err)
304+
}
305+
306+
simpleSyncEpsController := &svc.SimpleSyncEPSController{
307+
RootClient: mgr.GetClient(),
308+
GlobalLeafManager: globalLeafResourceManager,
309+
GlobalLeafClientManager: globalLeafClientManager,
310+
AutoCreateMCSPrefix: opts.AutoCreateMCSPrefix,
311+
ReservedNamespaces: opts.ReservedNamespaces,
312+
BackoffOptions: opts.BackoffOpts,
313+
}
314+
if err := simpleSyncEpsController.SetupWithManager(mgr); err != nil {
315+
return fmt.Errorf("error starting %s: %v", svc.SimpleSyncEPSControllerName, err)
316+
}
317+
}
292318
go func() {
293319
if err = mgr.Start(ctx); err != nil {
294320
klog.Errorf("failed to start controller manager: %v", err)

cmd/clustertree/cluster-manager/app/options/options.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ const (
2525
)
2626

2727
type Options struct {
28-
LeaderElection componentbaseconfig.LeaderElectionConfiguration
29-
KubernetesOptions KubernetesOptions
30-
ListenPort int32
31-
DaemonSetController bool
32-
MultiClusterService bool
28+
LeaderElection componentbaseconfig.LeaderElectionConfiguration
29+
KubernetesOptions KubernetesOptions
30+
ListenPort int32
31+
DaemonSetController bool
32+
MultiClusterService bool
33+
DirectClusterService bool
3334

3435
// If MultiClusterService is disabled, the clustertree will rewrite the dnsPolicy configuration for pods deployed in
3536
// the leaf clusters, directing them to the root cluster's CoreDNS, thus facilitating access to services across all
@@ -88,6 +89,7 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
8889
flags.Int32Var(&o.ListenPort, "listen-port", 10250, "Listen port for requests from the kube-apiserver.")
8990
flags.BoolVar(&o.DaemonSetController, "daemonset-controller", false, "Turn on or off daemonset controller.")
9091
flags.BoolVar(&o.MultiClusterService, "multi-cluster-service", false, "Turn on or off mcs support.")
92+
flags.BoolVar(&o.DirectClusterService, "direct-cluster-service", false, "Turn on or off direct cluster service.")
9193
flags.StringVar(&o.RootCoreDNSServiceNamespace, "root-coredns-service-namespace", CoreDNSServiceNamespace, "The namespace of the CoreDNS service in the root cluster, used to locate the CoreDNS service when MultiClusterService is disabled.")
9294
flags.StringVar(&o.RootCoreDNSServiceName, "root-coredns-service-name", CoreDNSServiceName, "The name of the CoreDNS service in the root cluster, used to locate the CoreDNS service when MultiClusterService is disabled.")
9395
flags.BoolVar(&o.OnewayStorageControllers, "oneway-storage-controllers", false, "Turn on or off oneway storage controllers.")

pkg/clustertree/cluster-manager/cluster_controller.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ func (c *ClusterController) clearClusterControllers(cluster *kosmosv1alpha1.Clus
234234
delete(c.ManagerCancelFuncs, cluster.Name)
235235
delete(c.ControllerManagers, cluster.Name)
236236

237+
actualClusterName := leafUtils.GetActualClusterName(cluster)
237238
c.GlobalLeafResourceManager.RemoveLeafResource(cluster.Name)
239+
c.GlobalLeafClientManager.RemoveLeafClientResource(actualClusterName)
238240
}
239241

240242
func (c *ClusterController) setupControllers(
@@ -252,6 +254,7 @@ func (c *ClusterController) setupControllers(
252254
Namespace: "",
253255
IgnoreLabels: strings.Split("", ","),
254256
EnableServiceAccount: true,
257+
IPFamilyType: cluster.Spec.ClusterLinkOptions.IPFamily,
255258
}, nodes)
256259

257260
c.GlobalLeafClientManager.AddLeafClientResource(&leafUtils.LeafClientResource{
@@ -283,11 +286,12 @@ func (c *ClusterController) setupControllers(
283286

284287
if c.Options.MultiClusterService {
285288
serviceImportController := &mcs.ServiceImportController{
286-
LeafClient: mgr.GetClient(),
287-
LeafKosmosClient: leafKosmosClient,
288-
EventRecorder: mgr.GetEventRecorderFor(mcs.LeafServiceImportControllerName),
289-
Logger: mgr.GetLogger(),
290-
LeafNodeName: cluster.Name,
289+
LeafClient: mgr.GetClient(),
290+
LeafKosmosClient: leafKosmosClient,
291+
EventRecorder: mgr.GetEventRecorderFor(mcs.LeafServiceImportControllerName),
292+
Logger: mgr.GetLogger(),
293+
LeafNodeName: cluster.Name,
294+
// todo Null pointer exception ?
291295
IPFamilyType: cluster.Spec.ClusterLinkOptions.IPFamily,
292296
RootResourceManager: c.RootResourceManager,
293297
ReservedNamespaces: c.Options.ReservedNamespaces,

0 commit comments

Comments
 (0)