mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-05-10 19:27:59 +00:00
* Build a commonoption for all managers Signed-off-by: Jian Qiu <jqiu@redhat.com> * Add unit tests Signed-off-by: Jian Qiu <jqiu@redhat.com> --------- Signed-off-by: Jian Qiu <jqiu@redhat.com>
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package spoke
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/spf13/cobra"
|
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
|
|
ocmfeature "open-cluster-management.io/api/feature"
|
|
|
|
commonoptions "open-cluster-management.io/ocm/pkg/common/options"
|
|
"open-cluster-management.io/ocm/pkg/features"
|
|
"open-cluster-management.io/ocm/pkg/version"
|
|
"open-cluster-management.io/ocm/pkg/work/spoke"
|
|
)
|
|
|
|
// NewWorkAgent generates a command to start work agent
|
|
func NewWorkAgent() *cobra.Command {
|
|
commonOptions := commonoptions.NewAgentOptions()
|
|
agentOption := spoke.NewWorkloadAgentOptions()
|
|
cfg := spoke.NewWorkAgentConfig(commonOptions, agentOption)
|
|
cmdConfig := commonOptions.CommoOpts.
|
|
NewControllerCommandConfig("work-agent", version.Get(), cfg.RunWorkloadAgent)
|
|
cmd := cmdConfig.NewCommandWithContext(context.TODO())
|
|
cmd.Use = agentCmdName
|
|
cmd.Short = "Start the Work Agent"
|
|
|
|
// add disable leader election flag
|
|
flags := cmd.Flags()
|
|
commonOptions.AddFlags(flags)
|
|
agentOption.AddFlags(flags)
|
|
utilruntime.Must(features.SpokeMutableFeatureGate.Add(ocmfeature.DefaultSpokeWorkFeatureGates))
|
|
features.SpokeMutableFeatureGate.AddFlag(flags)
|
|
|
|
return cmd
|
|
}
|