Skip to content

Commit

Permalink
Add Azure ObjectStore support to kanister (#5753)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten authored and Alex Vorbau committed Jun 6, 2019
1 parent bd17a14 commit 5292adb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pkg/blockstorage/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (

// Google Cloud environment variable names
const (
GoogleCloudZone = "CLOUDSDK_COMPUTE_ZONE"
GoogleCloudCreds = "GOOGLE_APPLICATION_CREDENTIALS"
GoogleProjectID = "projectID"
GoogleServiceKey = "serviceKey"
GoogleCloudZone = "CLOUDSDK_COMPUTE_ZONE"
GoogleCloudCreds = "GOOGLE_APPLICATION_CREDENTIALS"
GoogleProjectID = "projectID"
GoogleServiceKey = "serviceKey"
AzureStorageAccount = "AZURE_STORAGE_ACCOUNT_NAME"
AzureStorageKey = "AZURE_STORAGE_ACCOUNT_KEY"
)

// SanitizeTags are used to sanitize the tags
Expand Down
8 changes: 8 additions & 0 deletions pkg/location/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func getProviderType(lType crv1alpha1.LocationType) (objectstore.ProviderType, e
return objectstore.ProviderTypeS3, nil
case crv1alpha1.LocationTypeGCS:
return objectstore.ProviderTypeGCS, nil
case crv1alpha1.LocationTypeAzure:
return objectstore.ProviderTypeAzure, nil
default:
return "", errors.Errorf("Unsupported Location type: %s", lType)
}
Expand Down Expand Up @@ -136,6 +138,12 @@ func getOSSecret(pType objectstore.ProviderType, cred param.Credential) (*object
ProjectID: cred.KeyPair.ID,
ServiceKey: cred.KeyPair.Secret,
}
case objectstore.ProviderTypeAzure:
secret.Type = objectstore.SecretTypeAzStorageAccount
secret.Azure = &objectstore.SecretAzure{
StorageAccount: cred.KeyPair.ID,
StorageKey: cred.KeyPair.Secret,
}
default:
return nil, errors.Errorf("unknown or unsupported provider type '%s'", pType)
}
Expand Down
14 changes: 10 additions & 4 deletions pkg/location/location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
. "gopkg.in/check.v1"

crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/blockstorage"
"github.com/kanisterio/kanister/pkg/objectstore"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/testutil"
Expand All @@ -36,6 +37,7 @@ const (

var _ = Suite(&LocationSuite{osType: objectstore.ProviderTypeS3, region: testRegionS3})
var _ = Suite(&LocationSuite{osType: objectstore.ProviderTypeGCS, region: ""})
var _ = Suite(&LocationSuite{osType: objectstore.ProviderTypeAzure, region: ""})

func (s *LocationSuite) SetUpSuite(c *C) {
var location crv1alpha1.Location
Expand All @@ -45,19 +47,23 @@ func (s *LocationSuite) SetUpSuite(c *C) {
testutil.GetEnvOrSkip(c, AWSSecretAccessKey)
location = crv1alpha1.Location{
Type: crv1alpha1.LocationTypeS3Compliant,
Bucket: testBucketName,
Region: s.region,
}
case objectstore.ProviderTypeGCS:
testutil.GetEnvOrSkip(c, GoogleCloudCreds)
location = crv1alpha1.Location{
Type: crv1alpha1.LocationTypeGCS,
Bucket: testBucketName,
Type: crv1alpha1.LocationTypeGCS,
}
case objectstore.ProviderTypeAzure:
testutil.GetEnvOrSkip(c, blockstorage.AzureStorageAccount)
testutil.GetEnvOrSkip(c, blockstorage.AzureStorageKey)
location = crv1alpha1.Location{
Type: crv1alpha1.LocationTypeAzure,
}
default:
c.Fatalf("Unrecognized objectstore '%s'", s.osType)
}

location.Bucket = testBucketName
s.profile = *testutil.ObjectStoreProfileOrSkip(c, s.osType, location)
var err error
ctx := context.Background()
Expand Down
3 changes: 3 additions & 0 deletions pkg/testutil/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func ObjectStoreProfileOrSkip(c *check.C, osType objectstore.ProviderType, locat
c.Check(err, check.IsNil)
key = creds.ProjectID
val = string(creds.JSON)
case objectstore.ProviderTypeAzure:
key = GetEnvOrSkip(c, blockstorage.AzureStorageAccount)
val = GetEnvOrSkip(c, blockstorage.AzureStorageKey)
}
return &param.Profile{
Location: location,
Expand Down

0 comments on commit 5292adb

Please sign in to comment.