diff --git a/docs/antctl.md b/docs/antctl.md index 8f2a4277bc5..ca73f4faa1b 100644 --- a/docs/antctl.md +++ b/docs/antctl.md @@ -391,9 +391,7 @@ results: Antctl can run as a reverse proxy for the Antrea API (Controller or arbitrary Agent). Usage is very similar to `kubectl proxy` and the implementation is -essentially the same. One thing to keep in mind is that the TLS connection -between the proxy and the Antrea Agent or Controller will not be secure (no -certificate verification), and the proxy should be used for debugging only. +essentially the same. To run a reverse proxy for the Antrea Controller API, use: @@ -408,8 +406,15 @@ on Node , use: $ antctl proxy --agent-node ``` -You can then access the API at `127.0.0.1:8001`. To see the full list of -supported options, run `antctl proxy --help`. +You can then access the API at `127.0.0.1:8001`. To implement this +functionality, antctl retrieves the Node IP address and API server port for the +Antrea Controller or for the specified Agent from the K8s API, and it proxies +all the requests received on `127.0.0.1:8001` directly to that IP / port. One +thing to keep in mind is that the TLS connection between the proxy and the +Antrea Agent or Controller will not be secure (no certificate verification), and +the proxy should be used for debugging only. + +To see the full list of supported options, run `antctl proxy --help`. This feature is useful if one wants to use the Go [pprof](https://golang.org/pkg/net/http/pprof/) tool to collect runtime diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 7508bfc9144..66857273efd 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -244,10 +244,9 @@ commands. The easiest way to profile the Antrea components is to use the Go [pprof](https://golang.org/pkg/net/http/pprof/) tool. Both the Antrea Agent and -the Antrea Controller use the k8s apiserver library to server their API, and -this library enables the pprof HTTP server by default. In order to access it -without having to worry about authentication, you can use the antctl proxy -function. +the Antrea Controller use the K8s apiserver library to serve their API, and this +library enables the pprof HTTP server by default. In order to access it without +having to worry about authentication, you can use the antctl proxy function. For example, this is what you would do to look at a 30-second CPU profile for the Antrea Controller: diff --git a/pkg/antctl/command_list.go b/pkg/antctl/command_list.go index e0c8656d88f..1158ae90ebf 100644 --- a/pkg/antctl/command_list.go +++ b/pkg/antctl/command_list.go @@ -49,8 +49,8 @@ func (cl *commandList) ApplyToRootCommand(root *cobra.Command) { for _, groupCommand := range groupCommands { root.AddCommand(groupCommand) } - for i := range cl.definitions { - def := cl.definitions[i] + for i, _ := range cl.definitions { + def := &cl.definitions[i] if (runtime.Mode == runtime.ModeAgent && def.agentEndpoint == nil) || (runtime.Mode == runtime.ModeController && def.controllerEndpoint == nil) { continue @@ -106,8 +106,7 @@ func (cl *commandList) validate() []error { // are used for debugging purpose. func (cl *commandList) GetDebugCommands(mode string) [][]string { var allCommands [][]string - for i := range cl.definitions { - def := cl.definitions[i] + for _, def := range cl.definitions { // TODO: incorporate query commands into e2e testing once proxy access is implemented if def.commandGroup == query { continue @@ -126,10 +125,15 @@ func (cl *commandList) GetDebugCommands(mode string) [][]string { allCommands = append(allCommands, currentCommand) } } - for i := range cl.rawCommands { - if mode == runtime.ModeController && cl.rawCommands[i].supportController || - mode == runtime.ModeAgent && cl.rawCommands[i].supportAgent { - allCommands = append(allCommands, strings.Split(cl.rawCommands[i].cobraCommand.Use, " ")[:1]) + for _, cmd := range cl.rawCommands { + if cmd.cobraCommand.Use == "proxy" { + // proxy will keep running until interrupted so it + // cannot be used as is in e2e tests. + continue + } + if mode == runtime.ModeController && cmd.supportController || + mode == runtime.ModeAgent && cmd.supportAgent { + allCommands = append(allCommands, strings.Split(cmd.cobraCommand.Use, " ")[:1]) } } return allCommands