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

controller/reclaimspacejob: skip making node req if nodeID is empty #104

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

Rakshith-R
Copy link
Member

@Rakshith-R Rakshith-R commented Jan 27, 2022

Node reclaimspace request should not be made
when nodeID is empty indicating the pvc is
not mounted to any pod and no volumeattachment
object for that PVC was found.

Signed-off-by: Rakshith R [email protected]

@mergify mergify bot requested review from nixpanic, yati1998 and Yuggupta27 January 27, 2022 11:08
@Rakshith-R Rakshith-R requested a review from Madhu-1 January 27, 2022 11:12
@Madhu-1
Copy link
Member

Madhu-1 commented Jan 27, 2022

@Rakshith-R can you please provide more tails when the node ID will be empty?

@@ -376,6 +376,11 @@ func (r *ReclaimSpaceJobReconciler) nodeReclaimSpace(
ctx context.Context,
logger *logr.Logger,
target *targetDetails) (bool, *int64, error) {
if target.nodeID == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is cleaner to skip calling this function altogether. do the check where nodeReclaimSpace() is called?

Copy link
Member

Choose a reason for hiding this comment

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

is this means VA object is created but no NodeID is added to it? explaining in what case it can happen will be helpful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe add a helper func (td *targetDetails) canNodeReclaimSpace() bool {} so that the check for target.nodeID does not need to be placed in the execution flow of reconcile(). You might be able to drop the 1st return value from nodeReclaimSpace() that way too?

Copy link
Member Author

Choose a reason for hiding this comment

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

is this means VA object is created but no NodeID is added to it? explaining in what case it can happen will be helpful.

It means no VA object exists for that pvc, I'll add comments

maybe add a helper func (td *targetDetails) canNodeReclaimSpace() bool {} so that the check for target.nodeID does not need to be placed in the execution flow of reconcile(). You might be able to drop the 1st return value from nodeReclaimSpace() that way too?

okay 👍

@Rakshith-R
Copy link
Member Author

@Rakshith-R can you please provide more tails when the node ID will be empty?

When pvc is not mounted to any pod, no volumeattachments will be found, hence nodeID will be empty

@Rakshith-R Rakshith-R requested review from nixpanic and a team January 27, 2022 12:39
Comment on lines 401 to 402
err := fmt.Errorf("Node Client not found")
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := fmt.Errorf("Node Client not found")
return nil, err
return nil, errors.New("Node Client not found")

@@ -176,3 +176,42 @@ func TestCalculateReclaimedSpace(t *testing.T) {
})
}
}

func Test_targetDetails_canNodeReclaimSpace(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func Test_targetDetails_canNodeReclaimSpace(t *testing.T) {
TestcanNodeReclaimSpace

func Test_targetDetails_canNodeReclaimSpace(t *testing.T) {
type fields struct {
driverName string
pvName string
Copy link
Member

Choose a reason for hiding this comment

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

pv name and drivername are not required?

Copy link
Member Author

Choose a reason for hiding this comment

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

pv name and drivername are not required?

optional, added them now to keep it consistent in the tests.

Madhu-1
Madhu-1 previously approved these changes Jan 27, 2022
clientName, nodeClient := r.getRSClientWithCap(
target.driverName,
target.nodeID,
identity.Capability_ReclaimSpace_ONLINE)
if nodeClient == nil {
logger.Info("Node Client not found")
return false, nil, nil
return nil, errors.New("Node Client not found")
Copy link
Member

@Madhu-1 Madhu-1 Jan 27, 2022

Choose a reason for hiding this comment

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

Error should not start with capital letters

Fixed, please take a look

Thanks

@Rakshith-R Rakshith-R requested a review from Madhu-1 January 27, 2022 13:13
@mergify mergify bot dismissed Madhu-1’s stale review January 27, 2022 13:13

Pull request has been modified.

Madhu-1
Madhu-1 previously approved these changes Jan 27, 2022
Copy link
Collaborator

@nixpanic nixpanic left a comment

Choose a reason for hiding this comment

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

just a few nits for your consideration

{
name: "empty nodeID",
fields: fields{
driverName: "example.csi.com",
Copy link
Collaborator

Choose a reason for hiding this comment

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

csi.com exists, use csi.example.com instead

Copy link
Member Author

Choose a reason for hiding this comment

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

csi.com exists, use csi.example.com instead

done

// PVC may not be mounted to a pod and volumeattachment for PVC
// may not be found due to which nodeID will be empty.
// Make node reclaimspace request only if
// nodeID is not empty.
Copy link
Collaborator

Choose a reason for hiding this comment

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

the comment is not really needed to be this verbose. Only the comment for the function should explain about nodeID, the check may change in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

the comment is not really needed to be this verbose. Only the comment for the function should explain about nodeID, the check may change in the future.

I agree. The function comment should be sufficient.

@@ -176,3 +176,46 @@ func TestCalculateReclaimedSpace(t *testing.T) {
})
}
}

func TestCanNodeReclaimSpace(t *testing.T) {
type fields struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why introduce fields? just use targetDetails in the tests struct

Copy link
Member Author

Choose a reason for hiding this comment

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

why introduce fields? just use targetDetails in the tests struct

auto generated test, It uses targetDetails directly now.

Node reclaimspace request should not be made
when nodeID is empty indicating the pvc is
not mounted to any pod and no volumeattachment
object for that PVC was found.

Signed-off-by: Rakshith R <[email protected]>
@mergify mergify bot dismissed Madhu-1’s stale review January 28, 2022 05:13

Pull request has been modified.

@Rakshith-R Rakshith-R requested review from a team, nixpanic and Madhu-1 January 28, 2022 05:14
Copy link
Contributor

@yati1998 yati1998 left a comment

Choose a reason for hiding this comment

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

LGTM now.

@mergify mergify bot merged commit e033960 into csi-addons:main Jan 28, 2022
nixpanic pushed a commit to nixpanic/kubernetes-csi-addons that referenced this pull request Jan 12, 2024
Syncing latest changes from upstream main for kubernetes-csi-addons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants