diff --git a/deploy/job_analyze_network.yml b/deploy/job_analyze_network.yml new file mode 100644 index 000000000..8e96ba353 --- /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 1b95f6a19..bb7333376 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 232213ceb..5c5437e59 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 215d4deef..f85026c49 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{