Skip to content

Commit

Permalink
remove hard-coded value for ignoring namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Ankur Kothiwal <ankur.kothiwal99@gmail.com>
  • Loading branch information
Ankurk99 committed Jul 4, 2023
1 parent 66b2e06 commit 8a15eaf
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/cluster/k8sClientHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sort"
"strings"

"github.com/accuknox/auto-policy-discovery/src/config"
"github.com/accuknox/auto-policy-discovery/src/libs"
"github.com/accuknox/auto-policy-discovery/src/types"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -346,6 +347,7 @@ func GetClusterNameFromK8sClient() string {

func GetDeploymentsFromK8sClient() []types.Deployment {
results := []types.Deployment{}
nsNotFilter := config.CurrentCfg.ConfigSysPolicy.NsNotFilter

client := ConnectK8sClient()
if client == nil {
Expand All @@ -361,8 +363,10 @@ func GetDeploymentsFromK8sClient() []types.Deployment {
}

for _, d := range deployments.Items {
if d.Namespace == "kube-system" {
continue
for _, notns := range nsNotFilter {
if strings.Contains(d.Namespace, notns) {
continue
}
}

if d.Spec.Selector.MatchLabels != nil {
Expand Down Expand Up @@ -392,6 +396,7 @@ func GetDeploymentsFromK8sClient() []types.Deployment {

func GetReplicaSetsFromK8sClient() []types.Deployment {
results := []types.Deployment{}
nsNotFilter := config.CurrentCfg.ConfigSysPolicy.NsNotFilter

client := ConnectK8sClient()
if client == nil {
Expand All @@ -408,8 +413,10 @@ func GetReplicaSetsFromK8sClient() []types.Deployment {

for _, rs := range replicasets.Items {
if rs.OwnerReferences == nil {
if rs.Namespace == "kube-system" {
continue
for _, notns := range nsNotFilter {
if strings.Contains(rs.Namespace, notns) {
continue
}
}

if rs.Spec.Selector.MatchLabels != nil {
Expand All @@ -436,6 +443,7 @@ func GetReplicaSetsFromK8sClient() []types.Deployment {

func GetDaemonSetsFromK8sClient() []types.Deployment {
results := []types.Deployment{}
nsNotFilter := config.CurrentCfg.ConfigSysPolicy.NsNotFilter

client := ConnectK8sClient()
if client == nil {
Expand All @@ -452,8 +460,10 @@ func GetDaemonSetsFromK8sClient() []types.Deployment {

for _, ds := range daemonsets.Items {
if ds.OwnerReferences == nil {
if ds.Namespace == "kube-system" {
continue
for _, notns := range nsNotFilter {
if strings.Contains(ds.Namespace, notns) {
continue
}
}

if ds.Spec.Selector.MatchLabels != nil {
Expand All @@ -480,6 +490,7 @@ func GetDaemonSetsFromK8sClient() []types.Deployment {

func GetStatefulSetsFromK8sClient() []types.Deployment {
results := []types.Deployment{}
nsNotFilter := config.CurrentCfg.ConfigSysPolicy.NsNotFilter

client := ConnectK8sClient()
if client == nil {
Expand All @@ -496,8 +507,10 @@ func GetStatefulSetsFromK8sClient() []types.Deployment {

for _, sts := range statefulset.Items {
if sts.OwnerReferences == nil {
if sts.Namespace == "kube-system" {
continue
for _, notns := range nsNotFilter {
if strings.Contains(sts.Namespace, notns) {
continue
}
}

if sts.Spec.Selector.MatchLabels != nil {
Expand Down

0 comments on commit 8a15eaf

Please sign in to comment.