Skip to content

Commit 274184a

Browse files
committed
Respond to Round 3 of Dan's Comments
- Some smaller changes in grammer and wording. - Internal ordering - TODOs, figure out if Pointer to a slice is valid, and Combine Same/NotSame Labels into a single field Signed-off-by: astoycos <[email protected]>
1 parent ce92791 commit 274184a

6 files changed

+293
-282
lines changed

apis/v1alpha1/adminnetworkpolicy_types.go

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222
//+kubebuilder:object:root=true
2323
//+kubebuilder:subresource:status
2424

25-
// AdminNetworkPolicy is the Schema for the adminnetworkpolicies API.
25+
// AdminNetworkPolicy is a cluster level resource that is part of the
26+
// AdminNetworkPolicy API.
2627
type AdminNetworkPolicy struct {
2728
metav1.TypeMeta `json:",inline"`
2829
metav1.ObjectMeta `json:"metadata"`
@@ -42,36 +43,35 @@ type AdminNetworkPolicyStatus struct {
4243

4344
// AdminNetworkPolicySpec defines the desired state of AdminNetworkPolicy.
4445
type AdminNetworkPolicySpec struct {
45-
// Priority is an int32 value bound to 0 - 1000, the lowest priority,
46-
// "0" corresponds to the highest importance, while higher priorities have
47-
// lower importance.
46+
// Priority is a value from 0 to 1000. Rules with lower priority values have
47+
// higher precedence, and are checked before rules with higher priority values.
48+
// All AdminNetworkPolicy rules have higher precedence than NetworkPolicy or
49+
// BaselineAdminNetworkPolicy rules
4850
// +kubebuilder:validation:Minimum=0
4951
// +kubebuilder:validation:Maximum=1000
5052
Priority int32 `json:"priority"`
5153

5254
// Subject defines the pods to which this AdminNetworkPolicy applies.
5355
Subject AdminNetworkPolicySubject `json:"subject"`
5456

55-
// List of Ingress rules to be applied to the selected pods BEFORE any
56-
// NetworkPolicy or BaselineAdminNetworkPolicy rules have been applied.
57-
// A total of 100 rules will be allowed in each ANP instance.
58-
// ANPs with no ingress rules do not affect ingress traffic.
57+
// Ingress is the list of Ingress rules to be applied to the selected pods.
58+
// A total of 100 rules will be allowed in each ANP instance. ANPs with no
59+
// ingress rules do not affect ingress traffic.
5960
// +optional
6061
// +kubebuilder:validation:MaxItems=100
6162
Ingress []AdminNetworkPolicyIngressRule `json:"ingress,omitempty"`
6263

63-
// List of Egress rules to be applied to the selected pods BEFORE any
64-
// NetworkPolicy or BaselineAdminNetworkPolicy rules have been applied.
65-
// A total of 100 rules will be allowed in each ANP instance.
66-
// ANPs with no egress rules do not affect egress traffic.
64+
// Egress is the list of Egress rules to be applied to the selected pods.
65+
// A total of 100 rules will be allowed in each ANP instance. ANPs with no
66+
// egress rules do not affect egress traffic.
6767
// +optional
6868
// +kubebuilder:validation:MaxItems=100
6969
Egress []AdminNetworkPolicyEgressRule `json:"egress,omitempty"`
7070
}
7171

7272
// AdminNetworkPolicyIngressRule describes an action to take on a particular
7373
// set of traffic destined for pods selected by an AdminNetworkPolicy's
74-
// Subject field. The traffic must match both ports and from.
74+
// Subject field.
7575
type AdminNetworkPolicyIngressRule struct {
7676
// Name is an identifier for this rule, that may be no more than 100 characters
7777
// in length. This field should be used by the implementation to help
@@ -81,35 +81,34 @@ type AdminNetworkPolicyIngressRule struct {
8181
// +kubebuilder:validation:MaxLength=100
8282
Name string `json:"name,omitempty"`
8383

84-
// Action specifies the affect this rule will have on matching traffic,
85-
// currently the following actions are supported:
86-
// Allow: allows the selected traffic
84+
// Action specifies the effect this rule will have on matching traffic.
85+
// Currently the following actions are supported:
86+
// Allow: allows the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
8787
// Deny: denies the selected traffic
8888
// Pass: instructs the selected traffic to skip any remaining ANP rules, and
8989
// then pass execution to any NetworkPolicies that select the pod.
9090
// If the pod is not selected by any NetworkPolicies then execution
9191
// is passed to any BaselineAdminNetworkPolicies that select the pod.
92-
// This field is mandatory.
9392
Action AdminNetworkPolicyRuleAction `json:"action"`
9493

95-
// Ports allows for matching traffic based on port and protocols.
96-
// If Ports is not set then traffic is not filtered via port.
97-
// +optional
98-
// +kubebuilder:validation:MaxItems=100
99-
Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
100-
101-
// List of sources whose traffic this AdminNetworkPolicyRule applies to.
102-
// If any adminNetworkPolicyPeer matches the source of incoming
94+
// From is the list of sources whose traffic this rule applies to.
95+
// If any AdminNetworkPolicyPeer matches the source of incoming
10396
// traffic then the specified action is applied.
10497
// This field must be defined and contain at least one item.
10598
// +kubebuilder:validation:MinItems=1
10699
// +kubebuilder:validation:MaxItems=100
107100
From []AdminNetworkPolicyPeer `json:"from"`
101+
102+
// Ports allows for matching traffic based on port and protocols.
103+
// If Ports is not set then the rule does not filter traffic via port.
104+
// +optional
105+
// +kubebuilder:validation:MaxItems=100
106+
Ports *[]AdminNetworkPolicyPort `json:"ports,omitempty"`
108107
}
109108

110109
// AdminNetworkPolicyEgressRule describes an action to take on a particular
111110
// set of traffic originating from pods selected by a AdminNetworkPolicy's
112-
// Subject field. The traffic must match both ports and to.
111+
// Subject field.
113112
type AdminNetworkPolicyEgressRule struct {
114113
// Name is an identifier for this rule, that may be no more than 100 characters
115114
// in length. This field should be used by the implementation to help
@@ -119,45 +118,51 @@ type AdminNetworkPolicyEgressRule struct {
119118
// +kubebuilder:validation:MaxLength=100
120119
Name string `json:"name,omitempty"`
121120

122-
// Action specifies the affect this rule will have on matching traffic,
123-
// currently the following actions are supported:
121+
// Action specifies the effect this rule will have on matching traffic.
122+
// Currently the following actions are supported:
124123
// Allow: allows the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
125-
// Deny: denies the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
124+
// Deny: denies the selected traffic
126125
// Pass: instructs the selected traffic to skip any remaining ANP rules, and
127126
// then pass execution to any NetworkPolicies that select the pod.
128127
// If the pod is not selected by any NetworkPolicies then execution
129128
// is passed to any BaselineAdminNetworkPolicies that select the pod.
130-
// This field is mandatory.
131129
Action AdminNetworkPolicyRuleAction `json:"action"`
132130

133-
// Ports allows for matching traffic based on port and protocols.
134-
// If Ports is not set then traffic is not filtered via port.
135-
// +optional
136-
// +kubebuilder:validation:MaxItems=100
137-
Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
138-
139-
// List of destinations whose traffic this adminNetworkPolicyRule applies to.
140-
// If any adminNetworkPolicyPeer matches the destination of outgoing
131+
// To is the List of destinations whose traffic this rule applies to.
132+
// If any AdminNetworkPolicyPeer matches the destination of outgoing
141133
// traffic then the specified action is applied.
142134
// This field must be defined and contain at least one item.
143135
// +kubebuilder:validation:MinItems=1
144136
// +kubebuilder:validation:MaxItems=100
145137
To []AdminNetworkPolicyPeer `json:"to"`
138+
139+
// Ports allows for matching traffic based on port and protocols.
140+
// If Ports is not set then the rule does not filter traffic via port.
141+
// +optional
142+
// +kubebuilder:validation:MaxItems=100
143+
Ports *[]AdminNetworkPolicyPort `json:"ports,omitempty"`
146144
}
147145

148146
// AdminNetworkPolicyRuleAction string describes the AdminNetworkPolicy action type.
149147
// +enum
150148
type AdminNetworkPolicyRuleAction string
151149

152150
const (
153-
// AdminNetworkPolicyRuleActionPass enables admins to provide exceptions to
154-
// AdminNetworkPolicies by passing rule execution directly to any matching
155-
// K8s networkPolicies.
156-
AdminNetworkPolicyRuleActionPass AdminNetworkPolicyRuleAction = "Pass"
157-
// AdminNetworkPolicyRuleActionDeny enables admins to deny specific traffic.
158-
AdminNetworkPolicyRuleActionDeny AdminNetworkPolicyRuleAction = "Deny"
159-
// AdminNetworkPolicyRuleActionAllow enables admins to specifically allow certain traffic.
151+
// AdminNetworkPolicyRuleActionAllow indicates that matching traffic will be
152+
// allowed regardless of NetworkPolicy and BaselineAdminNetworkPolicy
153+
// rules. Users cannot block traffic which has been matched by an "Allow"
154+
// rule in an AdminNetworkPolicy.
160155
AdminNetworkPolicyRuleActionAllow AdminNetworkPolicyRuleAction = "Allow"
156+
// AdminNetworkPolicyRuleActionDeny indicates that matching traffic will be
157+
// denied before being checked against NetworkPolicy or
158+
// BaselineAdminNetworkPolicy rules. Pods will never receive traffic which
159+
// has been matched by a "Deny" rule in an AdminNetworkPolicy.
160+
AdminNetworkPolicyRuleActionDeny AdminNetworkPolicyRuleAction = "Deny"
161+
// AdminNetworkPolicyRuleActionPass indicates that matching traffic will
162+
// bypass further AdminNetworkPolicy processing (ignoring rules with lower
163+
// precedence) and be allowed or denied based on NetworkPolicy and
164+
// BaselineAdminNetworkPolicy rules.
165+
AdminNetworkPolicyRuleActionPass AdminNetworkPolicyRuleAction = "Pass"
161166
)
162167

163168
//+kubebuilder:object:root=true

apis/v1alpha1/baselineadminnetworkpolicy_types.go

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
//+kubebuilder:subresource:status
2424

2525
// BaselineAdminNetworkPolicy is a cluster level resource that is part of the
26-
// adminNetworkPolicy API.
26+
// AdminNetworkPolicy API.
2727
type BaselineAdminNetworkPolicy struct {
2828
metav1.TypeMeta `json:",inline"`
2929
metav1.ObjectMeta `json:"metadata"`
@@ -48,16 +48,16 @@ type BaselineAdminNetworkPolicySpec struct {
4848
// Subject defines the pods to which this BaselineAdminNetworkPolicy applies.
4949
Subject AdminNetworkPolicySubject `json:"subject"`
5050

51-
// List of Ingress rules to be applied to the selected pods if they are not
52-
// matched by any AdminNetworkPolicy or NetworkPolicy rules.
51+
// Ingress is the list of Ingress rules to be applied to the selected pods
52+
// if they are not matched by any AdminNetworkPolicy or NetworkPolicy rules.
5353
// A total of 100 Ingress rules will be allowed in each BANP instance.
5454
// BANPs with no ingress rules do not affect ingress traffic.
5555
// +optional
5656
// +kubebuilder:validation:MaxItems=100
5757
Ingress []BaselineAdminNetworkPolicyIngressRule `json:"ingress,omitempty"`
5858

59-
// List of Egress rules to be applied to the selected pods if they are not
60-
// matched by any AdminNetworkPolicy or NetworkPolicy rules.
59+
// Egress is the list of Egress rules to be applied to the selected pods if
60+
// they are not matched by any AdminNetworkPolicy or NetworkPolicy rules.
6161
// A total of 100 Egress rules will be allowed in each BANP instance. BANPs
6262
// with no egress rules do not affect egress traffic.
6363
// +optional
@@ -67,7 +67,7 @@ type BaselineAdminNetworkPolicySpec struct {
6767

6868
// BaselineAdminNetworkPolicyIngressRule describes an action to take on a particular
6969
// set of traffic destined for pods selected by a BaselineAdminNetworkPolicy's
70-
// Subject field. The traffic must match both ports and from.
70+
// Subject field.
7171
type BaselineAdminNetworkPolicyIngressRule struct {
7272
// Name is an identifier for this rule, that may be no more than 100 characters
7373
// in length. This field should be used by the implementation to help
@@ -77,29 +77,29 @@ type BaselineAdminNetworkPolicyIngressRule struct {
7777
// +kubebuilder:validation:MaxLength=100
7878
Name string `json:"name,omitempty"`
7979

80-
// Action specifies the affect this rule will have on matching traffic,
81-
// currently the following actions are supported:
80+
// Action specifies the effect this rule will have on matching traffic.
81+
// Currently the following actions are supported:
8282
// Allow: allows the selected traffic
8383
// Deny: denies the selected traffic
84-
// This field is mandatory.
8584
Action BaselineAdminNetworkPolicyRuleAction `json:"action"`
8685

87-
// Ports allows for matching traffic based on port and protocols.
88-
// If Ports is not set then traffic is not filtered via port.
89-
// +optional
90-
Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
91-
92-
// List of sources whose traffic this AdminNetworkPolicyRule applies to.
93-
// If any adminNetworkPolicyPeer matches the source of incoming
86+
// From is the list of sources whose traffic this rule applies to.
87+
// If any AdminNetworkPolicyPeer matches the source of incoming
9488
// traffic then the specified action is applied.
9589
// This field must be defined and contain at least one item.
9690
// +kubebuilder:validation:MinItems=1
9791
From []AdminNetworkPolicyPeer `json:"from"`
92+
93+
// Ports allows for matching traffic based on port and protocols.
94+
// If Ports is not set then the rule does not filter traffic via port.
95+
// +optional
96+
// +kubebuilder:validation:MaxItems=100
97+
Ports *[]AdminNetworkPolicyPort `json:"ports,omitempty"`
9898
}
9999

100100
// AdminNetworkPolicyEgressRule describes an action to take on a particular
101101
// set of traffic originating from pods selected by a BaselineAdminNetworkPolicy's
102-
// Subject field. The traffic must match both ports and to.
102+
// Subject field.
103103
type BaselineAdminNetworkPolicyEgressRule struct {
104104
// Name is an identifier for this rule, that may be no more than 100 characters
105105
// in length. This field should be used by the implementation to help
@@ -109,24 +109,24 @@ type BaselineAdminNetworkPolicyEgressRule struct {
109109
// +kubebuilder:validation:MaxLength=100
110110
Name string `json:"name,omitempty"`
111111

112-
// Action specifies the affect this rule will have on matching traffic,
113-
// currently the following actions are supported:
112+
// Action specifies the effect this rule will have on matching traffic.
113+
// Currently the following actions are supported:
114114
// Allow: allows the selected traffic
115115
// Deny: denies the selected traffic
116-
// This field is mandatory.
117116
Action BaselineAdminNetworkPolicyRuleAction `json:"action"`
118117

119-
// Ports allows for matching traffic based on port and protocols.
120-
// If Ports is not set then traffic is not filtered via port.
121-
// +optional
122-
Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
123-
124-
// List of destinations whose traffic this adminNetworkPolicyRule applies to.
125-
// If any adminNetworkPolicyPeer matches the destination of outgoing
118+
// To is the list of destinations whose traffic this rule applies to.
119+
// If any AdminNetworkPolicyPeer matches the destination of outgoing
126120
// traffic then the specified action is applied.
127121
// This field must be defined and contain at least one item.
128122
// +kubebuilder:validation:MinItems=1
129123
To []AdminNetworkPolicyPeer `json:"to"`
124+
125+
// Ports allows for matching traffic based on port and protocols.
126+
// If Ports is not set then the rule does not filter traffic via port.
127+
// +optional
128+
// +kubebuilder:validation:MaxItems=100
129+
Ports *[]AdminNetworkPolicyPort `json:"ports,omitempty"`
130130
}
131131

132132
// BaselineAdminNetworkPolicyRuleAction string describes the BaselineAdminNetworkPolicy
@@ -135,10 +135,9 @@ type BaselineAdminNetworkPolicyEgressRule struct {
135135
type BaselineAdminNetworkPolicyRuleAction string
136136

137137
const (
138-
139-
// BaselineAdminNetworkPolicyRuleActionDeny enables admins to deny specific traffic.
138+
// BaselineAdminNetworkPolicyRuleActionDeny enables admins to deny traffic.
140139
BaselineAdminNetworkPolicyRuleActionDeny BaselineAdminNetworkPolicyRuleAction = "Deny"
141-
// BaselineAdminNetworkPolicyRuleActionAllow enables admins to specifically allow certain traffic.
140+
// BaselineAdminNetworkPolicyRuleActionAllow enables admins to allow certain traffic.
142141
BaselineAdminNetworkPolicyRuleActionAllow BaselineAdminNetworkPolicyRuleAction = "Allow"
143142
)
144143

apis/v1alpha1/shared_types.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ type NamespacedPodSubject struct {
5050
// +kubebuilder:validation:MaxProperties=1
5151
// +kubebuilder:validation:MinProperties=1
5252
type AdminNetworkPolicyPort struct {
53-
// NamedPort selects a port on a pod(s) based on name.
53+
// Port selects a port on a pod(s) based on number.
5454
// +optional
55-
NamedPort *string `json:"namedPort,omitempty"`
55+
PortNumber *Port `json:"portNumber,omitempty"`
5656

57-
// Port selects a port on a pod(s) based on number.
57+
// NamedPort selects a port on a pod(s) based on name.
5858
// +optional
59-
Port *Port `json:"port,omitempty"`
59+
NamedPort *string `json:"namedPort,omitempty"`
6060

6161
// PortRange selects a port range on a pod(s) based on provided start and end
6262
// values.
@@ -65,24 +65,24 @@ type AdminNetworkPolicyPort struct {
6565
}
6666

6767
type Port struct {
68-
// The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified,
69-
// this field defaults to TCP.
68+
// Protocol is the network protocol (TCP, UDP, or SCTP) which traffic must
69+
// match. If not specified, this field defaults to TCP.
7070
// +kubebuilder:default=TCP
71-
Protocol *v1.Protocol `json:"protocol"`
71+
Protocol v1.Protocol `json:"protocol"`
7272

7373
// Number defines a network port value.
7474
// +kubebuilder:validation:Minimum=1
7575
// +kubebuilder:validation:Maximum=65535
76-
Number int32 `json:"number"`
76+
Port int32 `json:"port"`
7777
}
7878

7979
// PortRange defines an inclusive range of ports from the the assigned Start value
8080
// to End value.
8181
type PortRange struct {
82-
// The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified,
83-
// this field defaults to TCP.
82+
// Protocol is the network protocol (TCP, UDP, or SCTP) which traffic must
83+
// match. If not specified, this field defaults to TCP.
8484
// +kubebuilder:default=TCP
85-
Protocol *v1.Protocol `json:"protocol,omitempty"`
85+
Protocol v1.Protocol `json:"protocol,omitempty"`
8686

8787
// Start defines a network port that is the start of a port range, the Start
8888
// value must be less than End.
@@ -107,7 +107,7 @@ type AdminNetworkPolicyPeer struct {
107107
// Namespaces defines a way to select a set of Namespaces.
108108
// +optional
109109
Namespaces *NamespacedPeer `json:"namespaces,omitempty"`
110-
// NamespacedPods defines a way to select a set of pods in
110+
// Pods defines a way to select a set of pods in
111111
// in a set of namespaces.
112112
// +optional
113113
Pods *NamespacedPodPeer `json:"pods,omitempty"`
@@ -116,8 +116,8 @@ type AdminNetworkPolicyPeer struct {
116116
type NamespaceRelation string
117117

118118
const (
119-
NamespaceSame NamespaceRelation = "Self"
120-
NamespaceNotSame NamespaceRelation = "NotSelf"
119+
NamespaceSelf NamespaceRelation = "Self"
120+
NamespaceNotSelf NamespaceRelation = "NotSelf"
121121
)
122122

123123
// NamespacedPeer defines a flexible way to select Namespaces in a cluster.
@@ -127,9 +127,10 @@ const (
127127
// +kubebuilder:validation:MaxProperties=1
128128
// +kubebuilder:validation:MinProperties=1
129129
type NamespacedPeer struct {
130-
// Related provides a mechanism for selecting namespaces. It can be set to
131-
// "Self" to select all pods in the subject's namespace, and set to "NotSelf"
132-
// to select all pods not in the subject's namespace.
130+
// Related provides a mechanism for selecting namespaces relative to the
131+
// subject pod. A value of "Self" matches the subject pod's namespace,
132+
// while a value of "NotSelf" matches namespaces other than the subject
133+
// pod's namespace.
133134
// +optional
134135
Related *NamespaceRelation `json:"related,omitempty"`
135136

@@ -165,5 +166,5 @@ type NamespacedPodPeer struct {
165166
// PodSelector is a labelSelector used to select Pods, This field is NOT optional,
166167
// follows standard label selector semantics and if present but empty, it selects
167168
// all Pods.
168-
PodSelector *metav1.LabelSelector `json:"podSelector"`
169+
PodSelector metav1.LabelSelector `json:"podSelector"`
169170
}

0 commit comments

Comments
 (0)