Fixed standalone config, small refactor (#589)

This commit is contained in:
RoyUP9
2022-01-06 12:04:58 +02:00
committed by GitHub
parent 833d08bb40
commit b88bdb90f6
7 changed files with 33 additions and 19 deletions

View File

@@ -50,7 +50,9 @@ func PostTapConfig(c *gin.Context) {
c.JSON(http.StatusInternalServerError, err)
return
}
ctx, cancel := context.WithCancel(context.Background())
if _, err := startMizuTapperSyncer(ctx, kubernetesProvider, tappedNamespaces, *podRegex, []string{}, tapApi.TrafficFilteringOptions{}, false); err != nil {
c.JSON(http.StatusInternalServerError, err)
cancel()
@@ -69,25 +71,27 @@ func GetTapConfig(c *gin.Context) {
c.JSON(http.StatusInternalServerError, err)
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
namespaces, err := kubernetesProvider.ListAllNamespaces(ctx)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
tappedNamespaces := make(map[string]bool)
for _, namespace := range namespaces {
if namespace.Name == config.Config.MizuResourcesNamespace {
continue
}
if _, ok := globalTapConfig.TappedNamespaces[namespace.Name]; !ok {
globalTapConfig.TappedNamespaces[namespace.Name] = false
}
tappedNamespaces[namespace.Name] = globalTapConfig.TappedNamespaces[namespace.Name]
}
c.JSON(http.StatusOK, globalTapConfig)
tapConfig := models.TapConfig{TappedNamespaces: tappedNamespaces}
c.JSON(http.StatusOK, tapConfig)
}
func startMizuTapperSyncer(ctx context.Context, provider *kubernetes.Provider, targetNamespaces []string, podFilterRegex regexp.Regexp, ignoredUserAgents []string, mizuApiFilteringOptions tapApi.TrafficFilteringOptions, istio bool) (*kubernetes.MizuTapperSyncer, error) {