Skip to content

Commit ce92791

Browse files
committed
Respond to Round 2 of Dan Comments
Fix some nits Remove a level of indirection: `PodPeer` Change Ports protocol default Update some comment documentation Signed-off-by: Andrew Stoycos <[email protected]>
1 parent 7b7c961 commit ce92791

6 files changed

+725
-740
lines changed

apis/v1alpha1/adminnetworkpolicy_types.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ type AdminNetworkPolicy struct {
3535
Status AdminNetworkPolicyStatus `json:"status,omitempty"`
3636
}
3737

38+
// AdminNetworkPolicyStatus defines the observed state of AdminNetworkPolicy.
39+
type AdminNetworkPolicyStatus struct {
40+
Conditions []metav1.Condition `json:"conditions"`
41+
}
42+
3843
// AdminNetworkPolicySpec defines the desired state of AdminNetworkPolicy.
3944
type AdminNetworkPolicySpec struct {
4045
// Priority is an int32 value bound to 0 - 1000, the lowest priority,
@@ -48,15 +53,15 @@ type AdminNetworkPolicySpec struct {
4853
Subject AdminNetworkPolicySubject `json:"subject"`
4954

5055
// List of Ingress rules to be applied to the selected pods BEFORE any
51-
// NetworkPolicy or BaslineAdminNetworkPolicy rules have been applied.
56+
// NetworkPolicy or BaselineAdminNetworkPolicy rules have been applied.
5257
// A total of 100 rules will be allowed in each ANP instance.
5358
// ANPs with no ingress rules do not affect ingress traffic.
5459
// +optional
5560
// +kubebuilder:validation:MaxItems=100
5661
Ingress []AdminNetworkPolicyIngressRule `json:"ingress,omitempty"`
5762

5863
// List of Egress rules to be applied to the selected pods BEFORE any
59-
// NetworkPolicy or BaslineAdminNetworkPolicy rules have been applied.
64+
// NetworkPolicy or BaselineAdminNetworkPolicy rules have been applied.
6065
// A total of 100 rules will be allowed in each ANP instance.
6166
// ANPs with no egress rules do not affect egress traffic.
6267
// +optional
@@ -69,12 +74,15 @@ type AdminNetworkPolicySpec struct {
6974
// Subject field. The traffic must match both ports and from.
7075
type AdminNetworkPolicyIngressRule struct {
7176
// Name is an identifier for this rule, that may be no more than 100 characters
72-
// in length.
77+
// in length. This field should be used by the implementation to help
78+
// improve observability, readability and error-reporting for any applied
79+
// AdminNetworkPolicies.
7380
// +optional
7481
// +kubebuilder:validation:MaxLength=100
7582
Name string `json:"name,omitempty"`
7683

77-
// Action specifies whether this rule must pass, allow or deny traffic.
84+
// Action specifies the affect this rule will have on matching traffic,
85+
// currently the following actions are supported:
7886
// Allow: allows the selected traffic
7987
// Deny: denies the selected traffic
8088
// Pass: instructs the selected traffic to skip any remaining ANP rules, and
@@ -84,15 +92,16 @@ type AdminNetworkPolicyIngressRule struct {
8492
// This field is mandatory.
8593
Action AdminNetworkPolicyRuleAction `json:"action"`
8694

87-
// Ports allows for matching traffic based on port and protocols.
88-
// If Ports is empty or missing then traffic is not filtered via port.
95+
// Ports allows for matching traffic based on port and protocols.
96+
// If Ports is not set then traffic is not filtered via port.
8997
// +optional
9098
// +kubebuilder:validation:MaxItems=100
9199
Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
92100

93101
// List of sources whose traffic this AdminNetworkPolicyRule applies to.
94-
// Items in this list are combined using a logical OR
95-
// operation. This field must be defined and contain at least one item.
102+
// If any adminNetworkPolicyPeer matches the source of incoming
103+
// traffic then the specified action is applied.
104+
// This field must be defined and contain at least one item.
96105
// +kubebuilder:validation:MinItems=1
97106
// +kubebuilder:validation:MaxItems=100
98107
From []AdminNetworkPolicyPeer `json:"from"`
@@ -103,12 +112,15 @@ type AdminNetworkPolicyIngressRule struct {
103112
// Subject field. The traffic must match both ports and to.
104113
type AdminNetworkPolicyEgressRule struct {
105114
// Name is an identifier for this rule, that may be no more than 100 characters
106-
// in length.
115+
// in length. This field should be used by the implementation to help
116+
// improve observability, readability and error-reporting for any applied
117+
// AdminNetworkPolicies.
107118
// +optional
108119
// +kubebuilder:validation:MaxLength=100
109120
Name string `json:"name,omitempty"`
110121

111-
// Action specifies whether this rule must pass, allow or deny traffic.
122+
// Action specifies the affect this rule will have on matching traffic,
123+
// currently the following actions are supported:
112124
// Allow: allows the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
113125
// Deny: denies the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
114126
// Pass: instructs the selected traffic to skip any remaining ANP rules, and
@@ -119,14 +131,15 @@ type AdminNetworkPolicyEgressRule struct {
119131
Action AdminNetworkPolicyRuleAction `json:"action"`
120132

121133
// Ports allows for matching traffic based on port and protocols.
122-
// If Ports is empty or missing then traffic is not filtered via port.
134+
// If Ports is not set then traffic is not filtered via port.
123135
// +optional
124136
// +kubebuilder:validation:MaxItems=100
125137
Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
126138

127-
// List of destinations to which traffic will be allowed/denied/passed from the entities
128-
// selected by this AdminNetworkPolicyRule. Items in this list are combined using a logical OR
129-
// operation. This field must be defined and contain at least one item.
139+
// List of destinations whose traffic this adminNetworkPolicyRule applies to.
140+
// If any adminNetworkPolicyPeer matches the destination of outgoing
141+
// traffic then the specified action is applied.
142+
// This field must be defined and contain at least one item.
130143
// +kubebuilder:validation:MinItems=1
131144
// +kubebuilder:validation:MaxItems=100
132145
To []AdminNetworkPolicyPeer `json:"to"`
@@ -137,12 +150,13 @@ type AdminNetworkPolicyEgressRule struct {
137150
type AdminNetworkPolicyRuleAction string
138151

139152
const (
140-
// RuleActionPass enables admins to provide exceptions to AdminNetworkPolicies and delegate this rule to
141-
// K8s NetworkPolicies.
153+
// AdminNetworkPolicyRuleActionPass enables admins to provide exceptions to
154+
// AdminNetworkPolicies by passing rule execution directly to any matching
155+
// K8s networkPolicies.
142156
AdminNetworkPolicyRuleActionPass AdminNetworkPolicyRuleAction = "Pass"
143-
// RuleActionDeny enables admins to deny specific traffic.
157+
// AdminNetworkPolicyRuleActionDeny enables admins to deny specific traffic.
144158
AdminNetworkPolicyRuleActionDeny AdminNetworkPolicyRuleAction = "Deny"
145-
// RuleActionAllow enables admins to specifically allow certain traffic.
159+
// AdminNetworkPolicyRuleActionAllow enables admins to specifically allow certain traffic.
146160
AdminNetworkPolicyRuleActionAllow AdminNetworkPolicyRuleAction = "Allow"
147161
)
148162

apis/v1alpha1/baselineadminnetworkpolicy_types.go

Lines changed: 39 additions & 25 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"`
@@ -33,7 +33,13 @@ type BaselineAdminNetworkPolicy struct {
3333

3434
// Status is the status to be reported by the implementation.
3535
// +optional
36-
Status AdminNetworkPolicyStatus `json:"status,omitempty"`
36+
Status BaselineAdminNetworkPolicyStatus `json:"status,omitempty"`
37+
}
38+
39+
// BaselineAdminNetworkPolicyStatus defines the observed state of
40+
// BaselineAdminNetworkPolicy.
41+
type BaselineAdminNetworkPolicyStatus struct {
42+
Conditions []metav1.Condition `json:"conditions"`
3743
}
3844

3945
// BaselineAdminNetworkPolicySpec defines the desired state of
@@ -42,47 +48,51 @@ type BaselineAdminNetworkPolicySpec struct {
4248
// Subject defines the pods to which this BaselineAdminNetworkPolicy applies.
4349
Subject AdminNetworkPolicySubject `json:"subject"`
4450

45-
// List of Ingress rules to be applied to the selected pods AFTER all
46-
// AdminNetworkPolicy and NetworkPolicy rules have been applied.
51+
// List of Ingress rules to be applied to the selected pods if they are not
52+
// matched by any AdminNetworkPolicy or NetworkPolicy rules.
4753
// A total of 100 Ingress rules will be allowed in each BANP instance.
4854
// BANPs with no ingress rules do not affect ingress traffic.
4955
// +optional
5056
// +kubebuilder:validation:MaxItems=100
51-
Ingress []AdminNetworkPolicyIngressRule `json:"ingress,omitempty"`
57+
Ingress []BaselineAdminNetworkPolicyIngressRule `json:"ingress,omitempty"`
5258

53-
// List of Egress rules to be applied to the selected pods AFTER all
54-
// AdminNetworkPolicy and NetworkPolicy rules have been applied.
55-
// A total of 100 Egress rules will be allowed in each BANP instance. ANPs
59+
// List of Egress rules to be applied to the selected pods if they are not
60+
// matched by any AdminNetworkPolicy or NetworkPolicy rules.
61+
// A total of 100 Egress rules will be allowed in each BANP instance. BANPs
5662
// with no egress rules do not affect egress traffic.
5763
// +optional
5864
// +kubebuilder:validation:MaxItems=100
59-
Egress []AdminNetworkPolicyEgressRule `json:"egress,omitempty"`
65+
Egress []BaselineAdminNetworkPolicyEgressRule `json:"egress,omitempty"`
6066
}
6167

6268
// BaselineAdminNetworkPolicyIngressRule describes an action to take on a particular
6369
// set of traffic destined for pods selected by a BaselineAdminNetworkPolicy's
6470
// Subject field. The traffic must match both ports and from.
6571
type BaselineAdminNetworkPolicyIngressRule struct {
6672
// Name is an identifier for this rule, that may be no more than 100 characters
67-
// in length.
73+
// in length. This field should be used by the implementation to help
74+
// improve observability, readability and error-reporting for any applied
75+
// BaselineAdminNetworkPolicies.
6876
// +optional
6977
// +kubebuilder:validation:MaxLength=100
7078
Name string `json:"name,omitempty"`
7179

72-
// Action specifies whether this rule must allow or deny traffic.
80+
// Action specifies the affect this rule will have on matching traffic,
81+
// currently the following actions are supported:
7382
// Allow: allows the selected traffic
7483
// Deny: denies the selected traffic
7584
// This field is mandatory.
7685
Action BaselineAdminNetworkPolicyRuleAction `json:"action"`
7786

7887
// Ports allows for matching traffic based on port and protocols.
79-
// If Ports is empty or missing then traffic is not filtered via port.
88+
// If Ports is not set then traffic is not filtered via port.
8089
// +optional
8190
Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
8291

8392
// List of sources whose traffic this AdminNetworkPolicyRule applies to.
84-
// Items in this list are combined using a logical OR
85-
// operation. This field must be defined and contain at least one item.
93+
// If any adminNetworkPolicyPeer matches the source of incoming
94+
// traffic then the specified action is applied.
95+
// This field must be defined and contain at least one item.
8696
// +kubebuilder:validation:MinItems=1
8797
From []AdminNetworkPolicyPeer `json:"from"`
8898
}
@@ -92,25 +102,29 @@ type BaselineAdminNetworkPolicyIngressRule struct {
92102
// Subject field. The traffic must match both ports and to.
93103
type BaselineAdminNetworkPolicyEgressRule struct {
94104
// Name is an identifier for this rule, that may be no more than 100 characters
95-
// in length.
105+
// in length. This field should be used by the implementation to help
106+
// improve observability, readability and error-reporting for any applied
107+
// BaselineAdminNetworkPolicies.
96108
// +optional
97109
// +kubebuilder:validation:MaxLength=100
98110
Name string `json:"name,omitempty"`
99111

100-
// Action specifies whether this rule must pass, allow or deny traffic.
112+
// Action specifies the affect this rule will have on matching traffic,
113+
// currently the following actions are supported:
101114
// Allow: allows the selected traffic
102115
// Deny: denies the selected traffic
103116
// This field is mandatory.
104117
Action BaselineAdminNetworkPolicyRuleAction `json:"action"`
105118

106-
// Ports allows for matching traffic based on port and protocols.
107-
// If Ports is empty or missing then traffic is not filtered via port.
119+
// Ports allows for matching traffic based on port and protocols.
120+
// If Ports is not set then traffic is not filtered via port.
108121
// +optional
109122
Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
110123

111-
// List of destinations to which traffic will be allowed/denied/passed from the entities
112-
// selected by this AdminNetworkPolicyRule. Items in this list are combined using a logical OR
113-
// operation. This field must be defined and contain at least one item.
124+
// List of destinations whose traffic this adminNetworkPolicyRule applies to.
125+
// If any adminNetworkPolicyPeer matches the destination of outgoing
126+
// traffic then the specified action is applied.
127+
// This field must be defined and contain at least one item.
114128
// +kubebuilder:validation:MinItems=1
115129
To []AdminNetworkPolicyPeer `json:"to"`
116130
}
@@ -122,10 +136,10 @@ type BaselineAdminNetworkPolicyRuleAction string
122136

123137
const (
124138

125-
// RuleActionDeny enables admins to deny specific traffic.
126-
BaselineAdminNetworkPolicyRuleActionDeny AdminNetworkPolicyRuleAction = "Deny"
127-
// RuleActionAllow enables admins to specifically allow certain traffic.
128-
BaselineAdminNetworkPolicyRuleActionAllow AdminNetworkPolicyRuleAction = "Allow"
139+
// BaselineAdminNetworkPolicyRuleActionDeny enables admins to deny specific traffic.
140+
BaselineAdminNetworkPolicyRuleActionDeny BaselineAdminNetworkPolicyRuleAction = "Deny"
141+
// BaselineAdminNetworkPolicyRuleActionAllow enables admins to specifically allow certain traffic.
142+
BaselineAdminNetworkPolicyRuleActionAllow BaselineAdminNetworkPolicyRuleAction = "Allow"
129143
)
130144

131145
//+kubebuilder:object:root=true

apis/v1alpha1/shared_types.go

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

23-
// AdminNetworkPolicyStatus defines the observed state of AdminNetworkPolicy.
24-
type AdminNetworkPolicyStatus struct {
25-
Conditions []metav1.Condition `json:"conditions"`
26-
}
27-
2823
// AdminNetworkPolicySubject defines what resources the policy applies to.
2924
// Exactly one field must be set.
3025
// +kubebuilder:validation:MaxProperties=1
@@ -41,11 +36,11 @@ type AdminNetworkPolicySubject struct {
4136
// NamespacedPodSubject allows the user to select a given set of pod(s) in
4237
// selected namespace(s).
4338
type NamespacedPodSubject struct {
44-
// This field follows standard label selector semantics; if empty,
39+
// NamespaceSelector follows standard label selector semantics; if empty,
4540
// it selects all Namespaces.
4641
NamespaceSelector metav1.LabelSelector `json:"namespaceSelector"`
4742

48-
// Used to explicitly select pods within a namespace; if empty,
43+
// PodSelector is used to explicitly select pods within a namespace; if empty,
4944
// it selects all Pods.
5045
PodSelector metav1.LabelSelector `json:"podSelector"`
5146
}
@@ -63,17 +58,17 @@ type AdminNetworkPolicyPort struct {
6358
// +optional
6459
Port *Port `json:"port,omitempty"`
6560

66-
// PortRange selects a portrange on a pod(s) based on provided start and end
61+
// PortRange selects a port range on a pod(s) based on provided start and end
6762
// values.
6863
// +optional
6964
PortRange *PortRange `json:"portRange,omitempty"`
7065
}
7166

7267
type Port struct {
73-
// The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, traffic
74-
// is not filtered by protocol.
75-
// +optional
76-
Protocol *v1.Protocol `json:"protocol,omitempty"`
68+
// The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified,
69+
// this field defaults to TCP.
70+
// +kubebuilder:default=TCP
71+
Protocol *v1.Protocol `json:"protocol"`
7772

7873
// Number defines a network port value.
7974
// +kubebuilder:validation:Minimum=1
@@ -84,20 +79,20 @@ type Port struct {
8479
// PortRange defines an inclusive range of ports from the the assigned Start value
8580
// to End value.
8681
type PortRange struct {
87-
// The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, traffic
88-
// is not filtered by protocol.
89-
// +optional
82+
// The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified,
83+
// this field defaults to TCP.
84+
// +kubebuilder:default=TCP
9085
Protocol *v1.Protocol `json:"protocol,omitempty"`
9186

92-
// Start defines a network port that is the start of a portrange, the Start
87+
// Start defines a network port that is the start of a port range, the Start
9388
// value must be less than End.
9489
// +kubebuilder:validation:Minimum=1
95-
// +kubebuilder:validation:Maximum=65534
90+
// +kubebuilder:validation:Maximum=65535
9691
Start int32 `json:"start"`
9792

98-
// End defines a network port that is the end of a portrange, the End value
93+
// End defines a network port that is the end of a port range, the End value
9994
// must be greater than Start.
100-
// +kubebuilder:validation:Minimum=2
95+
// +kubebuilder:validation:Minimum=1
10196
// +kubebuilder:validation:Maximum=65535
10297
End int32 `json:"end"`
10398
}
@@ -138,11 +133,11 @@ type NamespacedPeer struct {
138133
// +optional
139134
Related *NamespaceRelation `json:"related,omitempty"`
140135

141-
// Selector is a labelSelector used to select Namespaces, This field
136+
// NamespaceSelector is a labelSelector used to select Namespaces, This field
142137
// follows standard label selector semantics; if present but empty, it selects
143138
// all Namespaces.
144139
// +optional
145-
Selector *metav1.LabelSelector `json:"selector,omitempty"`
140+
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
146141

147142
// SameLabels is used to select a set of Namespaces that share the same values
148143
// for a set of labels.
@@ -161,24 +156,14 @@ type NamespacedPeer struct {
161156
NotSameLabels []string `json:"notSameLabels,omitempty"`
162157
}
163158

164-
// PodPeer defines a flexible way to select pods in a cluster. Exactly one of the
165-
// selectors must be set. If a consumer observes none of its fields are set,
166-
// they must assume an unknown option has been specified and fail closed.
167-
// +kubebuilder:validation:MaxProperties=1
168-
// +kubebuilder:validation:MinProperties=1
169-
type PodPeer struct {
170-
// PodSelector is a labelSelector used to select Pods, This field is NOT optional,
171-
// follows standard label selector semantics and if present but empty, it selects
172-
// all Pods.
173-
PodSelector *metav1.LabelSelector `json:"podSelector"`
174-
}
175-
176159
// NamespacedPodPeer defines a flexible way to select Namespaces and pods in a
177160
// cluster. The `Namespaces` and `PodSelector` fields are required.
178161
type NamespacedPodPeer struct {
179162
// Namespaces is used to select a set of Namespaces.
180163
Namespaces NamespacedPeer `json:"namespaces"`
181164

182-
// Pods is used to select a set of Pods in the set of Namespaces.
183-
Pods PodPeer `json:"pods"`
165+
// PodSelector is a labelSelector used to select Pods, This field is NOT optional,
166+
// follows standard label selector semantics and if present but empty, it selects
167+
// all Pods.
168+
PodSelector *metav1.LabelSelector `json:"podSelector"`
184169
}

0 commit comments

Comments
 (0)