Skip to content

Commit

Permalink
add version command to components
Browse files Browse the repository at this point in the history
Signed-off-by: lonelyCZ <531187475@qq.com>
  • Loading branch information
lonelyCZ committed Sep 13, 2021
1 parent 5dc2648 commit ae9f7bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/karmada-io/karmada/pkg/util/informermanager"
"github.com/karmada-io/karmada/pkg/util/names"
"github.com/karmada-io/karmada/pkg/util/objectwatcher"
"github.com/karmada-io/karmada/pkg/version"
"github.com/karmada-io/karmada/pkg/version/sharedcommand"
)

// NewAgentCommand creates a *cobra.Command object with default parameters
Expand All @@ -45,11 +47,13 @@ func NewAgentCommand(ctx context.Context) *cobra.Command {
}

opts.AddFlags(cmd.Flags())
cmd.AddCommand(sharedcommand.NewCmdVersion(os.Stdout, "karmada-agent"))
cmd.Flags().AddGoFlagSet(flag.CommandLine)
return cmd
}

func run(ctx context.Context, karmadaConfig karmadactl.KarmadaConfig, opts *options.Options) error {
klog.Infof("karmada-agent version: %s", version.Get())
controlPlaneRestConfig, err := karmadaConfig.GetRestConfig(opts.KarmadaContext, opts.KarmadaKubeConfig)
if err != nil {
return fmt.Errorf("error building kubeconfig of karmada control plane: %s", err.Error())
Expand Down
8 changes: 6 additions & 2 deletions cmd/scheduler-estimator/app/scheduler-estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ import (

"github.com/karmada-io/karmada/cmd/scheduler-estimator/app/options"
"github.com/karmada-io/karmada/pkg/estimator/server"
"github.com/karmada-io/karmada/pkg/version"
"github.com/karmada-io/karmada/pkg/version/sharedcommand"
)

// NewSchedulerEstimatorCommand creates a *cobra.Command object with default parameters
func NewSchedulerEstimatorCommand(ctx context.Context) *cobra.Command {
opts := options.NewOptions()

cmd := &cobra.Command{
Use: "scheduler-estimator",
Long: `The scheduler estimator runs an accurate scheduler estimator of a cluster`,
Use: "karmada-scheduler-estimator",
Long: `The karmada scheduler estimator runs an accurate scheduler estimator of a cluster`,
Run: func(cmd *cobra.Command, args []string) {
if err := run(ctx, opts); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand All @@ -32,11 +34,13 @@ func NewSchedulerEstimatorCommand(ctx context.Context) *cobra.Command {
}

opts.AddFlags(cmd.Flags())
cmd.AddCommand(sharedcommand.NewCmdVersion(os.Stdout, "karmada-scheduler-estimator"))
cmd.Flags().AddGoFlagSet(flag.CommandLine)
return cmd
}

func run(ctx context.Context, opts *options.Options) error {
klog.Infof("karmada-scheduler-estimator version: %s", version.Get())
go serveHealthz(fmt.Sprintf("%s:%d", opts.BindAddress, opts.SecurePort))

restConfig, err := clientcmd.BuildConfigFromFlags(opts.Master, opts.KubeConfig)
Expand Down
6 changes: 5 additions & 1 deletion cmd/scheduler/app/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import (
"github.com/karmada-io/karmada/cmd/scheduler/app/options"
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
"github.com/karmada-io/karmada/pkg/scheduler"
"github.com/karmada-io/karmada/pkg/version"
"github.com/karmada-io/karmada/pkg/version/sharedcommand"
)

// NewSchedulerCommand creates a *cobra.Command object with default parameters
func NewSchedulerCommand(stopChan <-chan struct{}) *cobra.Command {
opts := options.NewOptions()

cmd := &cobra.Command{
Use: "scheduler",
Use: "karmada-scheduler",
Long: `The karmada scheduler binds resources to the clusters it manages.`,
Run: func(cmd *cobra.Command, args []string) {
if err := run(opts, stopChan); err != nil {
Expand All @@ -38,11 +40,13 @@ func NewSchedulerCommand(stopChan <-chan struct{}) *cobra.Command {
}

opts.AddFlags(cmd.Flags())
cmd.AddCommand(sharedcommand.NewCmdVersion(os.Stdout, "karmada-scheduler"))
cmd.Flags().AddGoFlagSet(flag.CommandLine)
return cmd
}

func run(opts *options.Options, stopChan <-chan struct{}) error {
klog.Infof("karmada-scheduler version: %s", version.Get())
go serveHealthz(fmt.Sprintf("%s:%d", opts.BindAddress, opts.SecurePort))

restConfig, err := clientcmd.BuildConfigFromFlags(opts.Master, opts.KubeConfig)
Expand Down
8 changes: 6 additions & 2 deletions cmd/webhook/app/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

"github.com/karmada-io/karmada/cmd/webhook/app/options"
"github.com/karmada-io/karmada/pkg/util/gclient"
"github.com/karmada-io/karmada/pkg/version"
"github.com/karmada-io/karmada/pkg/version/sharedcommand"
"github.com/karmada-io/karmada/pkg/webhook/cluster"
"github.com/karmada-io/karmada/pkg/webhook/clusterpropagationpolicy"
"github.com/karmada-io/karmada/pkg/webhook/overridepolicy"
Expand All @@ -27,8 +29,8 @@ func NewWebhookCommand(ctx context.Context) *cobra.Command {
opts := options.NewOptions()

cmd := &cobra.Command{
Use: "webhook",
Long: `Start a webhook server`,
Use: "karmada-webhook",
Long: `Start a karmada webhook server`,
Run: func(cmd *cobra.Command, args []string) {
if err := Run(ctx, opts); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand All @@ -38,13 +40,15 @@ func NewWebhookCommand(ctx context.Context) *cobra.Command {
}

cmd.Flags().AddGoFlagSet(flag.CommandLine)
cmd.AddCommand(sharedcommand.NewCmdVersion(os.Stdout, "karmada-webhook"))
opts.AddFlags(cmd.Flags())

return cmd
}

// Run runs the webhook server with options. This should never exit.
func Run(ctx context.Context, opts *options.Options) error {
klog.Infof("karmada-webhook version: %s", version.Get())
config, err := controllerruntime.GetConfig()
if err != nil {
panic(err)
Expand Down

0 comments on commit ae9f7bd

Please sign in to comment.