Skip to content

Commit

Permalink
title: virtualcluster join controller create mcs crd
Browse files Browse the repository at this point in the history
Signed-off-by: GreatLazyMan <[email protected]>
  • Loading branch information
GreatLazyMan committed Mar 13, 2024
1 parent 4f6e956 commit 98a25f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cmd/clustertree-operator/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type Options struct {
LeaderElection componentbaseconfig.LeaderElectionConfiguration
KubernetesOptions KubernetesOptions
NodeReuse bool
}

type KubernetesOptions struct {
Expand Down Expand Up @@ -43,4 +44,5 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.IntVar(&o.KubernetesOptions.Burst, "kube-burst", 60, "Burst to use while talking with kube-apiserver.")
flags.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path for kubernetes kubeconfig file, if left blank, will use in cluster way.")
flags.StringVar(&o.KubernetesOptions.Master, "master", "", "Used to generate kubeconfig for downloading, if not specified, will use host in kubeconfig.")
flags.BoolVar(&o.NodeReuse, "node-reuse", false, "different virtual cluster can reuse same node.")
}
1 change: 1 addition & 0 deletions cmd/clustertree-operator/app/tree_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func run(ctx context.Context, opts *options.Options) error {
Client: mgr.GetClient(),
EventRecorder: mgr.GetEventRecorderFor(constants.JoinControllerName),
KubeconfigPath: opts.KubernetesOptions.KubeConfig,
NodeReuse: opts.NodeReuse,
}
if err = VirtualClusterJoinController.SetupWithManager(mgr); err != nil {
return fmt.Errorf("error starting %s: %v", constants.JoinControllerName, err)
Expand Down
17 changes: 11 additions & 6 deletions pkg/treeoperator/controller/virtualcluster_join_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type VirtualClusterJoinController struct {
EventRecorder record.EventRecorder
KubeconfigPath string
KubeconfigStream []byte
NodeReuse bool
}

var nodeOwnerMap map[string]string = make(map[string]string)
Expand Down Expand Up @@ -146,11 +147,13 @@ func (c *VirtualClusterJoinController) UninstallClusterTree(ctx context.Context,
return fmt.Errorf("get cluster %s failed when we try to del: %v", clusterName, err)
}
} else {
mu.Lock()
for _, nodeName := range old.Spec.ClusterTreeOptions.LeafModels {
nodeOwnerMap[nodeName.LeafNodeName] = ""
if !c.NodeReuse {
mu.Lock()
for _, nodeName := range old.Spec.ClusterTreeOptions.LeafModels {
nodeOwnerMap[nodeName.LeafNodeName] = ""
}
mu.Unlock()
}
mu.Unlock()
err = c.RemoveClusterFinalizer(old, kosmosClient)
if err != nil {
return fmt.Errorf("removefinalizer %s failed: %v", clusterName, err)
Expand Down Expand Up @@ -331,7 +334,7 @@ func (c *VirtualClusterJoinController) CreateCluster(ctx context.Context, reques
klog.Errorf("node %s doesn't exits: %v", nodeName, err)
continue
}
if len(nodeOwnerMap) > 0 {
if !c.NodeReuse && len(nodeOwnerMap) > 0 {
if nodeOwner, existed := nodeOwnerMap[nodeName]; existed && len(nodeOwner) > 0 &&
nodeOwner != clusterName {
continue
Expand All @@ -350,7 +353,9 @@ func (c *VirtualClusterJoinController) CreateCluster(ctx context.Context, reques
NodeName: nodeName,
},
}
nodeOwnerMap[nodeName] = clusterName
if !c.NodeReuse {
nodeOwnerMap[nodeName] = clusterName
}
leafModels = append(leafModels, leafModel)
}
mu.Unlock()
Expand Down

0 comments on commit 98a25f3

Please sign in to comment.