Skip to content

Commit

Permalink
Merge pull request #168 from kanisterio/sync
Browse files Browse the repository at this point in the history
Kanister profile update; Fix locationDelete func;
  • Loading branch information
SupriyaKasten authored May 6, 2019
2 parents 99ebec3 + f7e5e27 commit 0c6ecf2
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 33 deletions.
6 changes: 3 additions & 3 deletions helm/profile/templates/profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ metadata:
location:
type: {{ .Values.location.type | quote }}
bucket: {{ .Values.location.bucket | quote }}
endpoint: {{ .Values.location.endpoint | quote }}
prefix: {{ .Values.location.prefix | quote }}
region: {{ .Values.location.region | quote }}
endpoint: {{ .Values.location.endpoint }}
prefix: {{ .Values.location.prefix }}
region: {{ .Values.location.region }}
credential:
type: keyPair
keyPair:
Expand Down
6 changes: 3 additions & 3 deletions helm/profile/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ profileName:
location:
type:
bucket:
endpoint:
prefix:
region:
endpoint: ""
prefix: ""
region: ""

aws:
accessKey:
Expand Down
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
2 changes: 1 addition & 1 deletion pkg/kube/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (s *JobSuite) TestJobsWaitOnNonExistentJob(c *C) {

// Call WaitForCompletion on non-existent kubernetes job.
err = job.WaitForCompletion(context.Background())
c.Assert(c, NotNil)
c.Assert(err, NotNil)
}

func (s *JobSuite) TestJobsVolumes(c *C) {
Expand Down
36 changes: 16 additions & 20 deletions pkg/kube/pod_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,34 @@ import (

// PodWriter specifies Kubernetes Client and the other params needed for writing content to a file
type PodWriter struct {
cli kubernetes.Interface
namespace string
path string
podName string
containerName string
cli kubernetes.Interface
path string
content io.Reader
}

// NewPodWriter returns a new PodWriter given Kubernetes Client, Namespace, path of file, name of pod and container
func NewPodWriter(cli kubernetes.Interface, namespace, path, podName, containerName string) *PodWriter {
// NewPodWriter returns a new PodWriter given Kubernetes Client, path of file and content
func NewPodWriter(cli kubernetes.Interface, path string, content io.Reader) *PodWriter {
return &PodWriter{
cli: cli,
namespace: namespace,
path: filepath.Clean(path),
podName: podName,
containerName: containerName,
cli: cli,
path: filepath.Clean(path),
content: content,
}
}

// Write will create a new file(if not present) and write the provided content to the file
func (p *PodWriter) Write(ctx context.Context, content io.Reader) error {
func (p *PodWriter) Write(ctx context.Context, namespace, podName, containerName string) error {
cmd := []string{"sh", "-c", "cat - > " + p.path}
stdout, stderr, err := Exec(p.cli, p.namespace, p.podName, p.containerName, cmd, content)
format.Log(p.podName, p.containerName, stdout)
format.Log(p.podName, p.containerName, stderr)
stdout, stderr, err := Exec(p.cli, namespace, podName, containerName, cmd, p.content)
format.Log(podName, containerName, stdout)
format.Log(podName, containerName, stderr)
return errors.Wrap(err, "Failed to write contents to file")
}

// Remove will delete the file created by Write() func
func (p *PodWriter) Remove(ctx context.Context) error {
func (p *PodWriter) Remove(ctx context.Context, namespace, podName, containerName string) error {
cmd := []string{"sh", "-c", "rm " + p.path}
stdout, stderr, err := Exec(p.cli, p.namespace, p.podName, p.containerName, cmd, nil)
format.Log(p.podName, p.containerName, stdout)
format.Log(p.podName, p.containerName, stderr)
stdout, stderr, err := Exec(p.cli, namespace, podName, containerName, cmd, nil)
format.Log(podName, containerName, stdout)
format.Log(podName, containerName, stderr)
return errors.Wrap(err, "Failed to delete file")
}
6 changes: 3 additions & 3 deletions pkg/kube/pod_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ func (p *PodWriteSuite) TestPodWriter(c *C) {
c.Assert(p.pod.Status.Phase, Equals, v1.PodRunning)
c.Assert(len(p.pod.Status.ContainerStatuses) > 0, Equals, true)
for _, cs := range p.pod.Status.ContainerStatuses {
pw := NewPodWriter(p.cli, p.pod.Namespace, path, p.pod.Name, cs.Name)
err := pw.Write(context.Background(), bytes.NewBufferString("badabing"))
pw := NewPodWriter(p.cli, path, bytes.NewBufferString("badabing"))
err := pw.Write(context.Background(), p.pod.Namespace, p.pod.Name, cs.Name)
c.Assert(err, IsNil)
cmd := []string{"sh", "-c", "cat " + pw.path}
stdout, stderr, err := Exec(p.cli, p.pod.Namespace, p.pod.Name, cs.Name, cmd, nil)
c.Assert(err, IsNil)
c.Assert(stdout, Equals, "badabing")
c.Assert(stderr, Equals, "")
err = pw.Remove(context.Background())
err = pw.Remove(context.Background(), p.pod.Namespace, p.pod.Name, cs.Name)
c.Assert(err, IsNil)
}
}

0 comments on commit 0c6ecf2

Please sign in to comment.