-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
@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 == "" { |
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 is cleaner to skip calling this function altogether. do the check where nodeReclaimSpace()
is called?
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.
is this means VA object is created but no NodeID is added to it? explaining in what case it can happen will be helpful.
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.
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?
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.
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 fortarget.nodeID
does not need to be placed in the execution flow ofreconcile()
. You might be able to drop the 1st return value fromnodeReclaimSpace()
that way too?
okay 👍
When pvc is not mounted to any pod, no volumeattachments will be found, hence nodeID will be empty |
c6f1071
to
e2fd460
Compare
err := fmt.Errorf("Node Client not found") | ||
return nil, 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.
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) { |
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.
func Test_targetDetails_canNodeReclaimSpace(t *testing.T) { | |
TestcanNodeReclaimSpace |
func Test_targetDetails_canNodeReclaimSpace(t *testing.T) { | ||
type fields struct { | ||
driverName string | ||
pvName string |
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.
pv name and drivername are not required?
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.
pv name and drivername are not required?
optional, added them now to keep it consistent in the tests.
e2fd460
to
43f0056
Compare
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") |
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.
Error should not start with capital letters
Fixed, please take a look
Thanks
43f0056
to
8818085
Compare
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.
just a few nits for your consideration
{ | ||
name: "empty nodeID", | ||
fields: fields{ | ||
driverName: "example.csi.com", |
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.
csi.com exists, use csi.example.com
instead
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.
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. |
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.
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.
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.
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 { |
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.
why introduce fields
? just use targetDetails
in the tests
struct
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.
why introduce
fields
? just usetargetDetails
in thetests
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]>
8818085
to
13d04f7
Compare
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.
LGTM now.
Syncing latest changes from upstream main for kubernetes-csi-addons
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]