Skip to content

Commit

Permalink
Add support for Namespace scoped NetworkPolicy CRD (antrea-io#775)
Browse files Browse the repository at this point in the history
* Add API types for Namespaced Antrea NetworkPolicy

* Update priority to float64

Add new CRD yamls only when explicitly set.

* Update apigroup for ExternalEndpoint CRD

Move ExternalEndpoint to core group.

* Fix name mismatch for externalNode field

* Move security and core group to v1alpha1

Address comments.

* Minor patches to ANP CRD types

- Nameport.protocol is no longer a pointer --> consistent with k8s core.servicePort
- ExternalEndPoint.ip is a string ---> so it is readable to end user.
- Add "omitempty" to all fields ---> we potentially can have some fields unset.
- added webhook methods ---> allows ExternalEntity to hookup to webhook service.

Co-authored-by: Abhishek Raut <rauta@vmware.com>
Co-authored-by: Su Wang <suw@vmware.com>
  • Loading branch information
3 people authored and GraysonWu committed Sep 23, 2020
1 parent 9aef83c commit ec5c1ec
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 0 deletions.
48 changes: 48 additions & 0 deletions build/yamls/base/core-crds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: externalentities.core.antrea.tanzu.vmware.com
spec:
group: core.antrea.tanzu.vmware.com
versions:
- name: v1alpha1
served: true
storage: true
scope: Namespaced
names:
plural: externalentities
singular: externalentity
kind: ExternalEntity
shortNames:
- ee
# Prune any unknown fields
preserveUnknownFields: false
validation:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
endpoints:
type: array
items:
type: object
properties:
ip:
type: string
format: ipv4
name:
type: string
ports:
type: array
items:
type: object
properties:
protocol:
type: string
port:
x-kubernetes-int-or-string: true
externalNode:
type: string
121 changes: 121 additions & 0 deletions build/yamls/base/security-crds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: networkpolicies.security.antrea.tanzu.vmware.com
spec:
group: security.antrea.tanzu.vmware.com
versions:
- name: v1alpha1
served: true
storage: true
scope: Namespaced
names:
plural: networkpolicies
singular: networkpolicy
kind: NetworkPolicy
shortNames:
- anp
# Prune any unknown fields
preserveUnknownFields: false
validation:
openAPIV3Schema:
type: object
properties:
spec:
# Ensure that Spec.AppliedTo and Spec.Priority fields are set
required:
- appliedTo
- priority
type: object
properties:
priority:
type: number
format: float
# Ensure that Spec.Priority field is between 1 and 10000
minimum: 1.0
maximum: 10000.0
appliedTo:
type: array
items:
type: object
# Ensure that Spec.AppliedTo does not allow NamespaceSelector/IPBlock field
properties:
podSelector:
type: object
additionalProperties:
type: object
externalEntitySelector:
type: object
additionalProperties:
type: object
ingress:
type: array
items:
type: object
required:
- action
properties:
# Ensure that Action field allows only ALLOW and DROP values
action:
type: string
pattern: '\bALLOW|\bAllow|\ballow|\bDROP|\bDrop|\bdrop'
ports:
type: array
items:
type: object
properties:
protocol:
type: string
port:
x-kubernetes-int-or-string: true
from:
type: array
items:
type: object
properties:
podSelector:
x-kubernetes-preserve-unknown-fields: true
namespaceSelector:
x-kubernetes-preserve-unknown-fields: true
ipBlock:
type: object
properties:
cidr:
type: string
format: cidr
egress:
type: array
items:
type: object
required:
- action
properties:
# Ensure that Action field allows only ALLOW and DROP values
action:
type: string
pattern: '\bALLOW|\bAllow|\ballow|\bDROP|\bDrop|\bdrop'
ports:
type: array
items:
type: object
properties:
protocol:
type: string
port:
x-kubernetes-int-or-string: true
to:
type: array
items:
type: object
properties:
podSelector:
x-kubernetes-preserve-unknown-fields: true
namespaceSelector:
x-kubernetes-preserve-unknown-fields: true
ipBlock:
type: object
properties:
cidr:
type: string
format: cidr
22 changes: 22 additions & 0 deletions build/yamls/patches/np/npRbac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: antrea-controller
rules:
- apiGroups:
- security.antrea.tanzu.vmware.com
resources:
- networkpolicies
verbs:
- get
- watch
- list
- apiGroups:
- core.antrea.tanzu.vmware.com
resources:
- externalentities
verbs:
- get
- watch
- list

0 comments on commit ec5c1ec

Please sign in to comment.