-
Notifications
You must be signed in to change notification settings - Fork 370
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
Fix nil pointer error when collecting agent supportbundle fails #4306
Conversation
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, I only reviewed the last commit
pkg/agent/apiserver/apiserver.go
Outdated
supportBundleStorage := supportbundle.NewAgentStorage(ovsctl.NewClient(aq.GetNodeConfig().OVSBridge), aq, npq, v4Enabled, v6Enabled) | ||
iptables, err := iptables.New(v4Enabled, v6Enabled) | ||
if err != nil { | ||
return fmt.Errorf("failed to new iptables client: %v", 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.
maybe "create" or "instantiate" since "new" is not a verb
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.
will update
require.NoError(t, err) | ||
|
||
var collectedBundle *system.SupportBundle | ||
assert.Eventually(t, func() bool { |
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.
this is neat. Is this new?
should we switch to assert.Eventually
for all new unit tests instead of wait.Poll
?
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.
Added in 1.4.0. Yes, I think it can replace wait.Poll in tests.
fakeAgentQuerier.EXPECT().GetAgentInfo(&clusterinformationv1beta1.AntreaAgentInfo{}, false) | ||
fakeIPTables.EXPECT().Save() | ||
storage := NewAgentStorage(fakeOVSCtl, fakeAgentQuerier, fakeNetworkPolicyQuerier, fakeIPTables) | ||
_, err := storage.SupportBundle.Create(context.TODO(), &system.SupportBundle{ |
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.
nit: I feel like it makes a bit more sense for unit test to define ctx := context.Background()
at the beginning of the test case and use that context for every function that requires it. I feel like Background
is more logical than TODO
for tests, given that we don't intend to ever replace this context.TODO()
with something else.
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.
Some tests for rest API customize context to set namespace:
ctx := request.WithNamespace(context.TODO(), tt.npNamespace) |
Some tests customize context to get a chance to cancel it:
ctx, cancelFunc := context.WithCancel(context.Background()) |
You mean creating a global background and use it for all tests, and create child context from it if needed?
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.
not global, but for a given test case if that test case requires a context object:
func MyTest(t *testing.T) {
ctx := context.Bakground()
obj1.req(ctx, ...)
obj2.req(ctx, ...)
ctx, cancelFunc := context.WithCancel(ctx)
defer cancelFunc()
obj3.req(ctx, ...)
}
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.
updated
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.
updated, thanks
Codecov Report
@@ Coverage Diff @@
## main #4306 +/- ##
==========================================
- Coverage 66.28% 65.57% -0.71%
==========================================
Files 369 364 -5
Lines 53270 52925 -345
==========================================
- Hits 35309 34706 -603
- Misses 15369 15652 +283
+ Partials 2592 2567 -25
|
9a73afc
to
7ae265d
Compare
/test-all |
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
The code should only schedule file cleanup when the returned error is empty (meaning the returned supportbundle is not nil), otherwise the supportbundle file would never be deleted and the program would panic when there is any error encountered during supportbundle collection. antrea-io#2598 tried to fix it but did the opposite. Signed-off-by: Quan Tian <[email protected]>
7ae265d
to
b9d47cd
Compare
/test-all |
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
…ea-io#4306) The code should only schedule file cleanup when the returned error is empty (meaning the returned supportbundle is not nil), otherwise the supportbundle file would never be deleted and the program would panic when there is any error encountered during supportbundle collection. antrea-io#2598 tried to fix it but did the opposite. Signed-off-by: Quan Tian <[email protected]>
…ea-io#4306) The code should only schedule file cleanup when the returned error is empty (meaning the returned supportbundle is not nil), otherwise the supportbundle file would never be deleted and the program would panic when there is any error encountered during supportbundle collection. antrea-io#2598 tried to fix it but did the opposite. Signed-off-by: Quan Tian <[email protected]>
The code should only schedule file cleanup when the returned error is empty (meaning the returned supportbundle is not nil), otherwise the supportbundle file would never be deleted and the program would panic when there is any error encountered during supportbundle collection.
#2598 tried to fix it but did the opposite.
Signed-off-by: Quan Tian [email protected]
Based on #4304 and #4295's testing code.