Skip to content

Commit ef14c8d

Browse files
authored
Fix a bug that created a random egress entry when deleting from ingress-centric policy group. Also added a check to add multiple default entries to prevent deletion of once policy to affect another. (#551)
1 parent 6ac5e8c commit ef14c8d

File tree

3 files changed

+5
-18
lines changed

3 files changed

+5
-18
lines changed

npm/iptm/iptm.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,6 @@ func (iptMgr *IptablesManager) DeleteChain(chain string) error {
283283
func (iptMgr *IptablesManager) Add(entry *IptEntry) error {
284284
log.Printf("Adding iptables entry: %+v.", entry)
285285

286-
exists, err := iptMgr.Exists(entry)
287-
if err != nil {
288-
return err
289-
}
290-
291-
if exists {
292-
return nil
293-
}
294-
295286
if entry.IsJumpEntry {
296287
iptMgr.OperationFlag = util.IptablesAppendFlag
297288
} else {

npm/nwpolicy.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,14 @@ func (npMgr *NetworkPolicyManager) AddNetworkPolicy(npObj *networkingv1.NetworkP
8585
}
8686

8787
if addedPolicy != nil {
88-
sets, lists, iptEntries = translatePolicy(addedPolicy)
8988
ns.processedNpMap[hashedSelector] = addedPolicy
9089
} else {
91-
sets, lists, iptEntries = translatePolicy(npObj)
9290
ns.processedNpMap[hashedSelector] = npObj
9391
}
9492

9593
ns.rawNpMap[npObj.ObjectMeta.Name] = npObj
9694

95+
sets, lists, iptEntries = translatePolicy(npObj)
9796
ipsMgr := allNs.ipsMgr
9897
for _, set := range sets {
9998
log.Printf("Creating set: %v, hashedSet: %v", set, util.GetHashedName(set))

npm/parsePolicy.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ func addPolicy(old, new *networkingv1.NetworkPolicy) (*networkingv1.NetworkPolic
5454
}
5555

5656
spec := &(addedPolicy.Spec)
57-
if len(old.Spec.PolicyTypes) == 1 && old.Spec.PolicyTypes[0] == networkingv1.PolicyTypeEgress &&
58-
len(new.Spec.PolicyTypes) == 1 && new.Spec.PolicyTypes[0] == networkingv1.PolicyTypeEgress {
59-
spec.PolicyTypes = []networkingv1.PolicyType{networkingv1.PolicyTypeEgress}
57+
if len(old.Spec.PolicyTypes) == 1 && len(new.Spec.PolicyTypes) == 1 && old.Spec.PolicyTypes[0] == new.Spec.PolicyTypes[0] {
58+
spec.PolicyTypes = []networkingv1.PolicyType{new.Spec.PolicyTypes[0]}
6059
} else {
6160
spec.PolicyTypes = []networkingv1.PolicyType{
6261
networkingv1.PolicyTypeIngress,
@@ -126,10 +125,8 @@ func deductPolicy(old, new *networkingv1.NetworkPolicy) (*networkingv1.NetworkPo
126125
deductedPolicy.Spec.Ingress = deductedIngress
127126
deductedPolicy.Spec.Egress = deductedEgress
128127

129-
if len(old.Spec.PolicyTypes) == 1 && old.Spec.PolicyTypes[0] == networkingv1.PolicyTypeEgress &&
130-
len(new.Spec.PolicyTypes) == 1 && new.Spec.PolicyTypes[0] == networkingv1.PolicyTypeEgress &&
131-
len(deductedIngress) == 0 {
132-
deductedPolicy.Spec.PolicyTypes = []networkingv1.PolicyType{networkingv1.PolicyTypeEgress}
128+
if len(old.Spec.PolicyTypes) == 1 && len(new.Spec.PolicyTypes) == 1 && old.Spec.PolicyTypes[0] == new.Spec.PolicyTypes[0] {
129+
deductedPolicy.Spec.PolicyTypes = []networkingv1.PolicyType{new.Spec.PolicyTypes[0]}
133130
} else {
134131
deductedPolicy.Spec.PolicyTypes = []networkingv1.PolicyType{
135132
networkingv1.PolicyTypeIngress,

0 commit comments

Comments
 (0)