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 Oct 5, 2023
1 parent 4aedbe7 commit b5551a4
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/cluster/k8sClientHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ 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"
"github.com/rs/zerolog/log"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -346,6 +348,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 +364,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 +397,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 +414,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 +444,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 +461,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 +491,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 +508,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 b5551a4

Please sign in to comment.