Skip to content

Commit

Permalink
fix(core): Fix two panics
Browse files Browse the repository at this point in the history
Signed-off-by: Anurag Rajawat <[email protected]>
  • Loading branch information
anurag-rajawat committed Apr 17, 2024
1 parent d3075c2 commit 2dec16a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions sentryflow/core/k8sHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
"sync"
"time"

"github.com/5GSEC/SentryFlow/config"
"github.com/5GSEC/SentryFlow/types"
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"

"github.com/5GSEC/SentryFlow/config"
"github.com/5GSEC/SentryFlow/types"
)

// K8s global reference for Kubernetes Handler
Expand Down Expand Up @@ -101,6 +102,7 @@ func (kh *K8sHandler) initExistingResources() {
podList, err := kh.clientSet.CoreV1().Pods(corev1.NamespaceAll).List(context.TODO(), v1.ListOptions{})
if err != nil {
log.Print("Error listing Pods:", err.Error())
return
}

// Add existing Pods to the podMap
Expand All @@ -114,6 +116,7 @@ func (kh *K8sHandler) initExistingResources() {
serviceList, err := kh.clientSet.CoreV1().Services(corev1.NamespaceAll).List(context.TODO(), v1.ListOptions{})
if err != nil {
log.Print("Error listing Services:", err.Error())
return
}

// Add existing Services to the svcMap
Expand Down Expand Up @@ -414,7 +417,7 @@ func (kh *K8sHandler) PatchIstioConfigMap() error {

// Append eps to the existing slice
if !duplicate {
meshConfig["extensionProviders"] = append(ep.([]map[interface{}]interface{}), eps)
meshConfig["extensionProviders"] = append(ep.([]interface{}), eps)
}
}

Expand Down
1 change: 1 addition & 0 deletions sentryflow/core/sentryflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func SentryFlow() {

if !exporter.AH.InitAIHandler() {
log.Printf("[Error] Failed to initialize AI Engine")
return
}
log.Printf("[SentryFlow] Successfuly initialized AI Engine")

Expand Down
7 changes: 6 additions & 1 deletion sentryflow/exporter/aiHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"io"
"log"

"google.golang.org/grpc"

cfg "github.com/5GSEC/SentryFlow/config"
"github.com/5GSEC/SentryFlow/protobuf"
"github.com/5GSEC/SentryFlow/types"
"google.golang.org/grpc"
)

// AH Local reference for AI handler server
Expand Down Expand Up @@ -74,6 +75,10 @@ func (ah *aiHandler) InitAIHandler() bool {
client := protobuf.NewSentryFlowMetricsClient(conn)

aiStream, err := client.GetAPIClassification(context.Background())
if err != nil {
log.Printf("[gRPC] Error getting API classification: %v", err)
return false
}

AH.aiStream = &streamInform{
aiStream: aiStream,
Expand Down

0 comments on commit 2dec16a

Please sign in to comment.