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

Added the feature to use secrets of ListSnapshots #252

Merged

Conversation

bells17
Copy link
Contributor

@bells17 bells17 commented Feb 10, 2020

I modified to be able to use secrets in ListSnapshotRequest.

What type of PR is this?
/kind feature

What this PR does / why we need it:
I want to use secrets in ListSnapshots.

Which issue(s) this PR fixes:
Fixes #236
This is a new PR. old PR is #237.
(Because I misunderstood how to support VolumeSnapshotSecret in ListVolumes, I recreated a new PR...)

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Adds support for ListSnapshots secrets

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 10, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @bells17. Thanks for your PR.

I'm waiting for a kubernetes-csi 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 the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 10, 2020
@bells17
Copy link
Contributor Author

bells17 commented Feb 10, 2020

@xing-yang I created a new PR. Could you review this PR?

@xing-yang
Copy link
Collaborator

/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 Feb 10, 2020
@xing-yang
Copy link
Collaborator

You need to add "release-note" right after ``` above the release note text like this:
```release-note
This is the release note
```

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 12, 2020
@bells17
Copy link
Contributor Author

bells17 commented Feb 12, 2020

Thank you, I added "release-note".

if content.Spec.VolumeSnapshotClassName != nil {
class, err := ctrl.getSnapshotClass(*content.Spec.VolumeSnapshotClassName)
if err != nil {
klog.Errorf("failed to getSnapshotClass %s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/failed/Failed
Can you also print out the snapshot class name in the error message.

snapshotterListCredentials, err = utils.GetCredentials(ctrl.client, snapshotterListSecretRef)
if err != nil {
// Continue with deletion, as the secret may have already been deleted.
klog.Errorf("Failed to credentials for snapshot %s: %s", content.Name, err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing "get":
Failed to get credentials for snapshot ...

if err != nil {
// Continue with deletion, as the secret may have already been deleted.
klog.Errorf("Failed to credentials for snapshot %s: %s", content.Name, err.Error())
return nil, fmt.Errorf("cannot get credentials for snapshot content %#v", content.Name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's good to have the "err" here as well. You can format a message and have it used in both logging and the return message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xing-yang Sorry,

You can format a message and have it used in both logging and the return message.

This means should I create a variable that store formatted error message, and hand over the variable to klog.Errorf argument and return value?
And should I apply the same to other parts as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. So that means the message needs to start with lower case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Um...Sorry I can't understand yet.
In this part, should I fix as below?

// Continue with deletion, as the secret may have already been deleted.
klog.Errorf("Failed to credentials for snapshot %s: %s", content.Name, err.Error())
return nil, fmt.Errorf("failed to credentials for snapshot %s: %s", content.Name, err.Error())

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that is fine too.

s/to credentials/to get credentials

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I understand.

snapshotterListSecretRef, err := utils.GetSecretReference(utils.SnapshotterListSecretParams, class.Parameters, content.GetObjectMeta().GetName(), nil)
if err != nil {
klog.Errorf("Failed to get secret reference for snapshot %s: %s", content.Name, err.Error())
return nil, fmt.Errorf("cannot get secret reference for snapshot content %#v", content.Name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

print err here as well.

class, err := ctrl.getSnapshotClass(*content.Spec.VolumeSnapshotClassName)
if err != nil {
klog.Errorf("failed to getSnapshotClass %s", err)
return nil, fmt.Errorf("cannot get snapshot class for snapshot content %s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

add snapshot class name here too.

@@ -925,6 +926,11 @@ func (f *fakeSnapshotter) GetSnapshotStatus(ctx context.Context, snapshotID stri
err = fmt.Errorf("unexpected List snapshot call")
}

if !reflect.DeepEqual(call.secrets, snapshotterListCredentials) {
f.t.Errorf("Wrong CSI List Snapshot call: snapshotID=%s, expected secrets %+v, got %+v", snapshotID, call.secrets, snapshotterListCredentials)
err = fmt.Errorf("unexpected Delete Snapshot call")
Copy link
Collaborator

Choose a reason for hiding this comment

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

/Delete/List

@xing-yang
Copy link
Collaborator

I tested this PR to create a snapshot dynamically with secrets for delete and list snapshots. It failed with the following error:

Failed to create snapshot: failed to take snapshot of the volume, 4cbb0970-5024-11ea-9bdb-0242ac110003: "failed to remove CSI Parameters of prefixed keys: found unknown parameter key \"csi.storage.k8s.io/snapshotter-list-secret-name\" with reserved namespace csi.storage.k8s.io/"

In function RemovePrefixedParameters() in util.go, those new prefixed keys for list snapshots secret need to be added. Please add a unit test for create snapshot with unknown keys.

@bells17
Copy link
Contributor Author

bells17 commented Feb 19, 2020

@xing-yang
#252 (comment)

In function RemovePrefixedParameters() in util.go, those new prefixed keys for list snapshots secret need to be added.

Sorry, it went over my head. I'll fix it.

Please add a unit test for create snapshot with unknown keys.

a unit test of checking unknown keys is already exists as below:

{
name: "unknown prefixed var",
params: map[string]string{csiParameterPrefix + "bim": "baz"},
expectErr: true,
},

So I think it's maybe better that append parameters that having "csi.storage.k8s.io/snapshotter-list-secret-namespace" and "csi.storage.k8s.io/snapshotter-list-secret-name" to the "default-class" for unit tests is better.

{
TypeMeta: metav1.TypeMeta{
Kind: "VolumeSnapshotClass",
},
ObjectMeta: metav1.ObjectMeta{
Name: defaultClass,
Annotations: map[string]string{utils.IsDefaultSnapshotClassAnnotation: "true"},
},
Driver: mockDriverName,
DeletionPolicy: crdv1.VolumeSnapshotContentDelete,
},

What do you think about this idea?

@xing-yang
Copy link
Collaborator

Yes, your suggestion on unit test sounds good to me.

@bells17
Copy link
Contributor Author

bells17 commented Feb 19, 2020

@xing-yang I fixed RemovePrefixedParameters() and improved log and error messages.
(Also I appended parameters to "default-class" for unit tests)

But I don't test below cases manually yet:

  • create a snapshot dynamically with secrets for delete and list snapshots.
  • import an existing snapshot with secrets for list.

I'll test above cases tomorrow.
(Because currently Japan now midnight 😅 I'm living in Japan.)

@xing-yang
Copy link
Collaborator

@bells17 no problem. Thanks for the heads up!

@bells17
Copy link
Contributor Author

bells17 commented Feb 20, 2020

@xing-yang Hi, I tested below cases:

  • create a snapshot dynamically with secrets for delete and list snapshots.
  • import an existing snapshot with secrets for list.

I wonder if you could review this PR again.

@xing-yang
Copy link
Collaborator

Thanks @bells17 ! I'll take a look.


snapshotterListSecretRef, err := utils.GetSecretReference(utils.SnapshotterListSecretParams, class.Parameters, content.GetObjectMeta().GetName(), nil)
if err != nil {
klog.Errorf("Failed to get secret reference for snapshot %s: %s", content.Name, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/for snapshot/for snapshot content

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also can you use "%v" to print err?

snapshotterListSecretRef, err := utils.GetSecretReference(utils.SnapshotterListSecretParams, class.Parameters, content.GetObjectMeta().GetName(), nil)
if err != nil {
klog.Errorf("Failed to get secret reference for snapshot %s: %s", content.Name, err)
return nil, fmt.Errorf("failed to get secret reference for snapshot %s: %s", content.Name, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

if content.Spec.VolumeSnapshotClassName != nil {
class, err := ctrl.getSnapshotClass(*content.Spec.VolumeSnapshotClassName)
if err != nil {
klog.Errorf("Failed to get snapshot class %s for snapshot content %s", *content.Spec.VolumeSnapshotClassName, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

klog.Errorf("Failed to get snapshot class %s for snapshot content %s: %v", *content.Spec.VolumeSnapshotClassName, content.Name, err)

class, err := ctrl.getSnapshotClass(*content.Spec.VolumeSnapshotClassName)
if err != nil {
klog.Errorf("Failed to get snapshot class %s for snapshot content %s", *content.Spec.VolumeSnapshotClassName, err)
return nil, fmt.Errorf("failed to get snapshot class %s for snapshot content %s", *content.Spec.VolumeSnapshotClassName, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

snapshotterListCredentials, err = utils.GetCredentials(ctrl.client, snapshotterListSecretRef)
if err != nil {
// Continue with deletion, as the secret may have already been deleted.
klog.Errorf("Failed to get credentials for snapshot %s: %s", content.Name, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/for snapshot/for snapshot content

Copy link
Collaborator

Choose a reason for hiding this comment

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

use %v to print err

if err != nil {
// Continue with deletion, as the secret may have already been deleted.
klog.Errorf("Failed to get credentials for snapshot %s: %s", content.Name, err)
return nil, fmt.Errorf("failed to get credentials for snapshot %s: %s", content.Name, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

PrefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name"
PrefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace"

PrefixedSnapshotterListSecretNameKey = csiParameterPrefix + "snapshotter-list-secret-name"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a comment: // Prefixed name key for ListSnapshots secret

PrefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace"

PrefixedSnapshotterListSecretNameKey = csiParameterPrefix + "snapshotter-list-secret-name"
PrefixedSnapshotterListSecretNamespaceKey = csiParameterPrefix + "snapshotter-list-secret-namespace"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a comment: // Prefixed namespace key for ListSnapshots secret

@@ -53,8 +53,11 @@ const (
// fields in subsequent CSI calls or Kubernetes API objects.
csiParameterPrefix = "csi.storage.k8s.io/"

prefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name"
prefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace"
PrefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a comment: // Prefixed name key for DeleteSnapshot secret

prefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name"
prefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace"
PrefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name"
PrefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a comment: // Prefixed namespace key for DeleteSnapshot secret

@bells17
Copy link
Contributor Author

bells17 commented Feb 20, 2020

@xing-yang Thank you for your review quickly and I'm sorry about that I have your commented log messages and error messages many times to improve these messages 😢
I reflected your comments.

@xing-yang
Copy link
Collaborator

Thanks for your work!
/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bells17, xing-yang

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

The pull request process is described 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 21, 2020
@k8s-ci-robot k8s-ci-robot merged commit 883842f into kubernetes-csi:master Feb 21, 2020
@bells17 bells17 deleted the add-feature-listsnapshots-secrets2 branch July 16, 2020 23:25
jsafrane added a commit to jsafrane/external-snapshotter that referenced this pull request May 13, 2024
adb3af9 Merge pull request kubernetes-csi#252 from bells17/update-go-version
b82ee38 Merge pull request kubernetes-csi#253 from bells17/fix-typo
c317456 Fix typo
0a78505 Bump to Go 1.22.3
edd89ad Merge pull request kubernetes-csi#251 from jsafrane/add-logcheck
043fd09 Add test-logcheck target
d7535ae Merge pull request kubernetes-csi#250 from jsafrane/go-1.22
b52e7ad Update go to 1.22.2
14fdb6f Merge pull request kubernetes-csi#247 from msau42/prow
9b4352e Update release playbook
c7bb972 Fix release notes script to use fixed tags
463a0e9 Add script to update specific go modules

git-subtree-dir: release-tools
git-subtree-split: adb3af9
bells17 added a commit to bells17/external-snapshotter that referenced this pull request May 13, 2024
adb3af9 Merge pull request kubernetes-csi#252 from bells17/update-go-version
b82ee38 Merge pull request kubernetes-csi#253 from bells17/fix-typo
c317456 Fix typo
0a78505 Bump to Go 1.22.3

git-subtree-dir: release-tools
git-subtree-split: adb3af9
andyzhangx pushed a commit to andyzhangx/external-snapshotter that referenced this pull request Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support ListSnapshots secrets
3 participants