@@ -97,13 +97,14 @@ func (r *defaultPolicyReferenceResolver) getReferredPoliciesForPod(ctx context.C
97
97
}
98
98
isPolicyReferred := false
99
99
isAdminPolicyReferred := false
100
- if r .isPodReferredOnIngressEgress (ctx , pod , policy , nil , false ) {
100
+ if isPolicyFound && r .isPodReferredOnIngressEgress (ctx , pod , policy , nil , false ) {
101
101
referredPolicies = append (referredPolicies , * policy )
102
102
processedPolicies .Insert (k8s .NamespacedName (policy ))
103
103
isPolicyReferred = true
104
104
// continue
105
105
}
106
- if r .isPodReferredOnIngressEgress (ctx , pod , nil , adminPolicy , true ) {
106
+
107
+ if isAdminPolicyFound && r .isPodReferredOnIngressEgress (ctx , pod , nil , adminPolicy , true ) {
107
108
referredAdminPolicies = append (referredAdminPolicies , * adminPolicy )
108
109
processedPolicies .Insert (k8s .NamespacedName (adminPolicy ))
109
110
isAdminPolicyReferred = false
@@ -112,21 +113,21 @@ func (r *defaultPolicyReferenceResolver) getReferredPoliciesForPod(ctx context.C
112
113
if isPolicyReferred && isAdminPolicyReferred {
113
114
continue
114
115
} else if isAdminPolicyReferred {
115
- if podOld != nil && r .isPodReferredOnIngressEgress (ctx , podOld , policy , nil , false ) {
116
+ if podOld != nil && isPolicyFound && r .isPodReferredOnIngressEgress (ctx , podOld , policy , nil , false ) {
116
117
referredPolicies = append (referredPolicies , * policy )
117
118
processedPolicies .Insert (k8s .NamespacedName (policy ))
118
119
}
119
120
} else if isPolicyReferred {
120
- if podOld != nil && r .isPodReferredOnIngressEgress (ctx , podOld , nil , adminPolicy , true ) {
121
+ if podOld != nil && isAdminPolicyFound && r .isPodReferredOnIngressEgress (ctx , podOld , nil , adminPolicy , true ) {
121
122
referredAdminPolicies = append (referredAdminPolicies , * adminPolicy )
122
123
processedPolicies .Insert (k8s .NamespacedName (adminPolicy ))
123
124
}
124
125
} else {
125
- if podOld != nil && r .isPodReferredOnIngressEgress (ctx , podOld , policy , nil , false ) {
126
+ if podOld != nil && isPolicyFound && r .isPodReferredOnIngressEgress (ctx , podOld , policy , nil , false ) {
126
127
referredPolicies = append (referredPolicies , * policy )
127
128
processedPolicies .Insert (k8s .NamespacedName (policy ))
128
129
}
129
- if podOld != nil && r .isPodReferredOnIngressEgress (ctx , podOld , nil , adminPolicy , true ) {
130
+ if podOld != nil && isAdminPolicyFound && r .isPodReferredOnIngressEgress (ctx , podOld , nil , adminPolicy , true ) {
130
131
referredAdminPolicies = append (referredAdminPolicies , * adminPolicy )
131
132
processedPolicies .Insert (k8s .NamespacedName (adminPolicy ))
132
133
}
@@ -169,9 +170,6 @@ func (r *defaultPolicyReferenceResolver) isPodMatchesPolicySelector(pod *corev1.
169
170
170
171
func (r * defaultPolicyReferenceResolver ) isPodReferredOnIngressEgress (ctx context.Context , pod * corev1.Pod , policy * networking.NetworkPolicy , adminPolicy * adminnetworking.AdminNetworkPolicy , isAdmin bool ) bool {
171
172
if isAdmin {
172
- if adminPolicy == nil {
173
- return false
174
- }
175
173
namepsaces , _ := r .podSelectorNamespaces (ctx , adminPolicy )
176
174
for _ , ns := range namepsaces {
177
175
for _ , ingRule := range adminPolicy .Spec .Ingress {
0 commit comments