Skip to content

Commit b0532b1

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 6774f36 commit b0532b1

8 files changed

+145
-96
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: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,37 @@ 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 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 all pods within a set of Namespaces.
131+
// Note that host-networked pods are not included in this type of peer.
132+
//
133+
// Support: Core
134+
//
135+
// +optional
136+
Namespaces *NamespacedPeer `json:"namespaces,omitempty"`
137+
// Pods defines a way to select a set of pods in
138+
// in a set of namespaces. Note that host-networked pods
139+
// are not included in this type of peer.
140+
//
141+
// Support: Core
142+
//
143+
// +optional
144+
Pods *NamespacedPodPeer `json:"pods,omitempty"`
145+
}
146+
147+
// AdminNetworkPolicyEgressPeer defines an in-cluster peer to allow traffic to.
148+
// Exactly one of the selector pointers must be set for a given peer. If a
149+
// consumer observes none of its fields are set, they must assume an unknown
150+
// option has been specified and fail closed.
151+
// +kubebuilder:validation:MaxProperties=1
152+
// +kubebuilder:validation:MinProperties=1
153+
type AdminNetworkPolicyEgressPeer struct {
130154
// Namespaces defines a way to select all pods within a set of Namespaces.
131155
// Note that host-networked pods are not included in this type of peer.
132156
//

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: 15 additions & 15 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,16 +151,16 @@ 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
160-
peer to allow traffic to/from. Exactly one of the selector
161-
pointers must be set for a given peer. If a consumer observes
162-
none of its fields are set, they must assume an unknown
163-
option has been specified and fail closed.
159+
description: AdminNetworkPolicyEgressPeer defines an in-cluster
160+
peer to allow traffic to. Exactly one of the selector pointers
161+
must be set for a given peer. If a consumer observes none
162+
of its fields are set, they must assume an unknown option
163+
has been specified and fail closed.
164164
maxProperties: 1
165165
minProperties: 1
166166
properties:
@@ -435,13 +435,13 @@ spec:
435435
type: string
436436
from:
437437
description: "From is the list of sources whose traffic this
438-
rule applies to. If any AdminNetworkPolicyPeer matches the
439-
source of incoming traffic then the specified action is applied.
440-
This field must be defined and contain at least one item.
441-
\n Support: Core"
438+
rule applies to. If any AdminNetworkPolicyIngressPeer matches
439+
the source of incoming traffic then the specified action is
440+
applied. This field must be defined and contain at least one
441+
item. \n Support: Core"
442442
items:
443-
description: AdminNetworkPolicyPeer defines an in-cluster
444-
peer to allow traffic to/from. Exactly one of the selector
443+
description: AdminNetworkPolicyIngressPeer defines an in-cluster
444+
peer to allow traffic from. Exactly one of the selector
445445
pointers must be set for a given peer. If a consumer observes
446446
none of its fields are set, they must assume an unknown
447447
option has been specified and fail closed.

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,16 @@ 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
152-
peer to allow traffic to/from. Exactly one of the selector
153-
pointers must be set for a given peer. If a consumer observes
154-
none of its fields are set, they must assume an unknown
155-
option has been specified and fail closed.
151+
description: AdminNetworkPolicyEgressPeer defines an in-cluster
152+
peer to allow traffic to. Exactly one of the selector pointers
153+
must be set for a given peer. If a consumer observes none
154+
of its fields are set, they must assume an unknown option
155+
has been specified and fail closed.
156156
maxProperties: 1
157157
minProperties: 1
158158
properties:
@@ -422,13 +422,13 @@ spec:
422422
type: string
423423
from:
424424
description: "From is the list of sources whose traffic this
425-
rule applies to. If any AdminNetworkPolicyPeer matches the
426-
source of incoming traffic then the specified action is applied.
427-
This field must be defined and contain at least one item.
428-
\n Support: Core"
425+
rule applies to. If any AdminNetworkPolicyIngressPeer matches
426+
the source of incoming traffic then the specified action is
427+
applied. This field must be defined and contain at least one
428+
item. \n Support: Core"
429429
items:
430-
description: AdminNetworkPolicyPeer defines an in-cluster
431-
peer to allow traffic to/from. Exactly one of the selector
430+
description: AdminNetworkPolicyIngressPeer defines an in-cluster
431+
peer to allow traffic from. Exactly one of the selector
432432
pointers must be set for a given peer. If a consumer observes
433433
none of its fields are set, they must assume an unknown
434434
option has been specified and fail closed.

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

Lines changed: 15 additions & 15 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,16 +147,16 @@ 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
156-
peer to allow traffic to/from. Exactly one of the selector
157-
pointers must be set for a given peer. If a consumer observes
158-
none of its fields are set, they must assume an unknown
159-
option has been specified and fail closed.
155+
description: AdminNetworkPolicyEgressPeer defines an in-cluster
156+
peer to allow traffic to. Exactly one of the selector pointers
157+
must be set for a given peer. If a consumer observes none
158+
of its fields are set, they must assume an unknown option
159+
has been specified and fail closed.
160160
maxProperties: 1
161161
minProperties: 1
162162
properties:
@@ -380,13 +380,13 @@ spec:
380380
type: string
381381
from:
382382
description: "From is the list of sources whose traffic this
383-
rule applies to. If any AdminNetworkPolicyPeer matches the
384-
source of incoming traffic then the specified action is applied.
385-
This field must be defined and contain at least one item.
386-
\n Support: Core"
383+
rule applies to. If any AdminNetworkPolicyIngressPeer matches
384+
the source of incoming traffic then the specified action is
385+
applied. This field must be defined and contain at least one
386+
item. \n Support: Core"
387387
items:
388-
description: AdminNetworkPolicyPeer defines an in-cluster
389-
peer to allow traffic to/from. Exactly one of the selector
388+
description: AdminNetworkPolicyIngressPeer defines an in-cluster
389+
peer to allow traffic from. Exactly one of the selector
390390
pointers must be set for a given peer. If a consumer observes
391391
none of its fields are set, they must assume an unknown
392392
option has been specified and fail closed.

0 commit comments

Comments
 (0)