mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-23 06:48:47 +00:00
TRA-3903 minor daemon mode refactor (#479)
* Update common.go and tapRunner.go * Update common.go
This commit is contained in:
parent
b7f7daa05c
commit
18be46809e
@ -4,9 +4,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/up9inc/mizu/cli/apiserver"
|
||||||
|
"github.com/up9inc/mizu/cli/mizu"
|
||||||
|
"github.com/up9inc/mizu/cli/mizu/fsUtils"
|
||||||
|
"github.com/up9inc/mizu/cli/telemetry"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/up9inc/mizu/cli/config"
|
"github.com/up9inc/mizu/cli/config"
|
||||||
"github.com/up9inc/mizu/cli/config/configStructs"
|
"github.com/up9inc/mizu/cli/config/configStructs"
|
||||||
@ -64,3 +70,42 @@ func handleKubernetesProviderError(err error) {
|
|||||||
logger.Log.Error(err)
|
logger.Log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func finishMizuExecution(kubernetesProvider *kubernetes.Provider, apiProvider *apiserver.Provider) {
|
||||||
|
telemetry.ReportAPICalls(apiProvider)
|
||||||
|
removalCtx, cancel := context.WithTimeout(context.Background(), cleanupTimeout)
|
||||||
|
defer cancel()
|
||||||
|
dumpLogsIfNeeded(removalCtx, kubernetesProvider)
|
||||||
|
cleanUpMizuResources(removalCtx, cancel, kubernetesProvider)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpLogsIfNeeded(ctx context.Context, kubernetesProvider *kubernetes.Provider) {
|
||||||
|
if !config.Config.DumpLogs {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mizuDir := mizu.GetMizuFolderPath()
|
||||||
|
filePath := path.Join(mizuDir, fmt.Sprintf("mizu_logs_%s.zip", time.Now().Format("2006_01_02__15_04_05")))
|
||||||
|
if err := fsUtils.DumpLogs(ctx, kubernetesProvider, filePath); err != nil {
|
||||||
|
logger.Log.Errorf("Failed dump logs %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanUpMizuResources(ctx context.Context, cancel context.CancelFunc, kubernetesProvider *kubernetes.Provider) {
|
||||||
|
logger.Log.Infof("\nRemoving mizu resources")
|
||||||
|
|
||||||
|
var leftoverResources []string
|
||||||
|
|
||||||
|
if config.Config.IsNsRestrictedMode() {
|
||||||
|
leftoverResources = cleanUpRestrictedMode(ctx, kubernetesProvider)
|
||||||
|
} else {
|
||||||
|
leftoverResources = cleanUpNonRestrictedMode(ctx, cancel, kubernetesProvider)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(leftoverResources) > 0 {
|
||||||
|
errMsg := fmt.Sprintf("Failed to remove the following resources, for more info check logs at %s:", fsUtils.GetLogFilePath())
|
||||||
|
for _, resource := range leftoverResources {
|
||||||
|
errMsg += "\n- " + resource
|
||||||
|
}
|
||||||
|
logger.Log.Errorf(uiUtils.Error, errMsg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -25,7 +24,6 @@ import (
|
|||||||
|
|
||||||
"github.com/up9inc/mizu/cli/mizu"
|
"github.com/up9inc/mizu/cli/mizu"
|
||||||
"github.com/up9inc/mizu/cli/mizu/fsUtils"
|
"github.com/up9inc/mizu/cli/mizu/fsUtils"
|
||||||
"github.com/up9inc/mizu/cli/telemetry"
|
|
||||||
"github.com/up9inc/mizu/cli/uiUtils"
|
"github.com/up9inc/mizu/cli/uiUtils"
|
||||||
"github.com/up9inc/mizu/shared"
|
"github.com/up9inc/mizu/shared"
|
||||||
"github.com/up9inc/mizu/shared/kubernetes"
|
"github.com/up9inc/mizu/shared/kubernetes"
|
||||||
@ -185,7 +183,7 @@ func printTappedPodsPreview(ctx context.Context, kubernetesProvider *kubernetes.
|
|||||||
if len(matchingPods) == 0 {
|
if len(matchingPods) == 0 {
|
||||||
printNoPodsFoundSuggestion(namespaces)
|
printNoPodsFoundSuggestion(namespaces)
|
||||||
}
|
}
|
||||||
logger.Log.Info("Pods that match regex at this instant:")
|
logger.Log.Info("Pods that match the provided criteria at this instant:")
|
||||||
for _, tappedPod := range matchingPods {
|
for _, tappedPod := range matchingPods {
|
||||||
logger.Log.Infof(uiUtils.Green, fmt.Sprintf("+%s", tappedPod.Name))
|
logger.Log.Infof(uiUtils.Green, fmt.Sprintf("+%s", tappedPod.Name))
|
||||||
}
|
}
|
||||||
@ -447,45 +445,6 @@ func getSyncEntriesConfig() *shared.SyncEntriesConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func finishMizuExecution(kubernetesProvider *kubernetes.Provider, apiProvider *apiserver.Provider) {
|
|
||||||
telemetry.ReportAPICalls(apiProvider)
|
|
||||||
removalCtx, cancel := context.WithTimeout(context.Background(), cleanupTimeout)
|
|
||||||
defer cancel()
|
|
||||||
dumpLogsIfNeeded(removalCtx, kubernetesProvider)
|
|
||||||
cleanUpMizuResources(removalCtx, cancel, kubernetesProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
func dumpLogsIfNeeded(ctx context.Context, kubernetesProvider *kubernetes.Provider) {
|
|
||||||
if !config.Config.DumpLogs {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mizuDir := mizu.GetMizuFolderPath()
|
|
||||||
filePath := path.Join(mizuDir, fmt.Sprintf("mizu_logs_%s.zip", time.Now().Format("2006_01_02__15_04_05")))
|
|
||||||
if err := fsUtils.DumpLogs(ctx, kubernetesProvider, filePath); err != nil {
|
|
||||||
logger.Log.Errorf("Failed dump logs %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func cleanUpMizuResources(ctx context.Context, cancel context.CancelFunc, kubernetesProvider *kubernetes.Provider) {
|
|
||||||
logger.Log.Infof("\nRemoving mizu resources")
|
|
||||||
|
|
||||||
var leftoverResources []string
|
|
||||||
|
|
||||||
if config.Config.IsNsRestrictedMode() {
|
|
||||||
leftoverResources = cleanUpRestrictedMode(ctx, kubernetesProvider)
|
|
||||||
} else {
|
|
||||||
leftoverResources = cleanUpNonRestrictedMode(ctx, cancel, kubernetesProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(leftoverResources) > 0 {
|
|
||||||
errMsg := fmt.Sprintf("Failed to remove the following resources, for more info check logs at %s:", fsUtils.GetLogFilePath())
|
|
||||||
for _, resource := range leftoverResources {
|
|
||||||
errMsg += "\n- " + resource
|
|
||||||
}
|
|
||||||
logger.Log.Errorf(uiUtils.Error, errMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func cleanUpRestrictedMode(ctx context.Context, kubernetesProvider *kubernetes.Provider) []string {
|
func cleanUpRestrictedMode(ctx context.Context, kubernetesProvider *kubernetes.Provider) []string {
|
||||||
leftoverResources := make([]string, 0)
|
leftoverResources := make([]string, 0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user