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

Refactor antctl framework #356

Merged
merged 1 commit into from
Mar 4, 2020
Merged

Conversation

weiqiangt
Copy link
Contributor

@weiqiangt weiqiangt commented Feb 4, 2020

  • Set up an API server on antrea agent
  • The antctl client is consuming the API server in antrea agent
    instead of using the specific antctl server
  • Added API /networkpolicies, /appliedtogroups, /addressgroups,
    /agentinfo and /version APIs to the agent API server
  • Add get network-policy, get address-group and get applied-to-group
    commands for both controller and agent
  • Make GetVersion in version.go returning a semantic version object.

By applying network policy:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: test-network-policy
  namespace: default
spec:
  podSelector:
    matchLabels:
      app: myapp
  policyTypes:
  - Ingress
  - Egress
  ingress:
  - from:
    - ipBlock:
        cidr: 172.17.0.0/16
        except:
        - 172.17.1.0/24
    - podSelector:
        matchLabels:
          app: myapp
    ports:
    - protocol: TCP
      port: 6379
  egress:
  - to:
    - ipBlock:
        cidr: 10.0.0.0/24
    ports:
    - protocol: TCP
      port: 5978

Antrea agent:

antctl get rule -oyaml

- direction: In
  from:
    addressGroups:
    - 5e8df597-d026-5144-bdc7-cd162c389dc3
    ipblocks:
    - cidr: 172.17.0.0/16
      except:
      - 172.17.1.0/24
  services:
  - protocol: TCP
    port: "6379"
- direction: Out
  to:
    ipblocks:
    - cidr: 10.0.0.0/24
  services:
  - protocol: TCP
    port: "5978"

antctl get applied-to-group -oyaml

- name: 5e8df597-d026-5144-bdc7-cd162c389dc3
  pods:
  - pod:
      name: myapp-pod-1
      namespace: default
  - pod:
      name: myapp-pod
      namespace: default

antctl get address-group -oyaml

- name: 5e8df597-d026-5144-bdc7-cd162c389dc3
  pods:
  - ip: 10.10.1.4
  - ip: 10.10.1.3

Antrea controller:

antctl get network-policy -oyaml

- name: test-network-policy
  rules:
  - direction: In
    from:
      addressGroups:
      - 5e8df597-d026-5144-bdc7-cd162c389dc3
      ipblocks:
      - cidr: 172.17.0.0/16
        except:
        - 172.17.1.0/24
    services:
    - protocol: TCP
      port:
        type: 0
        intval: 6379
        strval: ""
  - direction: Out
    to:
      ipblocks:
      - cidr: 10.0.0.0/24
    services:
    - protocol: TCP
      port:
        type: 0
        intval: 5978
        strval: ""
  appliedToGroups:
  - 5e8df597-d026-5144-bdc7-cd162c389dc3

antctl get applied-to-group -oyaml

- name: 5e8df597-d026-5144-bdc7-cd162c389dc3
  pods:
  - pod:
      name: myapp-pod-1
      namespace: default
  - pod:
      name: myapp-pod
      namespace: default

antctl get address-group -oyaml

- name: 5e8df597-d026-5144-bdc7-cd162c389dc3
  pods:
  - ip: 10.10.1.4
  - ip: 10.10.1.3

Resolves #239.

@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-networkpolicy: to trigger networkpolicy tests.
  • /skip-networkpolicy: to skip networkpolicy tests.
  • /test-all: to trigger all tests.
  • /skip-all: to skip all tests.

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

@weiqiangt weiqiangt force-pushed the antctl-refactor branch 2 times, most recently from dfac9a6 to fed76f5 Compare February 4, 2020 13:22
@weiqiangt weiqiangt requested a review from antoninbas February 4, 2020 13:28
@weiqiangt weiqiangt force-pushed the antctl-refactor branch 2 times, most recently from 8a48f6d to b626119 Compare February 5, 2020 02:49
@antoninbas
Copy link
Contributor

antoninbas commented Feb 5, 2020

@weiqiangt would you mind moving the openapi stuff to a separate PR (along with the license template change) - and reference #323 in that new PR

Removing the autogenerated code from your anctl refactor PR will make it easier to review

@weiqiangt weiqiangt changed the title [WIP] Refactor antctl framework Refactor antctl framework Feb 6, 2020
@weiqiangt weiqiangt requested a review from tnqn February 6, 2020 00:54
@weiqiangt
Copy link
Contributor Author

@weiqiangt would you mind moving the openapi stuff to a separate PR (along with the license template change) - and reference #323 in that new PR

Removing the autogenerated code from your anctl refactor PR will make it easier to review

Sure, I will separate this CL.

@weiqiangt weiqiangt force-pushed the antctl-refactor branch 2 times, most recently from e4f7392 to bd0e17b Compare February 6, 2020 01:56
@lzhecheng
Copy link
Contributor

Please push your patch again to refresh jenkins jobs' status.

Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

@weiqiangt: thanks for working on this. I guess there can be some misunderstanding in our discussion - what I suggested is that even for Agent, we should move the API server code out of antctl, as even Agent API can be consumed by other clients besides antctl, and one specific example is the Controller, if we want to query Agent info or send ops requests to Agent from a single entity - that is Antrea Controller (it might also mean later we might need to expose Agent API through the Node IP).
Another one - even for Controller, could we also expose some API through UDS, like controller-info, version, etc., so that even when K8s API is down, we can at least do some basic debugging using local CLI. I do not think this is critical though.

