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

Convert Network Policy Rules into json format and pass it as a string through gRPC #464

Open
clu2xlu opened this issue Apr 8, 2021 · 0 comments

Comments

@clu2xlu
Copy link
Contributor

clu2xlu commented Apr 8, 2021

Mizar and Arktos communicates through gRPC protocol.
The desired Network policy gRPC message should be:

message BuiltinsNetworkPolicyMessage {
  string name = 1;
  string tenant = 2;
  string namespace = 3; 
  string spec = 4;
}

https://github.com/clu2xlu/arktos/blob/poc/pkg/controller/mizar/builtins.proto#L75-L79

However, in go, the network policy obj's Spec is not in String format. e.g. policy.Spec cannot be converted to string directly.
https://github.com/clu2xlu/arktos/blob/poc/pkg/controller/mizar/util.go#L125

For this task, you will need to use NetworkPolicySpec, Ingress and Egress to convert network policy's spec into a json string

The desired spec json strong looks like this:

{'podSelector': {'matchLabels': {'run': 'pod0'}}, 'ingress': [{'ports': [{'protocol': 'TCP', 'port': 8000}, {'protocol': 'TCP', 'port': 5976}], 'from': [{'podSelector': {'matchLabels': {'run': 'pod1'}}}]}], 'egress': [{'ports': [{'protocol': 'TCP', 'port': 8000}], 'to': [{'podSelector': {'matchLabels': {'run': 'pod2'}}}]}], 'policyTypes': ['Ingress', 'Egress']}

it's yaml is

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: test-network-policy
  namespace: default
spec:
  podSelector:
    matchLabels:
      run: pod0
  policyTypes:
  - Ingress
  - Egress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          run: pod1
    ports:
    - protocol: TCP
      port: 8000
    - protocol: TCP
      port: 5976
  egress:
  - to:
    - podSelector:
        matchLabels:
          run: pod2
    ports:
    - protocol: TCP
      port: 8000

NOTE: please use my branch for now:

For mizar: use branch poc
https://github.com/clu2xlu/mizar/tree/poc

For arktos: use branch poc
https://github.com/clu2xlu/arktos/tree/poc

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

No branches or pull requests

1 participant