Skip to content

Commit

Permalink
fix: report failure if network policy doesn't match any pods
Browse files Browse the repository at this point in the history
Before, there was no failure reported by the netpol analyzer, if the
matcher on the policy doesn't match any pods.

Signed-off-by: Patrick Pichler <git@patrickpichler.dev>
  • Loading branch information
Patrick Pichler authored and patrickpichler committed Apr 25, 2023
1 parent d4dcc7a commit 8adde6b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions pkg/analyzer/netpol.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ func (NetworkPolicyAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error)
},
},
})
continue
}
// Check if policy is not applied to any pods
podList, err := util.GetPodListByLabels(a.Client.GetClient(), a.Namespace, policy.Spec.PodSelector.MatchLabels)
if err != nil {
return nil, err
}
if len(podList.Items) == 0 {
failures = append(failures, common.Failure{
Text: fmt.Sprintf("Network policy is not applied to any pods: %s", policy.Name),
Sensitive: []common.Sensitive{
{
Unmasked: policy.Name,
Masked: util.MaskString(policy.Name),
} else {
// Check if policy is not applied to any pods
podList, err := util.GetPodListByLabels(a.Client.GetClient(), a.Namespace, policy.Spec.PodSelector.MatchLabels)
if err != nil {
return nil, err
}
if len(podList.Items) == 0 {
failures = append(failures, common.Failure{
Text: fmt.Sprintf("Network policy is not applied to any pods: %s", policy.Name),
Sensitive: []common.Sensitive{
{
Unmasked: policy.Name,
Masked: util.MaskString(policy.Name),
},
},
},
})
})
}
}

if len(failures) > 0 {
Expand Down

0 comments on commit 8adde6b

Please sign in to comment.