Merge pull request #11 from qiujian16/split-hub-spoke

Split hub/spoke operator to two cmds
This commit is contained in:
OpenShift Merge Robot
2020-05-18 21:42:25 +02:00
committed by GitHub
4 changed files with 54 additions and 11 deletions

View File

@@ -26,14 +26,14 @@ func main() {
logs.InitLogs()
defer logs.FlushLogs()
command := newWorkCommand()
command := newNucleusCommand()
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
func newWorkCommand() *cobra.Command {
func newNucleusCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "nucleus",
Short: "Nucleus Operator",
@@ -49,7 +49,8 @@ func newWorkCommand() *cobra.Command {
cmd.Version = v
}
cmd.AddCommand(operator.NewOperatorCmd())
cmd.AddCommand(operator.NewHubOperatorCmd())
cmd.AddCommand(operator.NewSpokeOperatorCmd())
return cmd
}

View File

@@ -9,13 +9,13 @@ import (
"github.com/open-cluster-management/nucleus/pkg/version"
)
// NewOperatorCmd generatee a command to start workload agent
func NewOperatorCmd() *cobra.Command {
// NewHubOperatorCmd generatee a command to start hub operator
func NewHubOperatorCmd() *cobra.Command {
cmd := controllercmd.
NewControllerCommandConfig("nucleus-operator", version.Get(), operators.RunNucleusOperator).
NewControllerCommandConfig("nucleus-hub", version.Get(), operators.RunNucleusHubOperator).
NewCommand()
cmd.Use = "operator"
cmd.Short = "Start the nucleus operator"
cmd.Use = "hub"
cmd.Short = "Start the nucleus hub operator"
return cmd
}

21
pkg/cmd/operator/spoke.go Normal file
View File

@@ -0,0 +1,21 @@
package operator
import (
"github.com/spf13/cobra"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/open-cluster-management/nucleus/pkg/operators"
"github.com/open-cluster-management/nucleus/pkg/version"
)
// NewSpokeOperatorCmd generatee a command to start spoke operator
func NewSpokeOperatorCmd() *cobra.Command {
cmd := controllercmd.
NewControllerCommandConfig("nucleus-spoke", version.Get(), operators.RunNucleusSpokeOperator).
NewCommand()
cmd.Use = "spoke"
cmd.Short = "Start the nucleus hub operator"
return cmd
}

View File

@@ -15,8 +15,8 @@ import (
"github.com/open-cluster-management/nucleus/pkg/operators/spoke"
)
// RunNucleusOperator starts a new nucleus operator
func RunNucleusOperator(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
// RunNucleusHubOperator starts a new nucleus hub operator
func RunNucleusHubOperator(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
// Build kubclient client and informer for spoke cluster
kubeClient, err := kubernetes.NewForConfig(controllerContext.KubeConfig)
if err != nil {
@@ -40,6 +40,28 @@ func RunNucleusOperator(ctx context.Context, controllerContext *controllercmd.Co
nucleusClient.NucleusV1().HubCores(),
nucleusInformer.Nucleus().V1().HubCores(),
controllerContext.EventRecorder)
go nucleusInformer.Start(ctx.Done())
go hubcontroller.Run(ctx, 1)
<-ctx.Done()
return nil
}
// RunNucleusSpokeOperator starts a new nucleus spoke operator
func RunNucleusSpokeOperator(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
// Build kubclient client and informer for spoke cluster
kubeClient, err := kubernetes.NewForConfig(controllerContext.KubeConfig)
if err != nil {
return err
}
// Build nucleus client and informer
nucleusClient, err := nucleusclient.NewForConfig(controllerContext.KubeConfig)
if err != nil {
return err
}
nucleusInformer := nucleusinformer.NewSharedInformerFactory(nucleusClient, 5*time.Minute)
spokeController := spoke.NewNucleusSpokeController(
kubeClient,
nucleusClient.NucleusV1().SpokeCores(),
@@ -47,7 +69,6 @@ func RunNucleusOperator(ctx context.Context, controllerContext *controllercmd.Co
controllerContext.EventRecorder)
go nucleusInformer.Start(ctx.Done())
go hubcontroller.Run(ctx, 1)
go spokeController.Run(ctx, 1)
<-ctx.Done()
return nil