-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Google Object Store Support to Kanister (#4923)
* Add Google Object Store Support to Kanister * Added unit test * Address review comments, add unit tests * undo kando location push changes to get size
- Loading branch information
1 parent
27911ba
commit 2451822
Showing
5 changed files
with
222 additions
and
31 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
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
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 |
---|---|---|
@@ -1,47 +1,54 @@ | ||
package testutil | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"golang.org/x/oauth2/google" | ||
compute "google.golang.org/api/compute/v1" | ||
"gopkg.in/check.v1" | ||
|
||
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1" | ||
"github.com/kanisterio/kanister/pkg/location" | ||
"github.com/kanisterio/kanister/pkg/blockstorage" | ||
"github.com/kanisterio/kanister/pkg/blockstorage/awsebs" | ||
"github.com/kanisterio/kanister/pkg/objectstore" | ||
"github.com/kanisterio/kanister/pkg/param" | ||
) | ||
|
||
const testBucketName = "S3_TEST_BUCKET" | ||
const TestS3BucketName = "S3_TEST_BUCKET" | ||
|
||
var objectStoreTestEnvVars []string = []string{ | ||
location.AWSAccessKeyID, | ||
location.AWSSecretAccessKey, | ||
testBucketName, | ||
} | ||
func ObjectStoreProfileOrSkip(c *check.C, osType objectstore.ProviderType, location crv1alpha1.Location) *param.Profile { | ||
var key, val string | ||
|
||
func ObjectStoreProfileOrSkip(c *check.C) *param.Profile { | ||
skipIfEnvNotSet(c, objectStoreTestEnvVars) | ||
switch osType { | ||
case objectstore.ProviderTypeS3: | ||
key = GetEnvOrSkip(c, awsebs.AccessKeyID) | ||
val = GetEnvOrSkip(c, awsebs.SecretAccessKey) | ||
case objectstore.ProviderTypeGCS: | ||
GetEnvOrSkip(c, blockstorage.GoogleCloudCreds) | ||
creds, err := google.FindDefaultCredentials(context.Background(), compute.ComputeScope) | ||
c.Check(err, check.IsNil) | ||
key = creds.ProjectID | ||
val = string(creds.JSON) | ||
} | ||
return ¶m.Profile{ | ||
Location: crv1alpha1.Location{ | ||
Type: crv1alpha1.LocationTypeS3Compliant, | ||
Bucket: os.Getenv(testBucketName), | ||
Prefix: c.TestName(), | ||
}, | ||
Location: location, | ||
Credential: param.Credential{ | ||
Type: param.CredentialTypeKeyPair, | ||
KeyPair: ¶m.KeyPair{ | ||
ID: os.Getenv(location.AWSAccessKeyID), | ||
Secret: os.Getenv(location.AWSSecretAccessKey), | ||
ID: key, | ||
Secret: val, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func skipIfEnvNotSet(c *check.C, envVars []string) { | ||
for _, ev := range envVars { | ||
if os.Getenv(ev) == "" { | ||
reason := fmt.Sprintf("Test %s requires the environemnt variable '%s'", c.TestName(), ev) | ||
c.Skip(reason) | ||
} | ||
func GetEnvOrSkip(c *check.C, varName string) string { | ||
v := os.Getenv(varName) | ||
if v == "" { | ||
reason := fmt.Sprintf("Test %s requires the environemnt variable '%s'", c.TestName(), varName) | ||
c.Skip(reason) | ||
} | ||
return v | ||
} |