Skip to content

Allow users to specify "storage-locations" for snapshots. #793

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

Merged
merged 1 commit into from
Jun 23, 2021

Conversation

TeweiLuo
Copy link
Contributor

Use a comma separated string, for example "us-central1,us-west1"
as the "snapshot-locations" field of snapshot class parameters.
See the PR for detailed examples.

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change
/kind bug
/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

/kind feature

What this PR does / why we need it:
Allow users to set storage locations[1] for their PD snapshots by specifying them in the snapshot class. For example:

apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshotClass
metadata:
  name: snapshot-class-with-storage-locations
parameters:
  storage-locations: us-central1
driver: pd.csi.storage.gke.io
deletionPolicy: Delete

Current the default location[2] will be used for all snapshots. GKE customers may have organization policies restricting the placement of snapshots that conflicts with the default location. This features will help customers to consistently apply their policies.

This parameter is described in the API document[3] for snapshots.

Which issue(s) this PR fixes:

Fixes #791

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Users will be able to set the storage locations for snapshots by specifying them in the snapshot class.

[1] https://cloud.google.com/compute/docs/disks/snapshots#custom_location
[2] https://cloud.google.com/compute/docs/disks/snapshots#default_location
[3] https://cloud.google.com/compute/docs/reference/rest/v1/snapshots

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jun 21, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: TeweiLuo
To complete the pull request process, please assign verult after the PR has been reviewed.
You can assign the PR to them by writing /assign @verult in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from davidz627 and verult June 21, 2021 18:56
@k8s-ci-robot
Copy link
Contributor

Hi @TeweiLuo. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 21, 2021
@TeweiLuo TeweiLuo force-pushed the snapshot-location branch from 2e8bfee to 2447112 Compare June 21, 2021 20:42
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 21, 2021
@TeweiLuo TeweiLuo force-pushed the snapshot-location branch from 2447112 to 8740db7 Compare June 21, 2021 20:59
@@ -73,7 +73,7 @@ type GCECompute interface {
ListZones(ctx context.Context, region string) ([]string, error)
ListSnapshots(ctx context.Context, filter string, maxEntries int64, pageToken string) ([]*computev1.Snapshot, string, error)
GetSnapshot(ctx context.Context, project, snapshotName string) (*computev1.Snapshot, error)
CreateSnapshot(ctx context.Context, project string, volKey *meta.Key, snapshotName string) (*computev1.Snapshot, error)
CreateSnapshot(ctx context.Context, project string, volKey *meta.Key, snapshotName string, storageLocations string) (*computev1.Snapshot, error)
Copy link
Member

Choose a reason for hiding this comment

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

I had a question about using an array but I checked that parameters is a map[string]string https://github.com/kubernetes-csi/external-snapshotter/blob/f255fe7b46bd5410370537319879d06f2bf1a156/client/apis/volumesnapshot/v1/types.go#L215, I don't know if users would do this though (NOTE the space between the comma and the other region):

parameters:
  storage-locations: us-central1, us-central2

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 21, 2021
@mauriciopoppe
Copy link
Member

Probably need to add an e2e test too

@TeweiLuo
Copy link
Contributor Author

Probably need to add an e2e test too

I'm not sure if this should be a k/k e2e test because this param is pd specific. Maybe a GKE internal test is better?

@mauriciopoppe
Copy link
Member

got it, I saw a few tests in test/e2e but they seem to be integration tests, sure having a test either here or in GKE internal would be nice

@mattcary
Copy link
Contributor

/okay-to-test

@mauriciopoppe
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 22, 2021
if req.GetParameters() != nil {
parameters = req.GetParameters()
}
snapshot, err = gceCS.CloudProvider.CreateSnapshot(ctx, project, volKey, req.Name, parameters[common.ParameterStorageLocations])
Copy link
Contributor

Choose a reason for hiding this comment

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

We should split, trim and validate the storage locations here (via a helper ftn of course). See for example common.ExtractAndDefaultParameters and its usages as a model.

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 was thinking about the same thing initially but

  1. It's debatable whether we should validate the regions themselves - the PD backend may change.
  2. If (1) is true, then there is no other validation, because every string can be treated as a comma-separated string.

Copy link
Contributor

Choose a reason for hiding this comment

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

discussed offline. The API takes a list of strings, so we definitely need to split on commas, so we should do that early. If we're splitting on commas, we need to trim whitespace, which means we should do a regexp validation of the location to make sure it's plausible. Things like validating the regions will be done over in the PD service anyway and not in the driver, even in the cloud provider.

@TeweiLuo TeweiLuo force-pushed the snapshot-location branch from 8740db7 to efae0fc Compare June 22, 2021 20:10
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 22, 2021
@TeweiLuo
Copy link
Contributor Author

Refactored to use a generalized SnapshotParameters struct and added normalization/validation of storage locations. Will add an e2e test.

@mauriciopoppe
Copy link
Member

lgtm :)

@mattcary
Copy link
Contributor

@TeweiLuo
Copy link
Contributor Author

Update: while the storageLocations argument for the snapshot REST API is of type []string but it must be one location only. The only documentation I found is this sentence

Determine your snapshot storage location. You can use the default storage location, or a custom storage location.

from this page. I'll amend the PR accordingly.

@TeweiLuo TeweiLuo force-pushed the snapshot-location branch from efae0fc to da03764 Compare June 23, 2021 20:39
@TeweiLuo
Copy link
Contributor Author

Can you

Doc updated.

@TeweiLuo TeweiLuo force-pushed the snapshot-location branch from da03764 to 60f462f Compare June 23, 2021 20:44
@TeweiLuo TeweiLuo force-pushed the snapshot-location branch from 60f462f to 31a8f87 Compare June 23, 2021 20:45
@mattcary
Copy link
Contributor

thanks!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 23, 2021
@k8s-ci-robot
Copy link
Contributor

@TeweiLuo: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-gcp-compute-persistent-disk-csi-driver-kubernetes-integration 31a8f87 link /test pull-gcp-compute-persistent-disk-csi-driver-kubernetes-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@mattcary mattcary merged commit bd8799d into kubernetes-sigs:master Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow users to specify "Storage Locations" in snapshot class
4 participants