...

Source file src/edge-infra.dev/pkg/edge/controllers/syncedobject/config.go

Documentation: edge-infra.dev/pkg/edge/controllers/syncedobject

     1  package syncedobject
     2  
     3  import (
     4  	"context"
     5  	"flag"
     6  	"os"
     7  
     8  	"cloud.google.com/go/pubsub"
     9  	"github.com/peterbourgon/ff/v3"
    10  )
    11  
    12  type Config struct {
    13  	MetricsAddr  string
    14  	GCPProjectID string
    15  	PublishTopic string
    16  
    17  	PubsubTopic *pubsub.Topic
    18  	Concurrency int
    19  }
    20  
    21  func NewConfig(args []string) (*Config, error) {
    22  	var config = new(Config)
    23  
    24  	fs := flag.NewFlagSet("syncedobjectctl", flag.ExitOnError)
    25  
    26  	fs.StringVar(
    27  		&config.GCPProjectID,
    28  		"gcp-project-id",
    29  		"",
    30  		"GCP Project ID that PubSub topic resides in",
    31  	)
    32  	fs.StringVar(
    33  		&config.MetricsAddr,
    34  		"metrics-addr",
    35  		os.Getenv("METRICS_ADDR"),
    36  		"The address where prometheus metrics are hosted. Defaults to the value of METRICS_ADDR",
    37  	)
    38  	fs.StringVar(
    39  		&config.PublishTopic,
    40  		"pubsub-publish-topic",
    41  		"chariot-rides",
    42  		"PubSub topic to publish to",
    43  	)
    44  	fs.IntVar(
    45  		&config.Concurrency,
    46  		"concurrency",
    47  		24,
    48  		"Reconcile loop concurrency",
    49  	)
    50  
    51  	if err := ff.Parse(fs, args[1:], ff.WithEnvVarNoPrefix()); err != nil {
    52  		return nil, err
    53  	}
    54  
    55  	// The pubsub client and topic is created here so it can be dynamically updated in integration tests without complicating the syncedobject controller.
    56  	client, err := pubsub.NewClient(context.Background(), config.GCPProjectID)
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  	config.PubsubTopic = client.Topic(config.PublishTopic)
    61  
    62  	return config, nil
    63  }
    64  

View as plain text