Skip to content

Commit ab04c32

Browse files
committed
Split peers into ingress&&egress
This resulted from discussions in network-policy-api meetings and after consulting apiserver team for best practices. So far ingress and egress peer expressions were symmetric. However moving forward, since we are adding support for egress (northbound) peers and fqdn which might have differences compared to what we want to allow for ingress, we have decided to split the peers into ingress and egress. Signed-off-by: Surya Seetharaman <[email protected]>
1 parent f7e9b37 commit ab04c32

8 files changed

+123
-76
lines changed

apis/v1alpha1/adminnetworkpolicy_types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ type AdminNetworkPolicyIngressRule struct {
128128
Action AdminNetworkPolicyRuleAction `json:"action"`
129129

130130
// From is the list of sources whose traffic this rule applies to.
131-
// If any AdminNetworkPolicyPeer matches the source of incoming
131+
// If any AdminNetworkPolicyIngressPeer matches the source of incoming
132132
// traffic then the specified action is applied.
133133
// This field must be defined and contain at least one item.
134134
//
135135
// Support: Core
136136
//
137137
// +kubebuilder:validation:MinItems=1
138138
// +kubebuilder:validation:MaxItems=100
139-
From []AdminNetworkPolicyPeer `json:"from"`
139+
From []AdminNetworkPolicyIngressPeer `json:"from"`
140140

141141
// Ports allows for matching traffic based on port and protocols.
142142
// This field is a list of ports which should be matched on
@@ -180,18 +180,18 @@ type AdminNetworkPolicyEgressRule struct {
180180
Action AdminNetworkPolicyRuleAction `json:"action"`
181181

182182
// To is the List of destinations whose traffic this rule applies to.
183-
// If any AdminNetworkPolicyPeer matches the destination of outgoing
183+
// If any AdminNetworkPolicyEgressPeer matches the destination of outgoing
184184
// traffic then the specified action is applied.
185185
// This field must be defined and contain at least one item.
186186
//
187187
// Support: Core
188188
//
189189
// +kubebuilder:validation:MinItems=1
190190
// +kubebuilder:validation:MaxItems=100
191-
To []AdminNetworkPolicyPeer `json:"to"`
191+
To []AdminNetworkPolicyEgressPeer `json:"to"`
192192

193193
// Ports allows for matching traffic based on port and protocols.
194-
// This field is a list of destination ports for the outging egress traffic.
194+
// This field is a list of destination ports for the outgoing egress traffic.
195195
// If Ports is not set then the rule does not filter traffic via port.
196196
//
197197
// Support: Core

apis/v1alpha1/baselineadminnetworkpolicy_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ type BaselineAdminNetworkPolicyIngressRule struct {
112112
Action BaselineAdminNetworkPolicyRuleAction `json:"action"`
113113

114114
// From is the list of sources whose traffic this rule applies to.
115-
// If any AdminNetworkPolicyPeer matches the source of incoming
115+
// If any AdminNetworkPolicyIngressPeer matches the source of incoming
116116
// traffic then the specified action is applied.
117117
// This field must be defined and contain at least one item.
118118
//
119119
// Support: Core
120120
//
121121
// +kubebuilder:validation:MinItems=1
122122
// +kubebuilder:validation:MaxItems=100
123-
From []AdminNetworkPolicyPeer `json:"from"`
123+
From []AdminNetworkPolicyIngressPeer `json:"from"`
124124

125125
// Ports allows for matching traffic based on port and protocols.
126126
// This field is a list of ports which should be matched on
@@ -160,15 +160,15 @@ type BaselineAdminNetworkPolicyEgressRule struct {
160160
Action BaselineAdminNetworkPolicyRuleAction `json:"action"`
161161

162162
// To is the list of destinations whose traffic this rule applies to.
163-
// If any AdminNetworkPolicyPeer matches the destination of outgoing
163+
// If any AdminNetworkPolicyEgressPeer matches the destination of outgoing
164164
// traffic then the specified action is applied.
165165
// This field must be defined and contain at least one item.
166166
// +kubebuilder:validation:MinItems=1
167167
// +kubebuilder:validation:MaxItems=100
168168
//
169169
// Support: Core
170170
//
171-
To []AdminNetworkPolicyPeer `json:"to"`
171+
To []AdminNetworkPolicyEgressPeer `json:"to"`
172172

173173
// Ports allows for matching traffic based on port and protocols.
174174
// This field is a list of destination ports for the outging egress traffic.

apis/v1alpha1/shared_types.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,35 @@ type PortRange struct {
120120
End int32 `json:"end"`
121121
}
122122

123-
// AdminNetworkPolicyPeer defines an in-cluster peer to allow traffic to/from.
123+
// AdminNetworkPolicyIngressPeer defines an in-cluster peer to allow traffic to/from.
124124
// Exactly one of the selector pointers must be set for a given peer. If a
125125
// consumer observes none of its fields are set, they must assume an unknown
126126
// option has been specified and fail closed.
127127
// +kubebuilder:validation:MaxProperties=1
128128
// +kubebuilder:validation:MinProperties=1
129-
type AdminNetworkPolicyPeer struct {
129+
type AdminNetworkPolicyIngressPeer struct {
130+
// Namespaces defines a way to select a set of Namespaces.
131+
//
132+
// Support: Core
133+
//
134+
// +optional
135+
Namespaces *NamespacedPeer `json:"namespaces,omitempty"`
136+
// Pods defines a way to select a set of pods in
137+
// in a set of namespaces.
138+
//
139+
// Support: Core
140+
//
141+
// +optional
142+
Pods *NamespacedPodPeer `json:"pods,omitempty"`
143+
}
144+
145+
// AdminNetworkPolicyEgressPeer defines an in-cluster peer to allow traffic to/from.
146+
// Exactly one of the selector pointers must be set for a given peer. If a
147+
// consumer observes none of its fields are set, they must assume an unknown
148+
// option has been specified and fail closed.
149+
// +kubebuilder:validation:MaxProperties=1
150+
// +kubebuilder:validation:MinProperties=1
151+
type AdminNetworkPolicyEgressPeer struct {
130152
// Namespaces defines a way to select a set of Namespaces.
131153
//
132154
// Support: Core

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 54 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/experimental/policy.networking.k8s.io_adminnetworkpolicies.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ spec:
8282
ports:
8383
description: "Ports allows for matching traffic based on port
8484
and protocols. This field is a list of destination ports for
85-
the outging egress traffic. If Ports is not set then the rule
86-
does not filter traffic via port. \n Support: Core"
85+
the outgoing egress traffic. If Ports is not set then the
86+
rule does not filter traffic via port. \n Support: Core"
8787
items:
8888
description: AdminNetworkPolicyPort describes how to select
8989
network ports on pod(s). Exactly one field must be set.
@@ -151,12 +151,12 @@ spec:
151151
type: array
152152
to:
153153
description: "To is the List of destinations whose traffic this
154-
rule applies to. If any AdminNetworkPolicyPeer matches the
155-
destination of outgoing traffic then the specified action
154+
rule applies to. If any AdminNetworkPolicyEgressPeer matches
155+
the destination of outgoing traffic then the specified action
156156
is applied. This field must be defined and contain at least
157157
one item. \n Support: Core"
158158
items:
159-
description: AdminNetworkPolicyPeer defines an in-cluster
159+
description: AdminNetworkPolicyEgressPeer defines an in-cluster
160160
peer to allow traffic to/from. Exactly one of the selector
161161
pointers must be set for a given peer. If a consumer observes
162162
none of its fields are set, they must assume an unknown
@@ -431,12 +431,12 @@ spec:
431431
type: string
432432
from:
433433
description: "From is the list of sources whose traffic this
434-
rule applies to. If any AdminNetworkPolicyPeer matches the
435-
source of incoming traffic then the specified action is applied.
436-
This field must be defined and contain at least one item.
437-
\n Support: Core"
434+
rule applies to. If any AdminNetworkPolicyIngressPeer matches
435+
the source of incoming traffic then the specified action is
436+
applied. This field must be defined and contain at least one
437+
item. \n Support: Core"
438438
items:
439-
description: AdminNetworkPolicyPeer defines an in-cluster
439+
description: AdminNetworkPolicyIngressPeer defines an in-cluster
440440
peer to allow traffic to/from. Exactly one of the selector
441441
pointers must be set for a given peer. If a consumer observes
442442
none of its fields are set, they must assume an unknown

config/crd/experimental/policy.networking.k8s.io_baselineadminnetworkpolicies.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ spec:
143143
type: array
144144
to:
145145
description: "To is the list of destinations whose traffic this
146-
rule applies to. If any AdminNetworkPolicyPeer matches the
147-
destination of outgoing traffic then the specified action
146+
rule applies to. If any AdminNetworkPolicyEgressPeer matches
147+
the destination of outgoing traffic then the specified action
148148
is applied. This field must be defined and contain at least
149149
one item. \n Support: Core"
150150
items:
151-
description: AdminNetworkPolicyPeer defines an in-cluster
151+
description: AdminNetworkPolicyEgressPeer defines an in-cluster
152152
peer to allow traffic to/from. Exactly one of the selector
153153
pointers must be set for a given peer. If a consumer observes
154154
none of its fields are set, they must assume an unknown
@@ -418,12 +418,12 @@ spec:
418418
type: string
419419
from:
420420
description: "From is the list of sources whose traffic this
421-
rule applies to. If any AdminNetworkPolicyPeer matches the
422-
source of incoming traffic then the specified action is applied.
423-
This field must be defined and contain at least one item.
424-
\n Support: Core"
421+
rule applies to. If any AdminNetworkPolicyIngressPeer matches
422+
the source of incoming traffic then the specified action is
423+
applied. This field must be defined and contain at least one
424+
item. \n Support: Core"
425425
items:
426-
description: AdminNetworkPolicyPeer defines an in-cluster
426+
description: AdminNetworkPolicyIngressPeer defines an in-cluster
427427
peer to allow traffic to/from. Exactly one of the selector
428428
pointers must be set for a given peer. If a consumer observes
429429
none of its fields are set, they must assume an unknown

config/crd/standard/policy.networking.k8s.io_adminnetworkpolicies.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ spec:
8282
ports:
8383
description: "Ports allows for matching traffic based on port
8484
and protocols. This field is a list of destination ports for
85-
the outging egress traffic. If Ports is not set then the rule
86-
does not filter traffic via port. \n Support: Core"
85+
the outgoing egress traffic. If Ports is not set then the
86+
rule does not filter traffic via port. \n Support: Core"
8787
items:
8888
description: AdminNetworkPolicyPort describes how to select
8989
network ports on pod(s). Exactly one field must be set.
@@ -147,12 +147,12 @@ spec:
147147
type: array
148148
to:
149149
description: "To is the List of destinations whose traffic this
150-
rule applies to. If any AdminNetworkPolicyPeer matches the
151-
destination of outgoing traffic then the specified action
150+
rule applies to. If any AdminNetworkPolicyEgressPeer matches
151+
the destination of outgoing traffic then the specified action
152152
is applied. This field must be defined and contain at least
153153
one item. \n Support: Core"
154154
items:
155-
description: AdminNetworkPolicyPeer defines an in-cluster
155+
description: AdminNetworkPolicyEgressPeer defines an in-cluster
156156
peer to allow traffic to/from. Exactly one of the selector
157157
pointers must be set for a given peer. If a consumer observes
158158
none of its fields are set, they must assume an unknown
@@ -376,12 +376,12 @@ spec:
376376
type: string
377377
from:
378378
description: "From is the list of sources whose traffic this
379-
rule applies to. If any AdminNetworkPolicyPeer matches the
380-
source of incoming traffic then the specified action is applied.
381-
This field must be defined and contain at least one item.
382-
\n Support: Core"
379+
rule applies to. If any AdminNetworkPolicyIngressPeer matches
380+
the source of incoming traffic then the specified action is
381+
applied. This field must be defined and contain at least one
382+
item. \n Support: Core"
383383
items:
384-
description: AdminNetworkPolicyPeer defines an in-cluster
384+
description: AdminNetworkPolicyIngressPeer defines an in-cluster
385385
peer to allow traffic to/from. Exactly one of the selector
386386
pointers must be set for a given peer. If a consumer observes
387387
none of its fields are set, they must assume an unknown

config/crd/standard/policy.networking.k8s.io_baselineadminnetworkpolicies.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ spec:
139139
type: array
140140
to:
141141
description: "To is the list of destinations whose traffic this
142-
rule applies to. If any AdminNetworkPolicyPeer matches the
143-
destination of outgoing traffic then the specified action
142+
rule applies to. If any AdminNetworkPolicyEgressPeer matches
143+
the destination of outgoing traffic then the specified action
144144
is applied. This field must be defined and contain at least
145145
one item. \n Support: Core"
146146
items:
147-
description: AdminNetworkPolicyPeer defines an in-cluster
147+
description: AdminNetworkPolicyEgressPeer defines an in-cluster
148148
peer to allow traffic to/from. Exactly one of the selector
149149
pointers must be set for a given peer. If a consumer observes
150150
none of its fields are set, they must assume an unknown
@@ -363,12 +363,12 @@ spec:
363363
type: string
364364
from:
365365
description: "From is the list of sources whose traffic this
366-
rule applies to. If any AdminNetworkPolicyPeer matches the
367-
source of incoming traffic then the specified action is applied.
368-
This field must be defined and contain at least one item.
369-
\n Support: Core"
366+
rule applies to. If any AdminNetworkPolicyIngressPeer matches
367+
the source of incoming traffic then the specified action is
368+
applied. This field must be defined and contain at least one
369+
item. \n Support: Core"
370370
items:
371-
description: AdminNetworkPolicyPeer defines an in-cluster
371+
description: AdminNetworkPolicyIngressPeer defines an in-cluster
372372
peer to allow traffic to/from. Exactly one of the selector
373373
pointers must be set for a given peer. If a consumer observes
374374
none of its fields are set, they must assume an unknown

0 commit comments

Comments
 (0)