Skip to content

Commit

Permalink
Fix location delete (#5539)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten authored and Ilya Kislenko committed May 3, 2019
1 parent 3ae0a28 commit 15cb770
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 24 additions & 1 deletion pkg/function/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,26 @@ func newBackupDataBlueprint() *crv1alpha1.Blueprint {
}
}

func (s *DataSuite) TestBackupRestoreData(c *C) {
func newLocationDeleteBlueprint() *crv1alpha1.Blueprint {
return &crv1alpha1.Blueprint{
Actions: map[string]*crv1alpha1.BlueprintAction{
"delete": &crv1alpha1.BlueprintAction{
Kind: param.StatefulSetKind,
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testLocationDelete",
Func: "LocationDelete",
Args: map[string]interface{}{
LocationDeleteArtifactArg: "{{ .Profile.Location.Bucket }}",
},
},
},
},
},
}
}

func (s *DataSuite) TestBackupRestoreDeleteData(c *C) {
ctx := context.Background()
ss, err := s.cli.AppsV1().StatefulSets(s.namespace).Create(testutil.NewTestStatefulSet())
c.Assert(err, IsNil)
Expand Down Expand Up @@ -166,6 +185,7 @@ func (s *DataSuite) TestBackupRestoreData(c *C) {

location := crv1alpha1.Location{
Type: crv1alpha1.LocationTypeS3Compliant,
Prefix: "testBackupRestoreLocDelete",
Bucket: testutil.GetEnvOrSkip(c, testutil.TestS3BucketName),
}
tp.Profile = testutil.ObjectStoreProfileOrSkip(c, objectstore.ProviderTypeS3, location)
Expand All @@ -185,6 +205,9 @@ func (s *DataSuite) TestBackupRestoreData(c *C) {
// Test restore
bp = *newRestoreDataBlueprint(pvc.GetName(), RestoreDataBackupTagArg, BackupDataOutputBackupTag)
_ = runAction(c, bp, "restore", tp)

bp = *newLocationDeleteBlueprint()
_ = runAction(c, bp, "delete", tp)
}

func (s *DataSuite) TestBackupRestoreDataWithSnapshotID(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/function/location_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package function

import (
"context"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -37,8 +38,7 @@ func (*locationDeleteFunc) Exec(ctx context.Context, tp param.TemplateParams, ar
if err = validateProfile(tp.Profile); err != nil {
return nil, errors.Wrapf(err, "Failed to validate Profile")
}

return nil, location.Delete(ctx, *tp.Profile, artifact)
return nil, location.Delete(ctx, *tp.Profile, strings.TrimPrefix(artifact, tp.Profile.Location.Bucket))
}

func (*locationDeleteFunc) RequiredArgs() []string {
Expand Down

0 comments on commit 15cb770

Please sign in to comment.