package syncedobject import ( "context" "flag" "os" "cloud.google.com/go/pubsub" "github.com/peterbourgon/ff/v3" ) type Config struct { MetricsAddr string GCPProjectID string PublishTopic string PubsubTopic *pubsub.Topic Concurrency int } func NewConfig(args []string) (*Config, error) { var config = new(Config) fs := flag.NewFlagSet("syncedobjectctl", flag.ExitOnError) fs.StringVar( &config.GCPProjectID, "gcp-project-id", "", "GCP Project ID that PubSub topic resides in", ) fs.StringVar( &config.MetricsAddr, "metrics-addr", os.Getenv("METRICS_ADDR"), "The address where prometheus metrics are hosted. Defaults to the value of METRICS_ADDR", ) fs.StringVar( &config.PublishTopic, "pubsub-publish-topic", "chariot-rides", "PubSub topic to publish to", ) fs.IntVar( &config.Concurrency, "concurrency", 24, "Reconcile loop concurrency", ) if err := ff.Parse(fs, args[1:], ff.WithEnvVarNoPrefix()); err != nil { return nil, err } // The pubsub client and topic is created here so it can be dynamically updated in integration tests without complicating the syncedobject controller. client, err := pubsub.NewClient(context.Background(), config.GCPProjectID) if err != nil { return nil, err } config.PubsubTopic = client.Topic(config.PublishTopic) return config, nil }