pkg/antctl/antctl.go Outdated Show resolved Hide resolved
pkg/antctl/handlers/doc.go Show resolved Hide resolved
pkg/antctl/server.go Outdated Show resolved Hide resolved
@weiqiangt weiqiangt changed the title Refactor antctl framework [WIP]Refactor antctl framework Feb 7, 2020
@weiqiangt weiqiangt force-pushed the antctl-refactor branch 7 times, most recently from 7469dc6 to cb86a58 Compare February 19, 2020 04:16
@weiqiangt weiqiangt changed the title [WIP]Refactor antctl framework Refactor antctl framework Feb 19, 2020
@weiqiangt weiqiangt requested a review from jianjuns February 19, 2020 05:17
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.

Last two questions

func GetMajorVersion() string {
v, err := semver.Parse(Version[1:])
if err != nil {
println(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 not using log but output directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the Version is basically a constant, I think we could just ignore the error. Let me remove this error handling.

Copy link
Contributor Author

@weiqiangt weiqiangt Feb 27, 2020

Choose a reason for hiding this comment

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

I removed GetMajorVersion and GetMinorVersion and made the GetVersion to return a semantic version object.

println(err)
return "0"
}
return fmt.Sprintf("%d.%d", v.Minor, v.Patch)
Copy link
Member

Choose a reason for hiding this comment

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

Why merge minor and patch to minor? I think k8sversion.Info's intention is major for major, minor for minor, gitversion for full version (the Version in this file):

version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:13:49Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}

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 didn't know the git version is used as full version, I would update it.

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.

@weiqiangt
Copy link
Contributor Author

/test-all

tnqn
tnqn previously approved these changes Feb 27, 2020
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.

LGTM

@tnqn
Copy link
Member

tnqn commented Feb 27, 2020

I think you need to update the PR description now.

@jianjuns the PR looks good to me now, could you give another review?

pkg/agent/server/server.go Outdated Show resolved Hide resolved
@weiqiangt
Copy link
Contributor Author

/test-all

// Set the PairName but leave certificate directory blank to generate in-memory by default.
secureServing.ServerCert.CertDirectory = ""
secureServing.ServerCert.PairName = Name
ln, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", Port))
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought I added a comment here before but I could not find it any more. Anyway, have a question here: could we still enable unix domain socket for local CLI? I remember we discussed before security concerns on localhost TCP port without auth. Ideally we should enable the API server on both UDS and later host IP (for remote CLI, and potentially other consumers like Controller, support bundle collection, etc.).
@tnqn

Copy link
Member

Choose a reason for hiding this comment

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

Is 127.0.0.1 same as UDS from security perspective? Do you mean anonymous user can get into the container and access the loopback address?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the server which leverages built-in server used uds, but it looks like the APIServer is not able to set up an UDS listener (it looks up port for some reasons).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, one issue is about no way to restrict what local users/processes can access the API endpoint.
If no good way, we can merge the current implementation for now. But let us explore the possibility of enable UDS.

@lzhecheng
Copy link
Contributor

/test-all

@weiqiangt
Copy link
Contributor Author

/test-e2e

@jianjuns
Copy link
Contributor

jianjuns commented Mar 3, 2020

I think you need to update the PR description now.

@jianjuns the PR looks good to me now, could you give another review?

LGTM overall. Sorry, I did not get time to do a detailed review. I will try to read the code more, but do not wait for me to merge the PR.

@weiqiangt
Copy link
Contributor Author

/test-e2e

@weiqiangt
Copy link
Contributor Author

/test-all

@weiqiangt weiqiangt force-pushed the antctl-refactor branch 2 times, most recently from cbf0c79 to cc35c53 Compare March 3, 2020 07:19
@weiqiangt
Copy link
Contributor Author

/test-e2e

- Set up an API server on antrea agent
- The antctl client is consuming the API server in antrea agent
  instead of using the specific antctl server
- Added API `/rule`, `/appliedtogroup`, `/addressgroup`,
  `/agentinfo` and `version` APIs to the agent API server
- Add `get network-policy`, `get address-group` and `get applied-to-group`
  commands for controller
- Add `get rule`, `get address-group` and `get applied-to-group`
  commands for agent
- Make version file to honor semantic version

Signed-off-by: Weiqiang TANG <weiqiangt@vmware.com>
@lzhecheng
Copy link
Contributor

/test-e2e

@lzhecheng
Copy link
Contributor

/test-e2e

1 similar comment
@lzhecheng
Copy link
Contributor

/test-e2e

@weiqiangt
Copy link
Contributor Author

/test-all

1 similar comment
@lzhecheng
Copy link
Contributor

/test-all

@weiqiangt weiqiangt merged commit 25ad09a into antrea-io:master Mar 4, 2020
@weiqiangt weiqiangt deleted the antctl-refactor branch May 30, 2020 05:57
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.

Antrea CLI to dump applied-to groups, address groups and translated network policies
7 participants