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

antctl-query #10

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

antctl-query #10

wants to merge 7 commits into from

Conversation

jakesokol1
Copy link
Owner

No description provided.

Copy link

@antoninbas antoninbas left a 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/antctl.go Outdated Show resolved Hide resolved
pkg/antctl/antctl.go Outdated Show resolved Hide resolved
pkg/antctl/antctl.go Outdated Show resolved Hide resolved
pkg/antctl/command_definition.go Outdated Show resolved Hide resolved
// 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++ {

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?

Copy link
Owner Author

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).

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/networkpolicy/store/appliedtogroup.go Outdated Show resolved Hide resolved
pkg/controller/networkpolicy/store/appliedtogroup.go Outdated Show resolved Hide resolved
test/e2e/infra/vagrant/Vagrantfile Outdated Show resolved Hide resolved
test/e2e/infra/vagrant/push_antrea.sh Outdated Show resolved Hide resolved
Comment on lines 32 to 57
//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
}

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.

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

Copy link
Owner Author

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?

Copy link
Owner Author

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

Makefile Outdated Show resolved Hide resolved
pkg/antctl/transform/endpoint/transform.go Outdated Show resolved Hide resolved
if !ok {
return []string{}, nil
}
keys := make([]string, 0)

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

// 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++ {

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

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 {

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?

Copy link

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

more comments

pkg/antctl/command_definition.go Outdated Show resolved Hide resolved
pkg/antctl/command_definition.go Outdated Show resolved Hide resolved
pkg/antctl/command_definition.go Outdated Show resolved Hide resolved
pkg/controller/apiserver/handlers/handler_test.go Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
pkg/controller/networkpolicy/controller_query_test.go Outdated Show resolved Hide resolved
pkg/controller/querier/querier.go Outdated Show resolved Hide resolved
@jakesokol1 jakesokol1 force-pushed the antctl-query branch 2 times, most recently from b3e0c11 to 2aa69bd Compare July 31, 2020 18:57
@@ -41,7 +41,6 @@ func NewControllerQuerier(networkPolicyInfoQuerier querier.ControllerNetworkPoli
return &controllerQuerier{networkPolicyInfoQuerier: networkPolicyInfoQuerier, apiPort: apiPort}
}

// GetNodeSubnet gets current network policy info querier.

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

@@ -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"

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

Choose a reason for hiding this comment

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

?

Copy link
Owner Author

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

Copy link
Owner Author

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

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.

Comment on lines 17 to 31
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"
)

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
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.

2 participants