mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-05-05 16:57:48 +00:00
Update tappers via websocket instead of by env var. This way the DaemonSet doesn't have to be applied just to notify the tappers that the tap targets changed. The number of tapper restarts is reduced. The DaemonSet still gets applied when there is a need to add/remove a tapper from a node.
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/up9inc/mizu/agent/pkg/providers/tappedPods"
|
|
"github.com/up9inc/mizu/shared"
|
|
"github.com/up9inc/mizu/shared/logger"
|
|
)
|
|
|
|
func BroadcastTappedPodsStatus() {
|
|
tappedPodsStatus := tappedPods.GetTappedPodsStatus()
|
|
|
|
message := shared.CreateWebSocketStatusMessage(tappedPodsStatus)
|
|
if jsonBytes, err := json.Marshal(message); err != nil {
|
|
logger.Log.Errorf("Could not Marshal message %v", err)
|
|
} else {
|
|
BroadcastToBrowserClients(jsonBytes)
|
|
}
|
|
}
|
|
|
|
func SendTappedPods(socketId int, nodeToTappedPodMap shared.NodeToPodsMap) {
|
|
message := shared.CreateWebSocketTappedPodsMessage(nodeToTappedPodMap)
|
|
if jsonBytes, err := json.Marshal(message); err != nil {
|
|
logger.Log.Errorf("Could not Marshal message %v", err)
|
|
} else {
|
|
if err := SendToSocket(socketId, jsonBytes); err != nil {
|
|
logger.Log.Error(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BroadcastTappedPodsToTappers(nodeToTappedPodMap shared.NodeToPodsMap) {
|
|
message := shared.CreateWebSocketTappedPodsMessage(nodeToTappedPodMap)
|
|
if jsonBytes, err := json.Marshal(message); err != nil {
|
|
logger.Log.Errorf("Could not Marshal message %v", err)
|
|
} else {
|
|
BroadcastToTapperClients(jsonBytes)
|
|
}
|
|
}
|