-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in empty implementation of AKSBucketProvider
Implemented Container Exists check Implemented Azure container creation Added in logic to retrieve storage account keys Encapsulated the storage account parsing down close the CLI which appears to be the only part that requires them as separate arguments Fixing up houndci review
- Loading branch information
Chris Mellard
committed
Jul 18, 2020
1 parent
28c81d9
commit 15e49ee
Showing
3 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package storage | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jenkins-x/jx-logging/pkg/log" | ||
"github.com/jenkins-x/jx/v2/pkg/cloud/aks" | ||
"github.com/jenkins-x/jx/v2/pkg/cloud/buckets" | ||
"github.com/jenkins-x/jx/v2/pkg/config" | ||
"github.com/jenkins-x/jx/v2/pkg/util" | ||
"github.com/pkg/errors" | ||
uuid "github.com/satori/go.uuid" | ||
"io" | ||
"strings" | ||
) | ||
|
||
type AKSBucketProvider struct { | ||
Requirements *config.RequirementsConfig | ||
AzureStorage aks.AzureStorage | ||
} | ||
|
||
// CreateNewBucketForCluster creates a new dynamic bucket | ||
func (b *AKSBucketProvider) CreateNewBucketForCluster(clusterName string, bucketKind string) (string, error) { | ||
uuid4, _ := uuid.NewV4() | ||
bucketName := fmt.Sprintf("%s-%s-%s", clusterName, bucketKind, uuid4.String()) | ||
|
||
// Max length is 63, https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata | ||
if len(bucketName) > 63 { | ||
bucketName = bucketName[:63] | ||
} | ||
bucketName = strings.TrimRight(bucketName, "-") | ||
bucketURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s", b.Requirements.Velero.ServiceAccount, bucketName) | ||
err := b.EnsureBucketIsCreated(bucketURL) | ||
if err != nil { | ||
return bucketURL, errors.Wrapf(err, "failed to create bucket %s", bucketURL) | ||
} | ||
|
||
return bucketURL, nil | ||
} | ||
|
||
// EnsureBucketIsCreated ensures the bucket URL is created | ||
func (b *AKSBucketProvider) EnsureBucketIsCreated(bucketURL string) error { | ||
|
||
exists, err := b.AzureStorage.ContainerExists(bucketURL) | ||
if err != nil { | ||
return errors.Wrap(err, "checking if the provided container exists") | ||
} | ||
if exists { | ||
return nil | ||
} | ||
|
||
log.Logger().Infof("The bucket %s does not exist so lets create it", util.ColorInfo(bucketURL)) | ||
err = b.AzureStorage.CreateContainer(bucketURL) | ||
if err != nil { | ||
return errors.Wrapf(err, "there was a problem creating the bucket with URL %s", | ||
bucketURL) | ||
} | ||
return nil | ||
} | ||
|
||
// UploadFileToBucket is yet to be implemented for this provider | ||
func (b *AKSBucketProvider) UploadFileToBucket(r io.Reader, outputName string, bucketURL string) (string, error) { | ||
return "", nil | ||
} | ||
|
||
// DownloadFileFromBucket is yet to be implemented for this provider | ||
func (b *AKSBucketProvider) DownloadFileFromBucket(bucketURL string) (io.ReadCloser, error) { | ||
return nil, nil | ||
} | ||
|
||
// NewAKSBucketProvider create a new provider for AKS | ||
func NewAKSBucketProvider(requirements *config.RequirementsConfig) buckets.Provider { | ||
return &AKSBucketProvider{ | ||
Requirements: requirements, | ||
AzureStorage: aks.NewAzureRunner(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters