Files
Vaishnav KaleandGitHub 0ec4f5da1a feature: expose flags to configure spoke agent controller workers (#1560)
* feat: expose flags to configure spoke agent controller workers

Signed-off-by: Vaishnav88sk <vaishnavsk8804@gmail.com>

* fix: address PR review feedback on worker validation and formatting

Signed-off-by: Vaishnav88sk <vaishnavsk8804@gmail.com>

* refactor: consolidate worker count flags into a single flag

Signed-off-by: Vaishnav88sk <vaishnavsk8804@gmail.com>

---------

Signed-off-by: Vaishnav88sk <vaishnavsk8804@gmail.com>
2026-07-03 03:07:21 +00:00

76 lines
3.0 KiB
Go

package spoke
import (
"fmt"
"time"
"github.com/spf13/pflag"
"open-cluster-management.io/ocm/pkg/work/spoke/objectreader"
)
const (
defaultUserAgent = "work-agent"
)
// WorkloadAgentOptions defines the flags for workload agent
type WorkloadAgentOptions struct {
StatusSyncInterval time.Duration
AppliedManifestWorkEvictionGracePeriod time.Duration
MaxJSONRawLength int32
WorkloadSourceDriver string
WorkloadSourceConfig string
CloudEventsClientID string
CloudEventsClientCodecs []string
DefaultUserAgent string
WorkloadAgentWorkers int
ObjectReaderOption *objectreader.Options
}
// NewWorkloadAgentOptions returns the flags with default value set
func NewWorkloadAgentOptions() *WorkloadAgentOptions {
return &WorkloadAgentOptions{
MaxJSONRawLength: 1024,
StatusSyncInterval: 10 * time.Second,
AppliedManifestWorkEvictionGracePeriod: 60 * time.Minute,
WorkloadSourceDriver: "kube",
WorkloadSourceConfig: "/spoke/hub-kubeconfig/kubeconfig",
DefaultUserAgent: defaultUserAgent,
ObjectReaderOption: objectreader.NewOptions(),
WorkloadAgentWorkers: 10,
}
}
// AddFlags register and binds the default flags
func (o *WorkloadAgentOptions) AddFlags(fs *pflag.FlagSet) {
fs.Int32Var(&o.MaxJSONRawLength, "max-json-raw-length",
o.MaxJSONRawLength, "The maximum size of the JSON raw string returned from status feedback")
fs.DurationVar(&o.StatusSyncInterval, "status-sync-interval",
o.StatusSyncInterval, "Interval to sync resource status to hub.")
fs.DurationVar(&o.AppliedManifestWorkEvictionGracePeriod, "appliedmanifestwork-eviction-grace-period",
o.AppliedManifestWorkEvictionGracePeriod, "Grace period for appliedmanifestwork eviction")
fs.StringVar(&o.WorkloadSourceDriver, "workload-source-driver",
o.WorkloadSourceDriver, "The type of workload source driver, currently it can be kube, mqtt, grpc or kafka")
fs.StringVar(&o.WorkloadSourceConfig, "workload-source-config",
o.WorkloadSourceConfig, "The config file path of current workload source")
fs.StringVar(&o.CloudEventsClientID, "cloudevents-client-id",
o.CloudEventsClientID, "The ID of the cloudevents client when workload source source is based on cloudevents")
fs.StringSliceVar(&o.CloudEventsClientCodecs, "cloudevents-client-codecs", o.CloudEventsClientCodecs,
"The codecs for cloudevents client when workload source source is based on cloudevents, the valid codecs: manifest or manifestbundle")
fs.IntVar(&o.WorkloadAgentWorkers, "workload-agent-workers",
o.WorkloadAgentWorkers, "The number of workers for the workload agent controllers")
o.ObjectReaderOption.AddFlags(fs)
}
// Validate checks if the options are valid
func (o *WorkloadAgentOptions) Validate() error {
if o.WorkloadAgentWorkers < 1 {
return fmt.Errorf("workload-agent-workers must be >= 1, got %d", o.WorkloadAgentWorkers)
}
return nil
}