Changed sync tappers to start only when sync tappers config is true (#562)

This commit is contained in:
RoyUP9 2021-12-27 17:19:00 +02:00 committed by GitHub
parent 2da7c0f0ed
commit 15895d5947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 18 deletions

View File

@ -131,6 +131,10 @@ func main() {
}
}
if config.Config.SyncTappers {
startSyncingTappers()
}
hostApi(outputItemsChannel)
} else if *harsReaderMode {
outputItemsChannel := make(chan *tapApi.OutputChannelItem, 1000)
@ -260,20 +264,6 @@ func hostApi(socketHarOutputChannel chan<- *tapApi.OutputChannelItem) {
routes.StatusRoutes(app)
routes.NotFoundRoute(app)
if config.Config.DaemonMode {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
kubernetesProvider, err := kubernetes.NewProviderInCluster()
if err != nil {
logger.Log.Fatalf("error creating k8s provider: %+v", err)
}
if _, err := startMizuTapperSyncer(ctx, kubernetesProvider); err != nil {
logger.Log.Fatalf("error initializing tapper syncer: %+v", err)
}
}
utils.StartServer(app)
}
@ -461,6 +451,20 @@ func handleIncomingMessageAsTapper(socketConnection *websocket.Conn) {
}
}
func startSyncingTappers() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
kubernetesProvider, err := kubernetes.NewProviderInCluster()
if err != nil {
logger.Log.Fatalf("error creating k8s provider: %+v", err)
}
if _, err := startMizuTapperSyncer(ctx, kubernetesProvider); err != nil {
logger.Log.Fatalf("error initializing tapper syncer: %+v", err)
}
}
func startMizuTapperSyncer(ctx context.Context, provider *kubernetes.Provider) (*kubernetes.MizuTapperSyncer, error) {
tapperSyncer, err := kubernetes.CreateAndStartMizuTapperSyncer(ctx, provider, kubernetes.TapperSyncerConfig{
TargetNamespaces: config.Config.TargetNamespaces,

View File

@ -56,6 +56,6 @@ func getDefaultConfig() (*shared.MizuAgentConfig, error) {
TapTargetRegex: *regex,
MaxDBSizeBytes: defaultMaxDatabaseSizeBytes,
AgentDatabasePath: DefaultDatabasePath,
DaemonMode: false,
SyncTappers: false,
}, nil
}

View File

@ -17,7 +17,7 @@ import (
)
func HealthCheck(c *gin.Context) {
if config.Config.DaemonMode {
if config.Config.SyncTappers {
if providers.ExpectedTapperAmount != providers.TappersCount {
c.JSON(http.StatusInternalServerError, fmt.Sprintf("expecting more tappers than are actually connected (%d expected, %d connected)", providers.ExpectedTapperAmount, providers.TappersCount))
return

View File

@ -392,7 +392,6 @@ func getMizuAgentConfig(targetNamespaces []string, mizuApiFilteringOptions *api.
config := shared.MizuAgentConfig{
TapTargetRegex: *serializableRegex,
MaxDBSizeBytes: Config.Tap.MaxEntriesDBSizeBytes(),
DaemonMode: Config.Tap.DaemonMode,
TargetNamespaces: targetNamespaces,
AgentImage: Config.AgentImage,
PullPolicy: Config.ImagePullPolicyStr,
@ -403,6 +402,7 @@ func getMizuAgentConfig(targetNamespaces []string, mizuApiFilteringOptions *api.
MizuApiFilteringOptions: *mizuApiFilteringOptions,
AgentDatabasePath: shared.DataDirPath,
Istio: Config.Tap.Istio,
SyncTappers: Config.Tap.DaemonMode,
}
return &config, nil
}

View File

@ -36,7 +36,6 @@ type Resources struct {
type MizuAgentConfig struct {
TapTargetRegex api.SerializableRegexp `json:"tapTargetRegex"`
MaxDBSizeBytes int64 `json:"maxDBSizeBytes"`
DaemonMode bool `json:"daemonMode"`
TargetNamespaces []string `json:"targetNamespaces"`
AgentImage string `json:"agentImage"`
PullPolicy string `json:"pullPolicy"`
@ -47,6 +46,7 @@ type MizuAgentConfig struct {
MizuApiFilteringOptions api.TrafficFilteringOptions `json:"mizuApiFilteringOptions"`
AgentDatabasePath string `json:"agentDatabasePath"`
Istio bool `json:"istio"`
SyncTappers bool `json:"syncTappers"`
}
type WebSocketMessageMetadata struct {