Skip to content

Commit

Permalink
This commit adds the test code to verify backup REST endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: mittachaitu <[email protected]>
  • Loading branch information
mittachaitu committed Jun 1, 2020
1 parent 37345f3 commit 0dbaa38
Show file tree
Hide file tree
Showing 7 changed files with 679 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pkg/controllers/cstorvolumeconfig/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
leader "github.com/openebs/api/pkg/kubernetes/leaderelection"
server "github.com/openebs/cstor-operators/pkg/server"
cvcserver "github.com/openebs/cstor-operators/pkg/server/cstorvolumeconfig"
"github.com/openebs/cstor-operators/pkg/snapshot"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -185,7 +186,8 @@ func setupCVCServer(k8sclientset kubernetes.Interface, openebsClientset clientse

cvcServer := cvcserver.NewCVCServer(config, os.Stdout).
WithOpenebsClientSet(openebsClientset).
WithKubernetesClientSet(k8sclientset)
WithKubernetesClientSet(k8sclientset).
WithSnapshoter(&snapshot.SnapClient{})

// Setup the HTTP server
http, err := cvcserver.NewHTTPServer(cvcServer)
Expand Down
6 changes: 5 additions & 1 deletion pkg/server/cstorvolumeconfig/backup_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type backupAPIOps struct {
resp http.ResponseWriter
k8sclientset kubernetes.Interface
clientset clientset.Interface
snapshoter snapshot.Snapshoter
}

var (
Expand All @@ -58,6 +59,7 @@ func (s *HTTPServer) backupV1alpha1SpecificRequest(resp http.ResponseWriter, req
resp: resp,
k8sclientset: s.cvcServer.kubeclientset,
clientset: s.cvcServer.clientset,
snapshoter: s.cvcServer.snapshoter,
}

switch req.Method {
Expand Down Expand Up @@ -92,6 +94,7 @@ func (bOps *backupAPIOps) create() (interface{}, error) {
VolumeName: backUp.Spec.VolumeName,
SnapshotName: backUp.Spec.SnapName,
Namespace: getOpenEBSNamespace(),
SnapClient: bOps.snapshoter,
}
snapResp, err := snapshot.CreateSnapshot(bOps.clientset)
if err != nil {
Expand Down Expand Up @@ -267,6 +270,7 @@ func (bOps *backupAPIOps) deleteBackup(backup, volname, ns, schedule string) err
VolumeName: volname,
SnapshotName: backup,
Namespace: ns,
SnapClient: bOps.snapshoter,
}
// Snapshot Name and backup name are same
_, err = snapshot.DeleteSnapshot(bOps.clientset)
Expand Down Expand Up @@ -510,7 +514,7 @@ func fetchPoolManagerFromCSPI(k8sclientset kubernetes.Interface, cspiName string
if len(podList.Items) != 1 {
return nil, errors.Errorf("expected 1 pool manager but got %d pool managers", len(podList.Items))
}
return nil, errors.Errorf("No pool manager exists for CSPI %s", cspiName)
return &podList.Items[0], nil
}

// TODO: Move below functions into API because there kind of getter methods.
Expand Down
Loading

0 comments on commit 0dbaa38

Please sign in to comment.