feat: add a config option for custom GCS endpoints (#16419)

pull/16414/head
Ned Andreev 1 year ago committed by GitHub
parent 022b45c7a9
commit f1ebd970e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      docs/sources/shared/configuration.md
  2. 6
      pkg/storage/chunk/client/gcp/gcs_object_client.go

@ -2419,6 +2419,10 @@ The `gcs_storage_config` block configures the connection to Google Cloud Storage
# CLI flag: -<prefix>.gcs.bucketname
[bucket_name: <string> | default = ""]
# Custom GCS endpoint URL.
# CLI flag: -<prefix>.gcs.endpoint
[endpoint: <string> | default = ""]
# Service account key content in JSON format, refer to
# https://cloud.google.com/iam/docs/creating-managing-service-account-keys for
# creation.

@ -37,6 +37,7 @@ type GCSObjectClient struct {
// GCSConfig is config for the GCS Chunk Client.
type GCSConfig struct {
BucketName string `yaml:"bucket_name"`
Endpoint string `yaml:"endpoint"`
ServiceAccount flagext.Secret `yaml:"service_account"`
ChunkBufferSize int `yaml:"chunk_buffer_size"`
RequestTimeout time.Duration `yaml:"request_timeout"`
@ -57,6 +58,7 @@ func (cfg *GCSConfig) RegisterFlags(f *flag.FlagSet) {
// RegisterFlagsWithPrefix registers flags with prefix.
func (cfg *GCSConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.StringVar(&cfg.BucketName, prefix+"gcs.bucketname", "", "Name of GCS bucket. Please refer to https://cloud.google.com/docs/authentication/production for more information about how to configure authentication.")
f.StringVar(&cfg.Endpoint, prefix+"gcs.endpoint", "", "Custom GCS endpoint URL.")
f.Var(&cfg.ServiceAccount, prefix+"gcs.service-account", "Service account key content in JSON format, refer to https://cloud.google.com/iam/docs/creating-managing-service-account-keys for creation.")
f.IntVar(&cfg.ChunkBufferSize, prefix+"gcs.chunk-buffer-size", 0, "The size of the buffer that GCS client for each PUT request. 0 to disable buffering.")
f.DurationVar(&cfg.RequestTimeout, prefix+"gcs.request-timeout", 0, "The duration after which the requests to GCS should be timed out.")
@ -109,6 +111,10 @@ func newBucketHandle(ctx context.Context, cfg GCSConfig, hedgingCfg hedging.Conf
opts = append(opts, option.WithTelemetryDisabled())
}
if cfg.Endpoint != "" {
opts = append(opts, option.WithEndpoint(cfg.Endpoint))
}
client, err := clientFactory(ctx, opts...)
if err != nil {
return nil, err

Loading…
Cancel
Save