Skip to content

Commit

Permalink
Merge pull request kosmos-io#678 from duanmengkk/v0.4.0-0811-4
Browse files Browse the repository at this point in the history
cherry-pick: add direct sync service feature
  • Loading branch information
duanmengkk authored Aug 12, 2024
2 parents b7325be + 67f5b8c commit 43b2f5a
Show file tree
Hide file tree
Showing 6 changed files with 719 additions and 10 deletions.
26 changes: 26 additions & 0 deletions cmd/clustertree/cluster-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
podcontrollers "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pod"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pv"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/pvc"
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/controllers/svc"
nodeserver "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/node-server"
leafUtils "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/utils"
"github.com/kosmos.io/kosmos/pkg/scheme"
Expand Down Expand Up @@ -289,6 +290,31 @@ func run(ctx context.Context, opts *options.Options) error {
}
}

// init direct sync service and endpointslice controller
if opts.DirectClusterService {
simpleSyncServiceController := &svc.SimpleSyncServiceController{
RootClient: mgr.GetClient(),
GlobalLeafManager: globalLeafResourceManager,
GlobalLeafClientManager: globalLeafClientManager,
AutoCreateMCSPrefix: opts.AutoCreateMCSPrefix,
ReservedNamespaces: opts.ReservedNamespaces,
}
if err := simpleSyncServiceController.SetupWithManager(mgr); err != nil {
return fmt.Errorf("error starting %s: %v", svc.SimpleSyncServiceControllerName, err)
}

simpleSyncEpsController := &svc.SimpleSyncEPSController{
RootClient: mgr.GetClient(),
GlobalLeafManager: globalLeafResourceManager,
GlobalLeafClientManager: globalLeafClientManager,
AutoCreateMCSPrefix: opts.AutoCreateMCSPrefix,
ReservedNamespaces: opts.ReservedNamespaces,
BackoffOptions: opts.BackoffOpts,
}
if err := simpleSyncEpsController.SetupWithManager(mgr); err != nil {
return fmt.Errorf("error starting %s: %v", svc.SimpleSyncEPSControllerName, err)
}
}
go func() {
if err = mgr.Start(ctx); err != nil {
klog.Errorf("failed to start controller manager: %v", err)
Expand Down
12 changes: 7 additions & 5 deletions cmd/clustertree/cluster-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const (
)

type Options struct {
LeaderElection componentbaseconfig.LeaderElectionConfiguration
KubernetesOptions KubernetesOptions
ListenPort int32
DaemonSetController bool
MultiClusterService bool
LeaderElection componentbaseconfig.LeaderElectionConfiguration
KubernetesOptions KubernetesOptions
ListenPort int32
DaemonSetController bool
MultiClusterService bool
DirectClusterService bool

// If MultiClusterService is disabled, the clustertree will rewrite the dnsPolicy configuration for pods deployed in
// the leaf clusters, directing them to the root cluster's CoreDNS, thus facilitating access to services across all
Expand Down Expand Up @@ -88,6 +89,7 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.Int32Var(&o.ListenPort, "listen-port", 10250, "Listen port for requests from the kube-apiserver.")
flags.BoolVar(&o.DaemonSetController, "daemonset-controller", false, "Turn on or off daemonset controller.")
flags.BoolVar(&o.MultiClusterService, "multi-cluster-service", false, "Turn on or off mcs support.")
flags.BoolVar(&o.DirectClusterService, "direct-cluster-service", false, "Turn on or off direct cluster service.")
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.")
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.")
flags.BoolVar(&o.OnewayStorageControllers, "oneway-storage-controllers", false, "Turn on or off oneway storage controllers.")
Expand Down
14 changes: 9 additions & 5 deletions pkg/clustertree/cluster-manager/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ func (c *ClusterController) clearClusterControllers(cluster *kosmosv1alpha1.Clus
delete(c.ManagerCancelFuncs, cluster.Name)
delete(c.ControllerManagers, cluster.Name)

actualClusterName := leafUtils.GetActualClusterName(cluster)
c.GlobalLeafResourceManager.RemoveLeafResource(cluster.Name)
c.GlobalLeafClientManager.RemoveLeafClientResource(actualClusterName)
}

func (c *ClusterController) setupControllers(
Expand All @@ -252,6 +254,7 @@ func (c *ClusterController) setupControllers(
Namespace: "",
IgnoreLabels: strings.Split("", ","),
EnableServiceAccount: true,
IPFamilyType: cluster.Spec.ClusterLinkOptions.IPFamily,
}, nodes)

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

if c.Options.MultiClusterService {
serviceImportController := &mcs.ServiceImportController{
LeafClient: mgr.GetClient(),
LeafKosmosClient: leafKosmosClient,
EventRecorder: mgr.GetEventRecorderFor(mcs.LeafServiceImportControllerName),
Logger: mgr.GetLogger(),
LeafNodeName: cluster.Name,
LeafClient: mgr.GetClient(),
LeafKosmosClient: leafKosmosClient,
EventRecorder: mgr.GetEventRecorderFor(mcs.LeafServiceImportControllerName),
Logger: mgr.GetLogger(),
LeafNodeName: cluster.Name,
// todo Null pointer exception ?
IPFamilyType: cluster.Spec.ClusterLinkOptions.IPFamily,
RootResourceManager: c.RootResourceManager,
ReservedNamespaces: c.Options.ReservedNamespaces,
Expand Down
Loading

0 comments on commit 43b2f5a

Please sign in to comment.