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

add direct sync service feature #667

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
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
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.GlobalLeafResourceManager.RemoveLeafResource(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
Loading