Skip to content

Commit

Permalink
Merge pull request #55 from MikeSpreitzer/expose-zap-opts
Browse files Browse the repository at this point in the history
🐛 Expose zap flags from OCM Status Add-On Agent
  • Loading branch information
pdettori authored May 17, 2024
2 parents 654ca7e + 373c2d6 commit a1f669b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/agent/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func NewAgentCommand(addonName string) *cobra.Command {

// AgentOptions defines the flags for workload agent
type AgentOptions struct {
ZapOpts zap.Options
MetricsAddr string
EnableLeaderElection bool
ProbeAddr string
Expand All @@ -82,11 +83,14 @@ type AgentOptions struct {

// NewAgentOptions returns the flags with default value set
func NewAgentOptions(addonName string) *AgentOptions {
return &AgentOptions{AddonName: addonName}
return &AgentOptions{ZapOpts: zap.Options{Development: true}, AddonName: addonName}
}

func (o *AgentOptions) AddFlags(cmd *cobra.Command) {
flags := cmd.Flags()
forZap := flag.NewFlagSet("agent", flag.ExitOnError)
o.ZapOpts.BindFlags(forZap)
flags.AddGoFlagSet(forZap)
// This command only supports reading from config
flags.StringVar(&o.HubKubeconfigFile, "hub-kubeconfig", o.HubKubeconfigFile,
"Location of kubeconfig file to connect to hub cluster.")
Expand All @@ -101,13 +105,9 @@ func (o *AgentOptions) AddFlags(cmd *cobra.Command) {
}

func (o *AgentOptions) RunAgent(ctx context.Context, kubeconfig *rest.Config) error {
opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&o.ZapOpts)))

// setup manager
// manager here is mainly used for leader election and health checks
Expand Down

0 comments on commit a1f669b

Please sign in to comment.