Skip to content

Commit

Permalink
Stash V1beta1 E2E test for StatefulSet (#737)
Browse files Browse the repository at this point in the history
xref: #707

Tasks:
- [x] Workload backup and restore for Statefulset
  • Loading branch information
suaas21 authored and tamalsaha committed Apr 12, 2019
1 parent 37087b3 commit a2534c9
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 39 deletions.
2 changes: 1 addition & 1 deletion test/e2e/framework/backup_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (f *Invocation) BackupConfiguration(repoName string, targetref v1beta1.Targ
Repository: core.LocalObjectReference{
Name: repoName,
},
Schedule: "*/2 * * * *",
Schedule: "*/3 * * * *",
Target: &v1beta1.Target{
Ref: targetref,
Directories: []string{
Expand Down
12 changes: 11 additions & 1 deletion test/e2e/framework/backup_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (f *Framework) EventuallyBackupSessionCreated(meta metav1.ObjectMeta) Gomeg
}
return false
},
time.Minute*2,
time.Minute*7,
time.Second*5,
)
}
Expand All @@ -44,3 +44,13 @@ func (f *Framework) GetBackupSession(meta metav1.ObjectMeta) (*v1beta1.BackupSes
}
return nil,fmt.Errorf("no BackupSession found")
}

func (f *Framework) EventuallyBackupSessionTotalHost(meta metav1.ObjectMeta) GomegaAsyncAssertion {
return Eventually(
func() (totalhost *int32) {
bs, err := f.StashClient.StashV1beta1().BackupSessions(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
return bs.Status.TotalHosts
},
)
}
6 changes: 3 additions & 3 deletions test/e2e/framework/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ func (f *Framework) GetPod(meta metav1.ObjectMeta) (*core.Pod, error) {
}

func (f *Framework) GetAllPod(meta metav1.ObjectMeta) ([]core.Pod, error) {
pods := make([]core.Pod,0)
pods := make([]core.Pod, 0)
labelSelector := fields.SelectorFromSet(meta.Labels)
podList, err := f.KubeClient.CoreV1().Pods(meta.Namespace).List(metav1.ListOptions{LabelSelector: labelSelector.String()})
if err != nil {
return nil, err
}
for _, pod := range podList.Items {
if strings.HasPrefix(pod.Name, meta.Name) {
pods = append(pods,pod)
pods = append(pods, pod)
}
}
if len(pods) > 0{
if len(pods) > 0 {
return pods, nil
}
return nil, fmt.Errorf("no pod found for workload %v", meta.Name)
Expand Down
1 change: 0 additions & 1 deletion test/e2e/framework/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,3 @@ func (f *Framework) ReadDataFromMountedDir(meta metav1.ObjectMeta, paths []strin
}
return datas, nil
}

17 changes: 8 additions & 9 deletions test/e2e/framework/restore_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (f *Invocation) RestoreSession(repoName string, targetref v1beta1.TargetRef) v1beta1.RestoreSession {
func (f *Invocation) RestoreSession(repoName string, targetref v1beta1.TargetRef, rules []v1beta1.Rule) v1beta1.RestoreSession {
return v1beta1.RestoreSession{
ObjectMeta: metav1.ObjectMeta{
Name: rand.WithUniqSuffix(f.app),
Expand All @@ -20,13 +20,7 @@ func (f *Invocation) RestoreSession(repoName string, targetref v1beta1.TargetRef
Repository: core.LocalObjectReference{
Name: repoName,
},
Rules: []v1beta1.Rule{
{
Paths: []string{
TestSourceDataMountPath,
},
},
},
Rules: rules,
Target: &v1beta1.Target{
Ref: targetref,
VolumeMounts: []core.VolumeMount{
Expand All @@ -45,13 +39,18 @@ func (f *Invocation) CreateRestoreSession(restoreSession v1beta1.RestoreSession)
return err
}

func (f Invocation) DeleteRestoreSession(meta metav1.ObjectMeta) error{
_,err := f.StashClient.StashV1beta1().RestoreSessions(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
return err
}

func (f *Framework) EventuallyRestoreSessionPhase(meta metav1.ObjectMeta) GomegaAsyncAssertion {
return Eventually(func() v1beta1.RestoreSessionPhase {
restoreSession, err := f.StashClient.StashV1beta1().RestoreSessions(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
return restoreSession.Status.Phase
},
time.Minute*7,
time.Minute*5,
time.Second*5,
)
}
65 changes: 65 additions & 0 deletions test/e2e/framework/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/appscode/go/types"
. "github.com/onsi/gomega"
apps "k8s.io/api/apps/v1"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -33,6 +35,69 @@ func (fi *Invocation) StatefulSet(pvcName string) apps.StatefulSet {
}
}

func (fi *Invocation) StatefulSetForV1beta1API() apps.StatefulSet {
labels := map[string]string{
"app": fi.app,
"kind": "statefulset",
}
return apps.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: rand.WithUniqSuffix("stash"),
Namespace: fi.namespace,
Labels: labels,
},
Spec: apps.StatefulSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Replicas: types.Int32P(3),
ServiceName: TEST_HEADLESS_SERVICE,
Template: core.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
},
Spec: core.PodSpec{
Containers: []core.Container{
{
Name: "busybox",
Image: "busybox",
ImagePullPolicy: core.PullIfNotPresent,
Command: []string{
"sleep",
"3600",
},
VolumeMounts: []core.VolumeMount{
{
Name: TestSourceDataVolumeName,
MountPath: TestSourceDataMountPath,
},
},
},
},
},
},
VolumeClaimTemplates: []core.PersistentVolumeClaim{
{
ObjectMeta: metav1.ObjectMeta{
Name: TestSourceDataVolumeName,
},
Spec: core.PersistentVolumeClaimSpec{
AccessModes: []core.PersistentVolumeAccessMode{
core.ReadWriteOnce,
},
StorageClassName: types.StringP(fi.StorageClass),
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceName(core.ResourceStorage): resource.MustParse("1Gi"),
},
},
},
},
},
},
}
}

func (f *Framework) CreateStatefulSet(obj apps.StatefulSet) (*apps.StatefulSet, error) {
return f.KubeClient.AppsV1().StatefulSets(obj.Namespace).Create(&obj)
}
Expand Down
19 changes: 18 additions & 1 deletion test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (f *Framework) ReadSampleDataFromMountedDirectory(meta metav1.ObjectMeta, p
for _, pod := range pods {
data, err := f.ExecOnPod(&pod, "ls", "-R", path)
if err != nil {
return datas, err
continue
}
datas = append(datas, data)
}
Expand Down Expand Up @@ -345,9 +345,26 @@ func GetPathsFromRestoreSession(restoreSession *v1beta1.RestoreSession) []string
paths = append(paths, p)
}
}
paths = removeDuplicates(paths)
return paths
}

func removeDuplicates(elements []string) []string {
encountered := map[string]bool{}

// Create a map of all unique elements.
for v:= range elements {
encountered[elements[v]] = true
}

// Place all keys from the map into a slice.
result := []string{}
for key, _ := range encountered {
result = append(result, key)
}
return result
}

func (f *Framework) EventuallyJobSucceed(name string) GomegaAsyncAssertion {
jobCreated := false
return Eventually(func() bool {
Expand Down
Loading

0 comments on commit a2534c9

Please sign in to comment.