Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure: Add new storage_create_container configuration property #116

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#108](https://github.com/thanos-io/objstore/pull/108) Metrics: Add native histogram definitions to histograms
- [#112](https://github.com/thanos-io/objstore/pull/112) S3: Add `DisableDualstack option.
- [#100](https://github.com/thanos-io/objstore/pull/100) s3: add DisableMultipart option
- [#116](https://github.com/thanos-io/objstore/pull/116) Azure: Add new storage_create_container configuration property

### Changed
- [#38](https://github.com/thanos-io/objstore/pull/38) *: Upgrade minio-go version to `v7.0.45`.
Expand Down
25 changes: 14 additions & 11 deletions providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

// DefaultConfig for Azure objstore client.
var DefaultConfig = Config{
Endpoint: "blob.core.windows.net",
Endpoint: "blob.core.windows.net",
StorageCreateContainer: true,
HTTPConfig: exthttp.HTTPConfig{
IdleConnTimeout: model.Duration(90 * time.Second),
ResponseHeaderTimeout: model.Duration(2 * time.Minute),
Expand All @@ -47,6 +48,7 @@ type Config struct {
StorageAccountName string `yaml:"storage_account"`
StorageAccountKey string `yaml:"storage_account_key"`
StorageConnectionString string `yaml:"storage_connection_string"`
StorageCreateContainer bool `yaml:"storage_create_container"`
ContainerName string `yaml:"container"`
Endpoint string `yaml:"endpoint"`
UserAssignedID string `yaml:"user_assigned_id"`
Expand Down Expand Up @@ -167,19 +169,20 @@ func NewBucketWithConfig(logger log.Logger, conf Config, component string) (*Buc
}

// Check if storage account container already exists, and create one if it does not.
ctx := context.Background()
_, err = containerClient.GetProperties(ctx, &container.GetPropertiesOptions{})
if err != nil {
if !bloberror.HasCode(err, bloberror.ContainerNotFound) {
return nil, err
}
_, err := containerClient.Create(ctx, nil)
if conf.StorageCreateContainer {
ctx := context.Background()
_, err = containerClient.GetProperties(ctx, &container.GetPropertiesOptions{})
if err != nil {
return nil, errors.Wrapf(err, "error creating Azure blob container: %s", conf.ContainerName)
if !bloberror.HasCode(err, bloberror.ContainerNotFound) {
return nil, err
}
_, err := containerClient.Create(ctx, nil)
if err != nil {
return nil, errors.Wrapf(err, "error creating Azure blob container: %s", conf.ContainerName)
}
level.Info(logger).Log("msg", "Azure blob container successfully created", "address", conf.ContainerName)
}
level.Info(logger).Log("msg", "Azure blob container successfully created", "address", conf.ContainerName)
}

bkt := &Bucket{
logger: logger,
containerClient: containerClient,
Expand Down
Loading