-
Notifications
You must be signed in to change notification settings - Fork 379
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
Added the feature to use secrets of ListSnapshots #252
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
@xing-yang I created a new PR. Could you review this PR? |
/ok-to-test |
You need to add "release-note" right after ``` above the release note text like this: |
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) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/Delete/List
I tested this PR to create a snapshot dynamically with secrets for delete and list snapshots. It failed with the following error:
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. |
Sorry, it went over my head. I'll fix it.
a unit test of checking unknown keys is already exists as below: external-snapshotter/pkg/utils/util_test.go Lines 125 to 129 in 3b76de4
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. external-snapshotter/pkg/sidecar-controller/snapshot_delete_test.go Lines 120 to 130 in 3b76de4
What do you think about this idea? |
Yes, your suggestion on unit test sounds good to me. |
@xing-yang I fixed RemovePrefixedParameters() and improved log and error messages. But I don't test below cases manually yet:
I'll test above cases tomorrow. |
@bells17 no problem. Thanks for the heads up! |
@xing-yang Hi, I tested below cases:
I wonder if you could review this PR again. |
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
pkg/utils/util.go
Outdated
PrefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name" | ||
PrefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace" | ||
|
||
PrefixedSnapshotterListSecretNameKey = csiParameterPrefix + "snapshotter-list-secret-name" |
There was a problem hiding this comment.
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
pkg/utils/util.go
Outdated
PrefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace" | ||
|
||
PrefixedSnapshotterListSecretNameKey = csiParameterPrefix + "snapshotter-list-secret-name" | ||
PrefixedSnapshotterListSecretNamespaceKey = csiParameterPrefix + "snapshotter-list-secret-namespace" |
There was a problem hiding this comment.
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
pkg/utils/util.go
Outdated
@@ -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" |
There was a problem hiding this comment.
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
pkg/utils/util.go
Outdated
prefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name" | ||
prefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace" | ||
PrefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name" | ||
PrefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace" |
There was a problem hiding this comment.
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
@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 😢 |
Thanks for your work! |
[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 |
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
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
Update go to 1.22.3
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?: