• Kubernetes Submit Queue's avatar
    Merge pull request #61689 from Lion-Wei/kubectl-np · 44ede98e
    Kubernetes Submit Queue authored
    Automatic merge from submit-queue (batch tested with PRs 62510, 61689). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.
    
    Extend kubectl describe for networkPolicy
    
    **What this PR does / why we need it**:
    Recently `networkpolicy` was allowed podSelector and namespaceSelector to be specified together in a NetworkPolicyPeer, so we need to extend `kubectl describe` for networkpolicy.
    
    **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
    Fixes kubernetes/kubectl#376
    
    **Special notes for your reviewer**:
    Here is the example output of `kubectl describe networkpolicies`:
    NetworkPolicy file:
    ```yaml
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: test-network-policy
      namespace: default
    spec:
      podSelector:
        matchLabels:
          role: db
      ingress:
      - from:
        - namespaceSelector:
            matchLabels:
              project: myproject
          podSelector:
            matchLabels:
              role: frontend
        ports:
        - protocol: TCP
          port: 6379
      egress:
      - to:
        - namespaceSelector:
            matchLabels:
              project: myproject
          podSelector:
            matchLabels:
              role: frontend
        ports:
        - protocol: TCP
          port: 6379
    ```
    describe:
    ```shell
    # ./kubectl describe netpol test-network-policy
    Name:         test-network-policy
    Namespace:    default
    Created on:   2018-03-26 15:20:11 +0800 CST
    Labels:       <none>
    Annotations:  <none>
    Spec:
      PodSelector:     role=db
      Allowing ingress traffic:
        To Port: 6379/TCP
        From NamespaceSelector: project=myproject
             PodSelector: role=frontend
      Allowing egress traffic:
        To Port: 6379/TCP
        To NamespaceSelector: project=myproject
           PodSelector: role=frontend
      Policy Types: Ingress, Egress
    
    ```
    
    **Release note**:
    ```release-note
    NONE
    ```
    44ede98e
describe_test.go 76.1 KB