Files
open-cluster-management/pkg/cmd/spoke/work.go
Jian Qiu f7cd1402e9 run work and registration as a single binary (#201)
* run registratin/work together

Signed-off-by: Jian Qiu <jqiu@redhat.com>

* Fix integration test and lint issue

Signed-off-by: Jian Qiu <jqiu@redhat.com>

* Update operator to deploy singleton mode

Signed-off-by: Jian Qiu <jqiu@redhat.com>

* Update deps

Signed-off-by: Jian Qiu <jqiu@redhat.com>

---------

Signed-off-by: Jian Qiu <jqiu@redhat.com>
2023-07-14 04:56:48 +02:00

40 lines
1.3 KiB
Go

package spoke
import (
"context"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"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 := controllercmd.
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)
flags.BoolVar(&cmdConfig.DisableLeaderElection, "disable-leader-election", false, "Disable leader election for the agent.")
return cmd
}