-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split SnapshotCreate into Create/Wait methods (#4569)
* Split SnapshotCreate into Create/Wait methods This allows the caller to initiate snapshot creation and wait on completion separately * Cleanup * Add `skipWait` optional parameter The `CreateVolumeSnapshot` method will not wait for snapshot completion if this is set * Add a Snapshot Wait function (#4570) Allows the caller to wait for completion of a previously initiated snapshot operation. Also updated the e2e test blueprint
- Loading branch information
Vaibhav Kamra
authored and
Ilya Kislenko
committed
Dec 17, 2018
1 parent
977a152
commit 6ba94b9
Showing
9 changed files
with
203 additions
and
37 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
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,78 @@ | ||
package function | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/pkg/errors" | ||
|
||
kanister "github.com/kanisterio/kanister/pkg" | ||
"github.com/kanisterio/kanister/pkg/blockstorage" | ||
"github.com/kanisterio/kanister/pkg/blockstorage/awsebs" | ||
"github.com/kanisterio/kanister/pkg/blockstorage/getter" | ||
"github.com/kanisterio/kanister/pkg/param" | ||
) | ||
|
||
func init() { | ||
kanister.Register(&waitForSnapshotCompletionFunc{}) | ||
} | ||
|
||
var ( | ||
_ kanister.Func = (*waitForSnapshotCompletionFunc)(nil) | ||
) | ||
|
||
const ( | ||
WaitForSnapshotCompletionSnapshotsArg = "snapshots" | ||
) | ||
|
||
type waitForSnapshotCompletionFunc struct{} | ||
|
||
func (*waitForSnapshotCompletionFunc) Name() string { | ||
return "WaitForSnapshotCompletion" | ||
} | ||
|
||
func (*waitForSnapshotCompletionFunc) RequiredArgs() []string { | ||
return []string{WaitForSnapshotCompletionSnapshotsArg} | ||
} | ||
|
||
func (kef *waitForSnapshotCompletionFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]interface{}) (map[string]interface{}, error) { | ||
var snapshotinfo string | ||
if err := Arg(args, WaitForSnapshotCompletionSnapshotsArg, &snapshotinfo); err != nil { | ||
return nil, err | ||
} | ||
return nil, waitForSnapshotsCompletion(ctx, snapshotinfo, tp.Profile, getter.New()) | ||
} | ||
|
||
func waitForSnapshotsCompletion(ctx context.Context, snapshotinfo string, profile *param.Profile, getter getter.Getter) error { | ||
PVCData := []VolumeSnapshotInfo{} | ||
err := json.Unmarshal([]byte(snapshotinfo), &PVCData) | ||
if err != nil { | ||
return errors.Wrapf(err, "Could not decode JSON data") | ||
} | ||
for _, pvcInfo := range PVCData { | ||
config := make(map[string]string) | ||
switch pvcInfo.Type { | ||
case blockstorage.TypeEBS: | ||
if err = ValidateProfile(profile); err != nil { | ||
return errors.Wrap(err, "Profile validation failed") | ||
} | ||
config[awsebs.ConfigRegion] = pvcInfo.Region | ||
config[awsebs.AccessKeyID] = profile.Credential.KeyPair.ID | ||
config[awsebs.SecretAccessKey] = profile.Credential.KeyPair.Secret | ||
default: | ||
return errors.New("Storage provider not supported " + string(pvcInfo.Type)) | ||
} | ||
provider, err := getter.Get(pvcInfo.Type, config) | ||
if err != nil { | ||
return errors.Wrapf(err, "Could not get storage provider %v", pvcInfo.Type) | ||
} | ||
snapshot, err := provider.SnapshotGet(ctx, pvcInfo.SnapshotID) | ||
if err != nil { | ||
return errors.Wrapf(err, "Failed to get Snapshot from Provider") | ||
} | ||
if err = provider.SnapshotCreateWaitForCompletion(ctx, snapshot); err != nil { | ||
return errors.Wrap(err, "Snapshot creation did not complete "+snapshot.ID) | ||
} | ||
} | ||
return nil | ||
} |
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,55 @@ | ||
package function | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
. "gopkg.in/check.v1" | ||
|
||
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1" | ||
"github.com/kanisterio/kanister/pkg/blockstorage" | ||
"github.com/kanisterio/kanister/pkg/param" | ||
"github.com/kanisterio/kanister/pkg/testutil/mockblockstorage" | ||
) | ||
|
||
type WaitForSnapshotCompletionTestSuite struct{} | ||
|
||
var _ = Suite(&WaitForSnapshotCompletionTestSuite{}) | ||
|
||
func (s *WaitForSnapshotCompletionTestSuite) TestWait(c *C) { | ||
ctx := context.Background() | ||
mockGetter := mockblockstorage.NewGetter() | ||
profile := ¶m.Profile{ | ||
Location: crv1alpha1.Location{ | ||
Type: crv1alpha1.LocationTypeS3Compliant, | ||
S3Compliant: &crv1alpha1.S3CompliantLocation{ | ||
Region: "us-west-2"}, | ||
}, | ||
Credential: param.Credential{ | ||
Type: param.CredentialTypeKeyPair, | ||
KeyPair: ¶m.KeyPair{ | ||
ID: "foo", | ||
Secret: "bar", | ||
}, | ||
}, | ||
} | ||
pvcData1 := []VolumeSnapshotInfo{ | ||
VolumeSnapshotInfo{SnapshotID: "snap-1", Type: blockstorage.TypeEBS, Region: "us-west-2", PVCName: "pvc-1", Az: "us-west-2a", VolumeType: "ssd"}, | ||
VolumeSnapshotInfo{SnapshotID: "snap-2", Type: blockstorage.TypeEBS, Region: "us-west-2", PVCName: "pvc-2", Az: "us-west-2a", VolumeType: "ssd"}, | ||
} | ||
info, err := json.Marshal(pvcData1) | ||
c.Assert(err, IsNil) | ||
snapinfo := string(info) | ||
for _, tc := range []struct { | ||
snapshotinfo string | ||
check Checker | ||
}{ | ||
{ | ||
snapshotinfo: snapinfo, | ||
check: IsNil, | ||
}, | ||
} { | ||
err := waitForSnapshotsCompletion(ctx, tc.snapshotinfo, profile, mockGetter) | ||
c.Assert(err, tc.check) | ||
} | ||
} |
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