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 support traceflow #932

Merged
merged 1 commit into from
Aug 11, 2020
Merged

antctl support traceflow #932

merged 1 commit into from
Aug 11, 2020

Conversation

lzhecheng
Copy link
Contributor

@lzhecheng lzhecheng commented Jul 9, 2020

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.

$ antctl traceflow -S busybox0 -D busybox1
name: default-busybox0-to-default-busybox1
phase: Succeeded
source: default/busybox0
destination: default/busybox1
noderesults:
- node: antrea-linux-testbed7-2
  role: ""
  timestamp: 1595391265
  observations:
  - component: SpoofGuard
    componentinfo: ""
    action: Forwarded
    pod: ""
    dstmac: ""
    networkpolicy: ""
    ttl: 0
    translatedsrcip: ""
    translateddstip: ""
    tunneldstip: ""
  - component: Forwarding
    componentinfo: Output
    action: Delivered
    pod: ""
    dstmac: ""
    networkpolicy: ""
    ttl: 0
    translatedsrcip: ""
    translateddstip: ""
    tunneldstip: ""

@antrea-bot
Copy link
Collaborator

Thanks for your PR.
Unit tests and code linters are run automatically every time the PR is updated.
E2e, conformance and network policy tests can only be triggered by a member of the vmware-tanzu organization. Regular contributors to the project should join the org.

The following commands are available:

  • /test-e2e: to trigger e2e tests.
  • /skip-e2e: to skip e2e tests.
  • /test-conformance: to trigger conformance tests.
  • /skip-conformance: to skip conformance tests.
  • /test-whole-conformance: to trigger all conformance tests on linux.
  • /skip-whole-conformance: to skip all conformance tests on linux.
  • /test-networkpolicy: to trigger networkpolicy tests.
  • /skip-networkpolicy: to skip networkpolicy tests.
  • /test-windows-conformance: to trigger windows conformance tests.
  • /skip-windows-conformance: to skip windows conformance tests.
  • /test-all: to trigger all tests (except whole conformance).
  • /skip-all: to skip all tests (except whole conformance).

These commands can only be run by members of the vmware-tanzu organization.

@lzhecheng
Copy link
Contributor Author

/test-e2e
/test-conformance

@lzhecheng
Copy link
Contributor Author

/test-e2e

1 similar comment
@lzhecheng
Copy link
Contributor Author

/test-e2e

@lzhecheng
Copy link
Contributor Author

/test-e2e

@antrea-bot
Copy link
Collaborator

Thanks for your PR.
Unit tests and code linters are run automatically every time the PR is updated.
E2e, conformance and network policy tests can only be triggered by a member of the vmware-tanzu organization. Regular contributors to the project should join the org.

The following commands are available:

  • /test-e2e: to trigger e2e tests.
  • /skip-e2e: to skip e2e tests.
  • /test-conformance: to trigger conformance tests.
  • /skip-conformance: to skip conformance tests.
  • /test-whole-conformance: to trigger all conformance tests on linux.
  • /skip-whole-conformance: to skip all conformance tests on linux.
  • /test-networkpolicy: to trigger networkpolicy tests.
  • /skip-networkpolicy: to skip networkpolicy tests.
  • /test-windows-conformance: to trigger windows conformance tests.
  • /skip-windows-conformance: to skip windows conformance tests.
  • /test-windows-networkpolicy: to trigger windows networkpolicy tests.
  • /skip-windows-networkpolicy: to skip windows networkpolicy tests.
  • /test-all: to trigger all tests (except whole conformance).
  • /skip-all: to skip all tests (except whole conformance).

These commands can only be run by members of the vmware-tanzu organization.

@lzhecheng lzhecheng marked this pull request as draft July 15, 2020 03:40
@lzhecheng lzhecheng force-pushed the tf-cli branch 13 times, most recently from 49a7060 to 610ef7d Compare July 16, 2020 10:37
@lzhecheng
Copy link
Contributor Author

/test-e2e

1 similar comment
@lzhecheng
Copy link
Contributor Author

/test-e2e

