support setting host cluster name
Signed-off-by: yuswift <yuswift2018@gmail.com>
This commit is contained in:
@@ -190,7 +190,8 @@ func addControllers(
|
||||
client.Config(),
|
||||
kubesphereInformer.Cluster().V1alpha1().Clusters(),
|
||||
client.KubeSphere().ClusterV1alpha1().Clusters(),
|
||||
multiClusterOptions.ClusterControllerResyncSecond)
|
||||
multiClusterOptions.ClusterControllerResyncPeriod,
|
||||
multiClusterOptions.HostClusterName)
|
||||
}
|
||||
|
||||
var nsnpController manager.Runnable
|
||||
|
||||
@@ -155,6 +155,8 @@ type clusterController struct {
|
||||
clusterMap map[string]*clusterData
|
||||
|
||||
resyncPeriod time.Duration
|
||||
|
||||
hostClusterNmae string
|
||||
}
|
||||
|
||||
func NewClusterController(
|
||||
@@ -163,6 +165,7 @@ func NewClusterController(
|
||||
clusterInformer clusterinformer.ClusterInformer,
|
||||
clusterClient clusterclient.ClusterInterface,
|
||||
resyncPeriod time.Duration,
|
||||
hostClusterName string,
|
||||
) *clusterController {
|
||||
|
||||
broadcaster := record.NewBroadcaster()
|
||||
@@ -182,6 +185,7 @@ func NewClusterController(
|
||||
workerLoopPeriod: time.Second,
|
||||
clusterMap: make(map[string]*clusterData),
|
||||
resyncPeriod: resyncPeriod,
|
||||
hostClusterNmae: hostClusterName,
|
||||
}
|
||||
c.clusterLister = clusterInformer.Lister()
|
||||
c.clusterHasSynced = clusterInformer.Informer().HasSynced
|
||||
@@ -317,6 +321,7 @@ func (c *clusterController) reconcileHostCluster() error {
|
||||
// no host cluster, create one
|
||||
if len(clusters) == 0 {
|
||||
hostCluster.Spec.Connection.KubeConfig = hostKubeConfig
|
||||
hostCluster.Name = c.hostClusterNmae
|
||||
_, err = c.clusterClient.Create(context.TODO(), hostCluster, metav1.CreateOptions{})
|
||||
return err
|
||||
} else if len(clusters) > 1 {
|
||||
|
||||
@@ -22,7 +22,10 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
const DefaultResyncPeriod = 120 * time.Second
|
||||
const (
|
||||
DefaultResyncPeriod = 120 * time.Second
|
||||
DefaultHostClusterName = "host"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
// Enable
|
||||
@@ -43,11 +46,14 @@ type Options struct {
|
||||
// AgentImage is the image used when generating deployment for all cluster agents.
|
||||
AgentImage string `json:"agentImage,omitempty"`
|
||||
|
||||
// ClusterControllerResyncSecond is the resync period used by cluster controller.
|
||||
ClusterControllerResyncSecond time.Duration `json:"clusterControllerResyncSecond,omitempty" yaml:"clusterControllerResyncSecond"`
|
||||
// ClusterControllerResyncPeriod is the resync period used by cluster controller.
|
||||
ClusterControllerResyncPeriod time.Duration `json:"clusterControllerResyncPeriod,omitempty" yaml:"clusterControllerResyncPeriod"`
|
||||
|
||||
// HostClusterName is the name of the control plane cluster, default set to host.
|
||||
HostClusterName string `json:"hostClusterName,omitempty" yaml:"hostClusterName"`
|
||||
}
|
||||
|
||||
// NewOptions() returns a default nil options
|
||||
// NewOptions returns a default nil options
|
||||
func NewOptions() *Options {
|
||||
return &Options{
|
||||
Enable: false,
|
||||
@@ -55,7 +61,8 @@ func NewOptions() *Options {
|
||||
ProxyPublishAddress: "",
|
||||
ProxyPublishService: "",
|
||||
AgentImage: "kubesphere/tower:v1.0",
|
||||
ClusterControllerResyncSecond: DefaultResyncPeriod,
|
||||
ClusterControllerResyncPeriod: DefaultResyncPeriod,
|
||||
HostClusterName: DefaultHostClusterName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +85,9 @@ func (o *Options) AddFlags(fs *pflag.FlagSet, s *Options) {
|
||||
fs.StringVar(&o.AgentImage, "agent-image", s.AgentImage, ""+
|
||||
"This field is used when generating deployment yaml for agent.")
|
||||
|
||||
fs.DurationVar(&o.ClusterControllerResyncSecond, "cluster-controller-resync-second", s.ClusterControllerResyncSecond,
|
||||
"Cluster controller resync second to sync cluster resource. e.g. 2m 5m 10m ... default set to 2m")
|
||||
fs.DurationVar(&o.ClusterControllerResyncPeriod, "cluster-controller-resync-period", s.ClusterControllerResyncPeriod,
|
||||
"Cluster controller resync period to sync cluster resource. e.g. 2m 5m 10m ... default set to 2m")
|
||||
|
||||
fs.StringVar(&o.HostClusterName, "host-cluster-name", s.HostClusterName, "the name of the control plane"+
|
||||
" cluster, default set to host")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user