Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(REST, CVC): add a support for rest service in CVC Operator #83

Merged
merged 11 commits into from
Jun 9, 2020

Conversation

mittachaitu
Copy link
Contributor

@mittachaitu mittachaitu commented May 27, 2020

This PR adds support for rest service in CVC operator and it adds the following functionality:

  • Add support for handling Create, Get and Delete operations on CStorBackup and CStorRestore APIS.

Sample Backup resource created by backup endpoint:

metadata:
  name: snapshot2-pv-687c169c-4ec5-4144-9bcb-a30b75882c56
  namespace: openebs
  labels:
    cstorpoolinstance.openebs.io/name: cspc-cstor-pool2-hh6c
    cstorpoolinstance.openebs.io/uid: 577c169c-4ec5-4144-9bcb-a30b75882ca4
    openebs.io/backup: backup2
    openebs.io/persistent-volume: pv-687c169c-4ec5-4144-9bcb-a30b75882c56
spec:
  backupName: backup2
  volumeName: pv-687c169c-4ec5-4144-9bcb-a30b75882c56
  snapName: snapshot2
  prevSnapName: ''"
  backupDest: 172.102.29.12:3234
  localSnap: false
status: Pending

Sample Restore resource created by restore endpoint:

metadata:
  name: restore1-577c169c-4ec5-4144-9bcb
  namespace: openebs
  labels:
    cstorpoolinstance.openebs.io/name: cspc-cstor-pool2-hh6c
    cstorpoolinstance.openebs.io/uid: 577c169c-4ec5-4144-9bcb-a30b75882ca4
    openebs.io/restore: backup2
    openebs.io/persistent-volume: pv-687c169c-4ec5-4144-9bcb-a30b75882c56
TODO: add spec details

Note:

  • This is the initial commit to support CSI volumes backup and restore.

Manual testing:

  • Deployed CStor-CSI setup and made curl request on CVC-Operator service to interact with REST endpoints.
  • Able to successfully create the local backup and restore.
  • Able to successfully create CStorBackup and CStorRestore CR's by making curl request.

TODO:

  • Unit Test for Restore endpoint will take in separate PR.

Issues:

Signed-off-by: mittachaitu sai.chaithanya@mayadata.io

@mittachaitu mittachaitu requested a review from sonasingh46 May 27, 2020 15:26
@mittachaitu mittachaitu self-assigned this May 28, 2020
@mittachaitu mittachaitu linked an issue May 28, 2020 that may be closed by this pull request
@mittachaitu mittachaitu changed the title [WIP] feat(REST, CVC): add a support for rest service in CVC Operator feat(REST, CVC): add a support for rest service in CVC Operator Jun 1, 2020

switch req.Method {
case "POST":
return backupOp.create()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us log for create request also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of logging here good to log in create method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why it is logged for Get and Delete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will log it.

Copy link
Contributor

@mynktl mynktl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good 👍


// constants
const (
VolumeGrpcListenPort = 7777
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment here. Better not to define VolumeGrpcListenPort value here, instead we can use it from API/some package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I will move it to openebs/api repo in subsequent PRs.

case "POST":
return backupOp.create()
case "GET":
klog.Infof("Got backup GET request")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to change level to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good point but I need to check which log level is best i.e for this entier repo we need to fix specific log levels like 1, 2, 4 for different levels verbose. So I will incorporate this in subsequent PRs.

pkg/server/cstorvolumeconfig/backup_endpoint.go Outdated Show resolved Hide resolved
pkg/server/cstorvolumeconfig/backup_endpoint.go Outdated Show resolved Hide resolved
pkg/server/cstorvolumeconfig/backup_endpoint.go Outdated Show resolved Hide resolved

// If cspiName is not empty then fetch the CStor pool pod using CSPI name
if cspiName == "" {
klog.Errorf("failed to find pool manager empty CSPI is provided")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
klog.Errorf("failed to find pool manager empty CSPI is provided")
klog.Errorf("failed to find pool manager, empty CSPI is provided")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


// If cspiName is not empty then fetch the CStor pool pod using CSPI name
if cspiName == "" {
klog.Errorf("failed to find pool manager empty CSPI is provided")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
klog.Errorf("failed to find pool manager empty CSPI is provided")
klog.Errorf("failed to find pool manager, empty CSPI is provided")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

return "", err
}

return cstorvolume.Spec.TargetIP, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there not a possibility of cstorvolume.Spec.TargetIP be empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is empty snap creation will fail. So backup will fail

volume string) (*cstorapis.CStorVolumeReplica, error) {
namespace := getOpenEBSNamespace()
listOptions := metav1.ListOptions{
LabelSelector: "openebs.io/persistent-volume=" + volume,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This label is hardcoded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with api constant

}

// getLastBackupSnap will fetch the last successful backup's snapshot name
func (bOps *backupAPIOps) getLastBackupSnap(backUp *openebsapis.CStorBackup) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is misleading in terms of what it does vs the comments and the function name.
ToDo: Next PR can improve this.

mittachaitu added 2 commits June 4, 2020 18:34
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
mittachaitu added 7 commits June 4, 2020 18:34
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Signed-off-by: mittachaitu <sai.chaithanya@mayadata.io>
Copy link
Contributor

@prateekpandey14 prateekpandey14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backup/Restore for CSI based volumes using CSPC pools with V1 APIs
4 participants