diff --git a/relay-server/go.mod b/relay-server/go.mod index 521484f..4a3e55e 100644 --- a/relay-server/go.mod +++ b/relay-server/go.mod @@ -20,7 +20,6 @@ require ( github.com/kubearmor/KubeArmor/protobuf v0.0.0-20240315075053-fee50c9428b9 github.com/spf13/viper v1.18.2 go.uber.org/zap v1.27.0 - golang.org/x/sync v0.7.0 google.golang.org/grpc v1.63.2 k8s.io/api v0.30.1 k8s.io/apimachinery v0.30.1 diff --git a/relay-server/go.sum b/relay-server/go.sum index 8dfea1e..9d08f06 100644 --- a/relay-server/go.sum +++ b/relay-server/go.sum @@ -134,8 +134,6 @@ golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/relay-server/informers/informercache.go b/relay-server/informers/informercache.go index 0181d7f..60825dc 100644 --- a/relay-server/informers/informercache.go +++ b/relay-server/informers/informercache.go @@ -92,8 +92,12 @@ func StartInformers(client *Client) { podInformer.AddEventHandler( cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { + pod, ok := obj.(*v1.Pod) + if !ok { + kg.Errf("Failed to cast object to *v1.Pod in AddFunc: received type %T", obj) + return + } - pod := obj.(*v1.Pod) deploymentName := getDeploymentNamefromPod(pod) podInfo := PodServiceInfo{ Type: "POD", @@ -103,29 +107,30 @@ func StartInformers(client *Client) { } client.ClusterIPCache.Set(pod.Status.PodIP, podInfo) - - // kg.Printf("POD Added: %s/%s, remoteIP %s\n", pod.Name, deploymentName, pod.Status.PodIP) }, UpdateFunc: func(oldObj, newObj interface{}) { + pod, ok := newObj.(*v1.Pod) + if !ok { + kg.Errf("Failed to cast object to *v1.Pod in UpdateFunc: received type %T", newObj) + return + } - pod := newObj.(*v1.Pod) deploymentName := getDeploymentNamefromPod(pod) podInfo := PodServiceInfo{ - Type: "POD", PodName: pod.Name, DeploymentName: deploymentName, - - NamespaceName: pod.Namespace, + NamespaceName: pod.Namespace, } client.ClusterIPCache.Set(pod.Status.PodIP, podInfo) - // kg.Printf("POD Updated: %s/%s, remoteIP %s\n", pod.Name, deploymentName, pod.Status.PodIP) - }, DeleteFunc: func(obj interface{}) { - - pod := obj.(*v1.Pod) + pod, ok := obj.(*v1.Pod) + if !ok { + kg.Errf("Failed to cast object to *v1.Pod in DeleteFunc: received type %T", obj) + return + } client.ClusterIPCache.Delete(pod.Status.PodIP) }, @@ -139,7 +144,11 @@ func StartInformers(client *Client) { serviceInformer.AddEventHandler( cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - service := obj.(*v1.Service) + service, ok := obj.(*v1.Service) + if !ok { + kg.Errf("Failed to cast object to *v1.Service in AddFunc: received type %T", obj) + return + } svcInfo := PodServiceInfo{ @@ -154,8 +163,11 @@ func StartInformers(client *Client) { // kg.Printf("Service Added: %s/%s, remoteIP %s\n", service.Namespace, service.Name, service.Spec.ClusterIP) }, UpdateFunc: func(oldObj, newObj interface{}) { - service := newObj.(*v1.Service) - + service, ok := newObj.(*v1.Service) + if !ok { + kg.Errf("Failed to cast object to *v1.Service in UpdateFunc: received type %T", newObj) + return + } svcInfo := PodServiceInfo{ Type: "SERVICE", @@ -164,10 +176,14 @@ func StartInformers(client *Client) { NamespaceName: service.Namespace, } client.ClusterIPCache.Set(service.Spec.ClusterIP, svcInfo) - kg.Printf("Service Updated: %s/%s\n", service.Namespace, service.Name) + // kg.Printf("Service Updated: %s/%s\n", service.Namespace, service.Name) }, DeleteFunc: func(obj interface{}) { - service := obj.(*v1.Service) + service, ok := obj.(*v1.Service) + if !ok { + kg.Errf("Failed to cast object to *v1.Service in DeleteFunc: received type %T", obj) + return + } client.ClusterIPCache.Delete(service.Spec.ClusterIP) // kg.Printf("Service Deleted: %s/%s\n", service.Namespace, service.Name) diff --git a/relay-server/server/relayServer.go b/relay-server/server/relayServer.go index cc8227a..fecd140 100644 --- a/relay-server/server/relayServer.go +++ b/relay-server/server/relayServer.go @@ -681,7 +681,7 @@ func NewRelayServer(port string) *RelayServer { if enableEsDashboards { ESLogChannel = make(chan *pb.Log, 10000) - AlertBufferChannel = make(chan *pb.Alert, 1000) + ESAlertChannel = make(chan *pb.Alert, 1000) } // listen to gRPC port