support setting host cluster name

Signed-off-by: yuswift <yuswift2018@gmail.com>
This commit is contained in:
yuswift
2021-09-05 23:18:15 +08:00
parent 73b65b12ec
commit 8da8c5deb1
3 changed files with 24 additions and 8 deletions

View File

@@ -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 {