-
Notifications
You must be signed in to change notification settings - Fork 387
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 support traceflow #932
Conversation
Thanks for your PR. The following commands are available:
These commands can only be run by members of the vmware-tanzu organization. |
/test-e2e |
/test-e2e |
1 similar comment
/test-e2e |
/test-e2e |
Thanks for your PR. The following commands are available:
These commands can only be run by members of the vmware-tanzu organization. |
49a7060
to
610ef7d
Compare
/test-e2e |
1 similar comment
/test-e2e |
0453a1e
to
dff189c
Compare
Thanks for your PR. The following commands are available:
|
/test-all |
1362e92
to
dd11186
Compare
/test-all |
/test-e2e |
1 similar comment
/test-e2e |
30ec43e
to
f871cdc
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.
Some nits, otherwise LGTM.
var isPod bool | ||
var err error | ||
split = strings.Split(option.destination, "/") | ||
if len(split) == 1 { |
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 think the following if
blocks can be simplified since the only different is the namespace.
Consider following workflow:
if len == 1 {
setNameSpace
} else if len == 2 {
setNameSapce
} else {
error
}
original codes in `if` blocks.
Also, we can just check isPod
one time by using this flow.
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.
Good idea! Updated.
pkg/antctl/raw/traceflow/command.go
Outdated
) | ||
|
||
const ( | ||
ICMPProtocol int32 = 1 |
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.
Looks like we only use these constants to construct a map, how about just decalre a map here?
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.
Fixed antrea-io#923 antctl traceflow is on remote mode, inside controller mode and inside agent mode. It supports yaml and json output. It can return without retrieving results. e.g. ``` $ antctl traceflow -S busybox0 -D busybox1 name: default-busybox0-to-default-busybox1-fpllngzi phase: Succeeded source: default/busybox0 destination: default/busybox1 results: - node: antrea-linux-testbed7-1 timestamp: 1596435607 observations: - component: SpoofGuard action: Forwarded - component: Forwarding componentInfo: Output action: Delivered ```
/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.
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.
Sorry for late review, but I hope the comments can be addressed with a separate PR.
@@ -324,6 +325,11 @@ var CommandList = &commandList{ | |||
supportAgent: true, | |||
supportController: true, | |||
}, | |||
{ | |||
cobraCommand: traceflow.Command, | |||
supportAgent: true, |
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.
traceflow can support agent?
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.
antctl traceflow can be run on agent.
return nil | ||
} | ||
|
||
func setupKubeconfig(kubeconfig *rest.Config, groupVersion *schema.GroupVersion) { |
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 are the following setting necessary? for example, I think the kubeconfig should have CAData set?
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.
You are right. I followed code style in support bundle. But it is unnecessary since it is enough for traceflow to have connection to apiserver.
} else { | ||
return nil, fmt.Errorf("destination should be in the format of namespace/pod, pod, namespace/service or service") | ||
} | ||
if isPod, err = dstIsPod(client, dst.Namespace, dest); err != nil { |
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.
Pod and service can have same name, I think it's not reliable and clear to determine user's intention by querying runtime state. Maybe we should have an argument or flag to specify the type of the destination object.
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.
Yes. But could you please help check code here: https://github.com/vmware-tanzu/antrea/blob/master/pkg/agent/apiserver/handlers/ovstracing/handler.go#L151-L155
It seems like it is doing the same: find pod first, if not found then service.
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.
OK, then maybe we could discuss them together later, my personal feeling is it's not deterministic
for _, v := range strings.Split(cleanFlow, ",") { | ||
n, ok := protocols[v] | ||
if ok { | ||
(*pkt).IPHeader.Protocol = n |
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.
Does it really need to use (*pkt)
? So do all such cases in this file.
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.
Yes, it is not necessary.
} | ||
} | ||
|
||
r, ok, err := getFieldPortValue(cleanFlow, "tcp_src") |
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.
Can getFieldPortValue
just return a map to avoid repeated computation and the following redundant code?
It could be named getPortFields
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.
Good idea.
return fmt.Errorf("error when converting output to yaml: %w", err) | ||
} | ||
} else { | ||
return fmt.Errorf("output types are yaml and json") |
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 error is not clear
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.
Turned it into "output types should be yaml or json".
for i := range b { | ||
randIdx := rand.Intn(len(lettersAndDigits)) | ||
b[i] = lettersAndDigits[randIdx] | ||
} |
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.
Consider "k8s.io/apimachinery/pkg/util/rand.String"
for simplicity.
|
||
if err := installAPIGroup(s, c); err != nil { | ||
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.
Why making this change?
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 think 1) it looks clearer and 2) it keeps the same code style like agent/apiserver.
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.
ok, but I think it's controversial to separate a short function into multiple ones when they are not reused, especially in a PR that is not related. We should focus on the purpose of the PR and leave unrelated style unification to separate PR to save reviewers' effort and avoid controversy.
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.
Make sense. I will pay more attention next time. I used to change some apiserver code in this PR, but such change is dropped with a comment. However, this code remains due to the reason I mentioned above..
Fixed antrea-io#923 antctl traceflow is on remote mode, inside controller mode and inside agent mode. It supports yaml and json output. It can return without retrieving results. e.g. ``` $ antctl traceflow -S busybox0 -D busybox1 name: default-busybox0-to-default-busybox1-fpllngzi phase: Succeeded source: default/busybox0 destination: default/busybox1 results: - node: antrea-linux-testbed7-1 timestamp: 1596435607 observations: - component: SpoofGuard action: Forwarded - component: Forwarding componentInfo: Output action: Delivered ```
Fixed antrea-io#923 antctl traceflow is on remote mode, inside controller mode and inside agent mode. It supports yaml and json output. It can return without retrieving results. e.g. ``` $ antctl traceflow -S busybox0 -D busybox1 name: default-busybox0-to-default-busybox1-fpllngzi phase: Succeeded source: default/busybox0 destination: default/busybox1 results: - node: antrea-linux-testbed7-1 timestamp: 1596435607 observations: - component: SpoofGuard action: Forwarded - component: Forwarding componentInfo: Output action: Delivered ```
Fixed #923
antctl traceflow is on remote mode, inside controller mode and inside agent mode.
It supports yaml and json output. It can return without retrieving results.