Skip to content

Commit

Permalink
Merge pull request #594 from seswarrajan/dev
Browse files Browse the repository at this point in the history
Modify discover options to support the kind value
  • Loading branch information
nyrahul authored Nov 18, 2022
2 parents fbad090 + 6c35bc1 commit 06b601c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/networkpolicy/helperFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func GetNetPolicy(cluster, namespace, policyType string) *wpb.WorkerResponse {

var response wpb.WorkerResponse

if strings.Contains(policyType, "cilium") {
if strings.Contains(policyType, "CiliumNetworkPolicy") {
latestPolicies := libs.GetNetworkPolicies(CfgDB, cluster, namespace, "latest", "", "")
log.Info().Msgf("No. of latestPolicies - %d", len(latestPolicies))
ciliumPolicies := plugin.ConvertKnoxPoliciesToCiliumPolicies(latestPolicies)
Expand All @@ -797,7 +797,7 @@ func GetNetPolicy(cluster, namespace, policyType string) *wpb.WorkerResponse {
response.Ciliumpolicy = append(response.Ciliumpolicy, &ciliumpolicy)
}
response.K8SNetworkpolicy = nil
} else if strings.Contains(policyType, "generic") {
} else if strings.Contains(policyType, "NetworkPolicy") {
knoxNetPolicies := libs.GetNetworkPolicies(config.CurrentCfg.ConfigDB, cluster, namespace, "latest", "", "")
policies := plugin.ConvertKnoxNetPolicyToK8sNetworkPolicy(cluster, namespace, knoxNetPolicies)

Expand Down
1 change: 0 additions & 1 deletion src/plugin/k8sNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func ConvertKnoxNetPolicyToK8sNetworkPolicy(clustername, namespace string, knoxN
k8NetPol.Kind = types.K8sNwPolicyKind
k8NetPol.Name = knp.Metadata["name"]
k8NetPol.Namespace = knp.Metadata["namespace"]
k8NetPol.ClusterName = knp.Metadata["cluster_name"]
k8NetPol.Labels = knp.Spec.Selector.MatchLabels

if len(knp.Spec.Egress) > 0 {
Expand Down
6 changes: 3 additions & 3 deletions src/server/grpcServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ func (s *workerServer) GetWorkerStatus(ctx context.Context, in *wpb.WorkerReques

func (s *workerServer) Convert(ctx context.Context, in *wpb.WorkerRequest) (*wpb.WorkerResponse, error) {

if strings.Contains(in.GetPolicytype(), "network") {
if strings.Contains(in.GetPolicytype(), "CiliumNetworkPolicy") || strings.Contains(in.GetPolicytype(), "NetworkPolicy") {
log.Info().Msg("Convert network policy called")
network.InitNetPolicyDiscoveryConfiguration()
network.WriteNetworkPoliciesToFile(in.GetClustername(), in.GetNamespace())
return network.GetNetPolicy(in.Clustername, in.Namespace, in.GetPolicytype()), nil
} else if in.GetPolicytype() == "system" {
} else if in.GetPolicytype() == "KubearmorSecurityPolicy" {
log.Info().Msg("Convert system policy called")
system.InitSysPolicyDiscoveryConfiguration()
system.WriteSystemPoliciesToFile(in.GetNamespace(), in.GetClustername(), in.GetLabels(), in.GetFromsource(), in.GetIncludenetwork())
return system.GetSysPolicy(in.Namespace, in.Clustername, in.Labels, in.Fromsource, in.Includenetwork), nil
} else {
log.Info().Msg("Convert policy called, but no policy type")
log.Error().Msgf("unsupported policy type - %s", in.GetPolicytype())
}

return &wpb.WorkerResponse{Res: "ok"}, nil
Expand Down

0 comments on commit 06b601c

Please sign in to comment.