@lzhecheng lzhecheng force-pushed the tf-cli branch 5 times, most recently from 0453a1e to dff189c Compare July 17, 2020 09:01
@antrea-bot
Copy link
Collaborator

Thanks for your PR.
Unit tests and code linters are run automatically every time the PR is updated.
E2e, conformance and network policy tests can only be triggered by a member of the vmware-tanzu organization. Regular contributors to the project should join the org.

The following commands are available:

  • /test-e2e: to trigger e2e tests.
  • /skip-e2e: to skip e2e tests.
  • /test-conformance: to trigger conformance tests.
  • /skip-conformance: to skip conformance tests.
  • /test-whole-conformance: to trigger all conformance tests on linux.
  • /skip-whole-conformance: to skip all conformance tests on linux.
  • /test-networkpolicy: to trigger networkpolicy tests.
  • /skip-networkpolicy: to skip networkpolicy tests.
  • /test-windows-conformance: to trigger windows conformance tests.
  • /skip-windows-conformance: to skip windows conformance tests.
  • /test-windows-networkpolicy: to trigger windows networkpolicy tests.
  • /skip-windows-networkpolicy: to skip windows networkpolicy tests.
  • /test-hw-offload: to trigger ovs hardware offload test.
  • /skip-hw-offload: to skip ovs hardware offload test.
  • /test-all: to trigger all tests (except whole conformance).
  • /skip-all: to skip all tests (except whole conformance).

@lzhecheng lzhecheng requested a review from weiqiangt August 11, 2020 01:56
@lzhecheng
Copy link
Contributor Author

/test-all

@lzhecheng lzhecheng force-pushed the tf-cli branch 4 times, most recently from 1362e92 to dd11186 Compare August 11, 2020 03:00
@lzhecheng
Copy link
Contributor Author

/test-all

@lzhecheng
Copy link
Contributor Author

/test-e2e

1 similar comment
@lzhecheng
Copy link
Contributor Author

/test-e2e

pkg/antctl/raw/traceflow/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/traceflow/command.go Show resolved Hide resolved
pkg/antctl/raw/traceflow/command_test.go Show resolved Hide resolved
pkg/apis/ops/v1alpha1/register.go Outdated Show resolved Hide resolved
@lzhecheng lzhecheng force-pushed the tf-cli branch 4 times, most recently from 30ec43e to f871cdc Compare August 11, 2020 05:57
@lzhecheng
Copy link
Contributor Author

/test-all

Copy link
Contributor

@weiqiangt weiqiangt left a 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 {
Copy link
Contributor

@weiqiangt weiqiangt Aug 11, 2020

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Updated.

)

const (
ICMPProtocol int32 = 1
Copy link
Contributor

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?

Copy link
Contributor Author

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
```
@lzhecheng
Copy link
Contributor Author

/test-all

@lzhecheng lzhecheng requested a review from weiqiangt August 11, 2020 11:39
Copy link
Contributor

@weiqiangt weiqiangt left a comment

Choose a reason for hiding this comment

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

LGTM.

@lzhecheng lzhecheng merged commit 8fb94c1 into antrea-io:master Aug 11, 2020
@lzhecheng lzhecheng deleted the tf-cli branch August 11, 2020 12:03
Copy link
Member

@tnqn tnqn left a 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,
Copy link
Member

Choose a reason for hiding this comment

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

traceflow can support agent?

Copy link
Contributor Author

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.

pkg/antctl/raw/traceflow/command.go Show resolved Hide resolved
return nil
}

func setupKubeconfig(kubeconfig *rest.Config, groupVersion *schema.GroupVersion) {
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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")
Copy link
Member

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

Copy link
Contributor Author

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")
Copy link
Member

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

Copy link
Contributor Author

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]
}
Copy link
Member

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
}
Copy link
Member

Choose a reason for hiding this comment

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

Why making this change?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

GraysonWu pushed a commit to GraysonWu/antrea that referenced this pull request Sep 22, 2020
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
```
GraysonWu pushed a commit to GraysonWu/antrea that referenced this pull request Sep 23, 2020
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
```
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.

[Antctl] Support Traceflow
7 participants