mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-05-06 01:07:13 +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.
103 lines
2.7 KiB
Go
103 lines
2.7 KiB
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
core "k8s.io/api/core/v1"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/up9inc/mizu/agent/pkg/api"
|
|
"github.com/up9inc/mizu/agent/pkg/holder"
|
|
"github.com/up9inc/mizu/agent/pkg/providers"
|
|
"github.com/up9inc/mizu/agent/pkg/providers/tappedPods"
|
|
"github.com/up9inc/mizu/agent/pkg/providers/tappers"
|
|
"github.com/up9inc/mizu/agent/pkg/up9"
|
|
"github.com/up9inc/mizu/agent/pkg/validation"
|
|
"github.com/up9inc/mizu/shared"
|
|
"github.com/up9inc/mizu/shared/kubernetes"
|
|
"github.com/up9inc/mizu/shared/logger"
|
|
)
|
|
|
|
func HealthCheck(c *gin.Context) {
|
|
tappersStatus := make([]*shared.TapperStatus, 0)
|
|
for _, value := range tappers.GetStatus() {
|
|
tappersStatus = append(tappersStatus, value)
|
|
}
|
|
|
|
response := shared.HealthResponse{
|
|
TappedPods: tappedPods.Get(),
|
|
ConnectedTappersCount: tappers.GetConnectedCount(),
|
|
TappersStatus: tappersStatus,
|
|
}
|
|
c.JSON(http.StatusOK, response)
|
|
}
|
|
|
|
func PostTappedPods(c *gin.Context) {
|
|
var requestTappedPods []core.Pod
|
|
if err := c.Bind(&requestTappedPods); err != nil {
|
|
c.JSON(http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
|
|
podInfos := kubernetes.GetPodInfosForPods(requestTappedPods)
|
|
|
|
logger.Log.Infof("[Status] POST request: %d tapped pods", len(requestTappedPods))
|
|
tappedPods.Set(podInfos)
|
|
api.BroadcastTappedPodsStatus()
|
|
|
|
nodeToTappedPodMap := kubernetes.GetNodeHostToTappedPodsMap(requestTappedPods)
|
|
tappedPods.SetNodeToTappedPodMap(nodeToTappedPodMap)
|
|
api.BroadcastTappedPodsToTappers(nodeToTappedPodMap)
|
|
}
|
|
|
|
func PostTapperStatus(c *gin.Context) {
|
|
tapperStatus := &shared.TapperStatus{}
|
|
if err := c.Bind(tapperStatus); err != nil {
|
|
c.JSON(http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
|
|
if err := validation.Validate(tapperStatus); err != nil {
|
|
c.JSON(http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
|
|
logger.Log.Infof("[Status] POST request, tapper status: %v", tapperStatus)
|
|
tappers.SetStatus(tapperStatus)
|
|
api.BroadcastTappedPodsStatus()
|
|
}
|
|
|
|
func GetConnectedTappersCount(c *gin.Context) {
|
|
c.JSON(http.StatusOK, tappers.GetConnectedCount())
|
|
}
|
|
|
|
func GetAuthStatus(c *gin.Context) {
|
|
authStatus, err := providers.GetAuthStatus()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, authStatus)
|
|
}
|
|
|
|
func GetTappingStatus(c *gin.Context) {
|
|
tappedPodsStatus := tappedPods.GetTappedPodsStatus()
|
|
c.JSON(http.StatusOK, tappedPodsStatus)
|
|
}
|
|
|
|
func AnalyzeInformation(c *gin.Context) {
|
|
c.JSON(http.StatusOK, up9.GetAnalyzeInfo())
|
|
}
|
|
|
|
func GetGeneralStats(c *gin.Context) {
|
|
c.JSON(http.StatusOK, providers.GetGeneralStats())
|
|
}
|
|
|
|
func GetRecentTLSLinks(c *gin.Context) {
|
|
c.JSON(http.StatusOK, providers.GetAllRecentTLSAddresses())
|
|
}
|
|
|
|
func GetCurrentResolvingInformation(c *gin.Context) {
|
|
c.JSON(http.StatusOK, holder.GetResolver().GetMap())
|
|
}
|