npc: Add defaultAllowIPSetName helper
This commit is contained in:
1 parent
79727a86fa
commit
f27d4d2117
1 file changed
+11
-14
+11
-14
@@ -118,10 +118,7 @@ func (ns *ns) onNewDstPodSelector(selector *selector, policyType policyType) err
|
|||||||
for _, pod := range ns.pods {
|
for _, pod := range ns.pods {
|
||||||
if hasIP(pod) {
|
if hasIP(pod) {
|
||||||
// Remove the pod from default-allow if dst podselector matches the pod
|
// Remove the pod from default-allow if dst podselector matches the pod
|
||||||
ipset := ns.ingressDefaultAllowIPSet
|
ipset := ns.defaultAllowIPSetName(policyType)
|
||||||
if policyType == egressPolicy {
|
|
||||||
ipset = ns.egressDefaultAllowIPSet
|
|
||||||
}
|
|
||||||
if selector.matches(pod.ObjectMeta.Labels) {
|
if selector.matches(pod.ObjectMeta.Labels) {
|
||||||
if err := ns.ips.DelEntry(pod.ObjectMeta.UID, ipset, pod.Status.PodIP); err != nil {
|
if err := ns.ips.DelEntry(pod.ObjectMeta.UID, ipset, pod.Status.PodIP); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -162,10 +159,7 @@ func (ns *ns) addToDefaultAllowIfNoMatching(pod *coreapi.Pod, policyType policyT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
ipset := ns.ingressDefaultAllowIPSet
|
ipset := ns.defaultAllowIPSetName(policyType)
|
||||||
if policyType == egressPolicy {
|
|
||||||
ipset = ns.egressDefaultAllowIPSet
|
|
||||||
}
|
|
||||||
if err := ns.ips.AddEntry(pod.ObjectMeta.UID, ipset, pod.Status.PodIP, podComment(pod)); err != nil {
|
if err := ns.ips.AddEntry(pod.ObjectMeta.UID, ipset, pod.Status.PodIP, podComment(pod)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -306,11 +300,7 @@ func (ns *ns) updatePod(oldObj, newObj *coreapi.Pod) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ns *ns) addOrRemoveToDefaultAllowIPSet(ps *selector, oldObj, newObj *coreapi.Pod, oldMatch, newMatch bool, policyType policyType) error {
|
func (ns *ns) addOrRemoveToDefaultAllowIPSet(ps *selector, oldObj, newObj *coreapi.Pod, oldMatch, newMatch bool, policyType policyType) error {
|
||||||
ipset := ns.ingressDefaultAllowIPSet
|
ipset := ns.defaultAllowIPSetName(policyType)
|
||||||
if policyType == egressPolicy {
|
|
||||||
ipset = ns.egressDefaultAllowIPSet
|
|
||||||
}
|
|
||||||
|
|
||||||
if ns.podSelectors.dstSelectorExist(ps, policyType) {
|
if ns.podSelectors.dstSelectorExist(ps, policyType) {
|
||||||
switch {
|
switch {
|
||||||
case !oldMatch && newMatch:
|
case !oldMatch && newMatch:
|
||||||
@@ -323,7 +313,6 @@ func (ns *ns) addOrRemoveToDefaultAllowIPSet(ps *selector, oldObj, newObj *corea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,6 +590,14 @@ func podComment(pod *coreapi.Pod) string {
|
|||||||
return fmt.Sprintf("namespace: %s, pod: %s", pod.ObjectMeta.Namespace, pod.ObjectMeta.Name)
|
return fmt.Sprintf("namespace: %s, pod: %s", pod.ObjectMeta.Namespace, pod.ObjectMeta.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ns *ns) defaultAllowIPSetName(pt policyType) ipset.Name {
|
||||||
|
ipset := ns.ingressDefaultAllowIPSet
|
||||||
|
if pt == egressPolicy {
|
||||||
|
ipset = ns.egressDefaultAllowIPSet
|
||||||
|
}
|
||||||
|
return ipset
|
||||||
|
}
|
||||||
|
|
||||||
func (ns *ns) analyse(obj interface{}) (
|
func (ns *ns) analyse(obj interface{}) (
|
||||||
uid types.UID,
|
uid types.UID,
|
||||||
rules map[string]*ruleSpec,
|
rules map[string]*ruleSpec,
|
||||||
|
|||||||
Reference in new issue
Block a user