From 39f897a148be49e788dedc8d12372d17f7a0c81c Mon Sep 17 00:00:00 2001 From: jackyalbo Date: Tue, 10 Dec 2024 12:10:12 +0200 Subject: [PATCH] adding network analyzer Signed-off-by: jackyalbo --- deploy/job_analyze_network.yml | 35 ++++++++++++++++++++++++++++++ pkg/bundle/deploy.go | 39 ++++++++++++++++++++++++++++++++++ pkg/diagnostics/analyze.go | 35 +++++++++++++++++++++++++++--- pkg/diagnostics/diagnostics.go | 15 ++++++++++++- 4 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 deploy/job_analyze_network.yml diff --git a/deploy/job_analyze_network.yml b/deploy/job_analyze_network.yml new file mode 100644 index 0000000000..8e96ba3532 --- /dev/null +++ b/deploy/job_analyze_network.yml @@ -0,0 +1,35 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: noobaa-analyze-network + labels: + app: noobaa +spec: + completions: 1 + parallelism: 1 + backoffLimit: 0 + activeDeadlineSeconds: 60 + ttlSecondsAfterFinished: 10 + template: + spec: + containers: + - name: noobaa-analyze-network + image: NOOBAA_CORE_IMAGE_PLACEHOLDER + env: + - name: CONTAINER_PLATFORM + value: KUBERNETES + # - name: RESOURCE_NAME + # - name: BUCKET + # - name: ENDPOINT + # - name: REGION + # - name: S3_SIGNATURE_VERSION + # - name: HTTP_PROXY + # - name: HTTPS_PROXY + # - name: NO_PROXY + # - name: NODE_EXTRA_CA_CERTS + command: + - /bin/bash + - -c + - "cd /root/node_modules/noobaa-core/; node ./src/tools/diagnostics/analyze_network.js" + restartPolicy: Never + serviceAccountName: noobaa diff --git a/pkg/bundle/deploy.go b/pkg/bundle/deploy.go index 1b95f6a199..bb73333769 100644 --- a/pkg/bundle/deploy.go +++ b/pkg/bundle/deploy.go @@ -5255,6 +5255,45 @@ const File_deploy_internal_text_system_status_readme_rejected_tmpl = ` NooBaa Operator Version: {{.OperatorVersion}} ` +const Sha256_deploy_job_analyze_network_yml = "d0a0b3d80571e7df633aaa8fffb91d77ddf39818eee1a0af03d8775b022b8a61" + +const File_deploy_job_analyze_network_yml = `apiVersion: batch/v1 +kind: Job +metadata: + name: noobaa-analyze-network + labels: + app: noobaa +spec: + completions: 1 + parallelism: 1 + backoffLimit: 0 + activeDeadlineSeconds: 60 + ttlSecondsAfterFinished: 10 + template: + spec: + containers: + - name: noobaa-analyze-network + image: NOOBAA_CORE_IMAGE_PLACEHOLDER + env: + - name: CONTAINER_PLATFORM + value: KUBERNETES + # - name: RESOURCE_NAME + # - name: BUCKET + # - name: ENDPOINT + # - name: REGION + # - name: S3_SIGNATURE_VERSION + # - name: HTTP_PROXY + # - name: HTTPS_PROXY + # - name: NO_PROXY + # - name: NODE_EXTRA_CA_CERTS + command: + - /bin/bash + - -c + - "cd /root/node_modules/noobaa-core/; node ./src/tools/diagnostics/analyze_network.js" + restartPolicy: Never + serviceAccountName: noobaa +` + const Sha256_deploy_job_analyze_resource_yml = "c80810baeda94fd9dd97a6c62241be5c582e08009bdbb1f2a13992c99d90ea33" const File_deploy_job_analyze_resource_yml = `apiVersion: batch/v1 diff --git a/pkg/diagnostics/analyze.go b/pkg/diagnostics/analyze.go index 232213ceb6..5c5437e594 100644 --- a/pkg/diagnostics/analyze.go +++ b/pkg/diagnostics/analyze.go @@ -172,16 +172,45 @@ func analyzeNamespaceStore(cmd *cobra.Command, namespaceStore *nbv1.NamespaceSto setJobAnalyzeResource(cmd, analyzeResourceJob, collector) } +// RunAnalyzeNetwork runs a CLI command +func RunAnalyzeNetwork(cmd *cobra.Command, args []string) { + log := util.Logger() + + log.Printf("⏳ Running this command will run the network diagnostic\n") + collector := collectorInstance(cmd) + makeDirForLogs(collector.folderName) + analyzeNetwork(cmd, collector) + destDir, _ := cmd.Flags().GetString("dir") + err := printTestsSummary(collector.folderName) + if err != nil { + log.Errorln("❌ Could not print tests summary") + } + collector.ExportDiagnostics(destDir) +} + +func analyzeNetwork(cmd *cobra.Command, collector *Collector) { + analyzeResourceJob := loadAnalyzeNetworkJob() + setImageInJob(analyzeResourceJob) + setJobAnalyzeResource(cmd, analyzeResourceJob, collector) +} + + func loadAnalyzeResourceJob() *batchv1.Job { analyzeResourceJob := util.KubeObject(bundle.File_deploy_job_analyze_resource_yml).(*batchv1.Job) analyzeResourceJob.Namespace = options.Namespace return analyzeResourceJob } +func loadAnalyzeNetworkJob() *batchv1.Job { + analyzeNetworkJob := util.KubeObject(bundle.File_deploy_job_analyze_network_yml).(*batchv1.Job) + analyzeNetworkJob.Namespace = options.Namespace + return analyzeNetworkJob +} + func collectorInstance(cmd *cobra.Command) *Collector { kubeconfig, _ := cmd.Flags().GetString("kubeconfig") collector := &Collector{ - folderName: fmt.Sprintf("%s_%d", "noobaa_analyze_resource", time.Now().Unix()), + folderName: fmt.Sprintf("%s_%d", "noobaa_analyze_result", time.Now().Unix()), log: util.Logger(), kubeconfig: kubeconfig, kubeCommand: util.GetAvailabeKubeCli(), @@ -479,8 +508,8 @@ func printTestsSummary(folderName string) error { scanner := bufio.NewScanner(file) shouldPrint := false // this is a printing that appears if it fails configuring or after the tests run (in the core repo) - prefixToSearchFailed := "Test Diagnose Resource Failed" - prefixToSearchSummary := "Analyze Resource Tests Result" + prefixToSearchFailed := "Test Diagnose Network Failed" + prefixToSearchSummary := "Analyze Network Tests Result" var indexToExtractLine int for scanner.Scan() { line := scanner.Text() diff --git a/pkg/diagnostics/diagnostics.go b/pkg/diagnostics/diagnostics.go index 215d4deef2..f85026c495 100644 --- a/pkg/diagnostics/diagnostics.go +++ b/pkg/diagnostics/diagnostics.go @@ -58,12 +58,13 @@ func CmdDbDump() *cobra.Command { func CmdAnalyze() *cobra.Command { cmd := &cobra.Command{ Use: "analyze", - Short: "Analyze the resource status by running tests on it", + Short: "Analyze the resource/network status by running tests on it", } cmd.AddCommand( CmdAnalyzeBackingStore(), CmdAnalyzeNamespaceStore(), CmdAnalyzeResources(), + CmdAnalyzeNetwork(), ) return cmd } @@ -79,6 +80,18 @@ func CmdReport() *cobra.Command { return cmd } +// CmdAnalyzeNetwork returns a CLI command +func CmdAnalyzeNetwork() *cobra.Command { + cmd := &cobra.Command{ + Use: "network", + Short: "Run network analyze", + Run: RunAnalyzeNetwork, + } + cmd.Flags().String("job-resources", "", "Analyze job resources JSON") + cmd.Flags().String("dir", "", "collect analyze network tar file into destination directory") + return cmd +} + // CmdAnalyzeBackingStore returns a CLI command func CmdAnalyzeBackingStore() *cobra.Command { cmd := &cobra.Command{