-
Notifications
You must be signed in to change notification settings - Fork 0
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
antctl-query #10
base: master
Are you sure you want to change the base?
antctl-query #10
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.
@jakesokol1 we should be good to open the upstream PR after these comments are addressed. I didn't review the server part in details, since I did several reviews earlier.
You may have questions about some comments (e.g. the one about the Transform). Ping me on Slack if it is the case and we can have a Zoom.
pkg/antctl/command_definition.go
Outdated
// Do not limit the column length for a single column table. | ||
// This is for the case a single column table can have long rows which cannot | ||
// fit into a single line (one example is the ovsflows outputs). | ||
widths[0] = 0 | ||
} else { | ||
// Get the width of every column. | ||
for j := 0; j < numColumns; j++ { | ||
for j := 0; j < numCol; j++ { |
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 the renaming from Columns to Col is not strictly needed and just makes the diff larger?
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.
I renamed to numCol for consistency with the refactored version (in getColumnWidths).
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.
that's fine by me, but it looks like it should be numCols
and not numCol
. Otherwise it's not consistent with numRows
.
pkg/controller/querier/querier.go
Outdated
//TODO: expand this interface similarly to AgentQuerier | ||
type ControllerQuerier interface { | ||
GetControllerInfo(controllInfo *v1beta1.AntreaControllerInfo, partial bool) | ||
} | ||
|
||
//TODO: implement interface methods | ||
type controllerQuerier struct { | ||
networkPolicyInfoQuerier querier.ControllerNetworkPolicyInfoQuerier | ||
endpointQuerier networkpolicy.EndpointQuerier | ||
apiPort int | ||
} | ||
|
||
func NewControllerQuerier(networkPolicyInfoQuerier querier.ControllerNetworkPolicyInfoQuerier, apiPort int) *controllerQuerier { | ||
return &controllerQuerier{networkPolicyInfoQuerier: networkPolicyInfoQuerier, apiPort: apiPort} | ||
func NewControllerQuerier(networkPolicyInfoQuerier querier.ControllerNetworkPolicyInfoQuerier, | ||
endPointQuerier networkpolicy.EndpointQuerier, apiPort int) *controllerQuerier { | ||
return &controllerQuerier{networkPolicyInfoQuerier: networkPolicyInfoQuerier, | ||
endpointQuerier: endPointQuerier, apiPort: apiPort} | ||
} | ||
|
||
// GetNodeSubnet gets current network policy info querier. | ||
func (cq controllerQuerier) getNetworkPolicyInfoQuerier() querier.ControllerNetworkPolicyInfoQuerier { | ||
return cq.networkPolicyInfoQuerier | ||
} | ||
|
||
func (cq controllerQuerier) getEndpointQuerierReplier() networkpolicy.EndpointQuerier { | ||
return cq.endpointQuerier | ||
} | ||
|
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.
with the current state of the code, we actually do not use this anywhere. So we should either remove your changes to this file, or have a small refactoring in cmd/antrea-controller/controller.go to leverage this.
The easiest solution is definitely to just remove this code, so I suggest we go this route. Keep this code somewhere in another branch (rebase-2 is fine) in case we need it later. In particular, I think the refactoring would involve moving createAPIServerConfig
to pkg/apiserver
, and making the instantiation of the Agent apiserver more similar to the instantiation of the Controller apiserver. Probably a bit of a tricky project at this stage.
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.
I was also confused by the TODOs, but it's irrelevant if we just remove the code
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.
I do need to include the changes in NewControllerQuerier correct?
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.
Actually never mind, it is never used
if !ok { | ||
return []string{}, nil | ||
} | ||
keys := make([]string, 0) |
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.
that's right my bad
pkg/antctl/command_definition.go
Outdated
// Do not limit the column length for a single column table. | ||
// This is for the case a single column table can have long rows which cannot | ||
// fit into a single line (one example is the ovsflows outputs). | ||
widths[0] = 0 | ||
} else { | ||
// Get the width of every column. | ||
for j := 0; j < numColumns; j++ { | ||
for j := 0; j < numCol; j++ { |
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.
that's fine by me, but it looks like it should be numCols
and not numCol
. Otherwise it's not consistent with numRows
.
_, querier := makeControllerAndEndpointQueryReplier(objs...) | ||
// Everything is ready, now start timing. | ||
start := time.Now() | ||
// track execution time by calling query endpoint 1000 times on random pods |
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.
that's a shortcut (sed syntax) for: replace the "pods" spelling with "Pods"
Name string | ||
} | ||
|
||
type Response 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.
@jakesokol1 this is my most important comment I think. Are you working on addressing it?
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.
more comments
b3e0c11
to
2aa69bd
Compare
pkg/controller/querier/querier.go
Outdated
@@ -41,7 +41,6 @@ func NewControllerQuerier(networkPolicyInfoQuerier querier.ControllerNetworkPoli | |||
return &controllerQuerier{networkPolicyInfoQuerier: networkPolicyInfoQuerier, apiPort: apiPort} | |||
} | |||
|
|||
// GetNodeSubnet gets current network policy info querier. |
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.
don't remove the comment, fix the method name instead
hack/update-codegen-dockerized.sh
Outdated
@@ -91,7 +91,7 @@ MOCKGEN_TARGETS=( | |||
"pkg/ovs/ovsctl OVSCtlClient" | |||
"pkg/agent/querier AgentQuerier" | |||
"pkg/controller/querier ControllerQuerier" | |||
"pkg/querier AgentNetworkPolicyInfoQuerier" | |||
"pkg/querier AgentNetworkPolicyInfoQuerier,ControllerNetworkPolicyInfoQuerier" |
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.
I don't think you need to generate a mock for ControllerNetworkPolicyInfoQuerier
. If yes, where are you using it?
However, you do need to generate the mock for EndpointQuerier
. I see that you have the generated mock file checked-in, but I don't know how it was generated since hack/update-codegen-dockerized.sh
does not reference EndpointQuerier
.
@@ -1,4 +1,4 @@ | |||
// Copyright 2019 Antrea Authors | |||
// Copyright YEAR Antrea Authors |
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.
?
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.
I am not sure how this happened, Ill change it back
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.
Whenever a run make codegen it switches back to YEAR
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 able to reproduce locally. But I have observed that if I manually set it to YEAR and commit that change, then it will leave it as YEAR. Even if you don't explicitly set it to YEAR, that could happen if the script failed halfway because of some in correct changes.
import ( | ||
"encoding/json" | ||
"github.com/vmware-tanzu/antrea/pkg/controller/networkpolicy" | ||
v1 "k8s.io/api/admission/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/vmware-tanzu/antrea/pkg/controller/apiserver/handlers/endpoint" | ||
queriermock "github.com/vmware-tanzu/antrea/pkg/controller/networkpolicy/testing" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) |
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.
we usually group imports as follows (you may want to fix it before opening the upstream PR, otherwise someone is likely to comment about it):
- go standard imports
- whiteline
- all third-party imports
- whiteline
- antrea imports
Antctl query endpoint gives users the ability to filter network policies relevant to a certain endpoint. The user is able to query internal controller stores using the antrea controller apiserver through antctl. To answer queries in an efficient way, we add new indexers to the internal stores of the controller, incurring a small memory overhead (~20%, depends on structure of NetworkPolicies). Note, antctl query endpoint only works when run in the controller. We are working on getting it to work out of cluster. Fixes antrea-io#974
No description provided.