Skip to content

Commit 885ce91

Browse files
committed
adding network analyzer
Signed-off-by: jackyalbo <[email protected]>
1 parent e2ea947 commit 885ce91

File tree

4 files changed

+116
-4
lines changed

4 files changed

+116
-4
lines changed

deploy/job_analyze_network.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: noobaa-analyze-network
5+
labels:
6+
app: noobaa
7+
spec:
8+
completions: 1
9+
parallelism: 1
10+
backoffLimit: 0
11+
activeDeadlineSeconds: 60
12+
ttlSecondsAfterFinished: 10
13+
template:
14+
spec:
15+
containers:
16+
- name: noobaa-analyze-network
17+
image: NOOBAA_CORE_IMAGE_PLACEHOLDER
18+
# env:
19+
# - name: RESOURCE_TYPE
20+
# - name: RESOURCE_NAME
21+
# - name: BUCKET
22+
# - name: ENDPOINT
23+
# - name: REGION
24+
# - name: S3_SIGNATURE_VERSION
25+
# - name: HTTP_PROXY
26+
# - name: HTTPS_PROXY
27+
# - name: NO_PROXY
28+
# - name: NODE_EXTRA_CA_CERTS
29+
command:
30+
- /bin/bash
31+
- -c
32+
- "cd /root/node_modules/noobaa-core/; node ./src/tools/diagnostics/analyze_network/analyze_network.js"
33+
restartPolicy: Never

pkg/bundle/deploy.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5247,6 +5247,43 @@ const File_deploy_internal_text_system_status_readme_rejected_tmpl = `
52475247
NooBaa Operator Version: {{.OperatorVersion}}
52485248
`
52495249

5250+
const Sha256_deploy_job_analyze_network_yml = "4f15b1aa0d98aa2eca62e615ed5c290d60a7ceb7c84f40b5f6c6aab0c6c0f5af"
5251+
5252+
const File_deploy_job_analyze_network_yml = `apiVersion: batch/v1
5253+
kind: Job
5254+
metadata:
5255+
name: noobaa-analyze-network
5256+
labels:
5257+
app: noobaa
5258+
spec:
5259+
completions: 1
5260+
parallelism: 1
5261+
backoffLimit: 0
5262+
activeDeadlineSeconds: 60
5263+
ttlSecondsAfterFinished: 10
5264+
template:
5265+
spec:
5266+
containers:
5267+
- name: noobaa-analyze-network
5268+
image: NOOBAA_CORE_IMAGE_PLACEHOLDER
5269+
# env:
5270+
# - name: RESOURCE_TYPE
5271+
# - name: RESOURCE_NAME
5272+
# - name: BUCKET
5273+
# - name: ENDPOINT
5274+
# - name: REGION
5275+
# - name: S3_SIGNATURE_VERSION
5276+
# - name: HTTP_PROXY
5277+
# - name: HTTPS_PROXY
5278+
# - name: NO_PROXY
5279+
# - name: NODE_EXTRA_CA_CERTS
5280+
command:
5281+
- /bin/bash
5282+
- -c
5283+
- "cd /root/node_modules/noobaa-core/; node ./src/tools/diagnostics/analyze_network/analyze_network.js"
5284+
restartPolicy: Never
5285+
`
5286+
52505287
const Sha256_deploy_job_analyze_resource_yml = "c80810baeda94fd9dd97a6c62241be5c582e08009bdbb1f2a13992c99d90ea33"
52515288

52525289
const File_deploy_job_analyze_resource_yml = `apiVersion: batch/v1

pkg/diagnostics/analyze.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,45 @@ func analyzeNamespaceStore(cmd *cobra.Command, namespaceStore *nbv1.NamespaceSto
172172
setJobAnalyzeResource(cmd, analyzeResourceJob, collector)
173173
}
174174

175+
// RunAnalyzeNetwork runs a CLI command
176+
func RunAnalyzeNetwork(cmd *cobra.Command, args []string) {
177+
log := util.Logger()
178+
179+
log.Printf("⏳ Running this command will run the network diagnostic\n")
180+
collector := collectorInstance(cmd)
181+
makeDirForLogs(collector.folderName)
182+
analyzeNetwork(cmd, collector)
183+
destDir, _ := cmd.Flags().GetString("dir")
184+
err := printTestsSummary(collector.folderName)
185+
if err != nil {
186+
log.Errorln("❌ Could not print tests summary")
187+
}
188+
collector.ExportDiagnostics(destDir)
189+
}
190+
191+
func analyzeNetwork(cmd *cobra.Command, collector *Collector) {
192+
analyzeResourceJob := loadAnalyzeNetworkJob()
193+
setImageInJob(analyzeResourceJob)
194+
setJobAnalyzeResource(cmd, analyzeResourceJob, collector)
195+
}
196+
197+
175198
func loadAnalyzeResourceJob() *batchv1.Job {
176199
analyzeResourceJob := util.KubeObject(bundle.File_deploy_job_analyze_resource_yml).(*batchv1.Job)
177200
analyzeResourceJob.Namespace = options.Namespace
178201
return analyzeResourceJob
179202
}
180203

204+
func loadAnalyzeNetworkJob() *batchv1.Job {
205+
analyzeNetworkJob := util.KubeObject(bundle.File_deploy_job_analyze_network_yml).(*batchv1.Job)
206+
analyzeNetworkJob.Namespace = options.Namespace
207+
return analyzeNetworkJob
208+
}
209+
181210
func collectorInstance(cmd *cobra.Command) *Collector {
182211
kubeconfig, _ := cmd.Flags().GetString("kubeconfig")
183212
collector := &Collector{
184-
folderName: fmt.Sprintf("%s_%d", "noobaa_analyze_resource", time.Now().Unix()),
213+
folderName: fmt.Sprintf("%s_%d", "noobaa_analyze_result", time.Now().Unix()),
185214
log: util.Logger(),
186215
kubeconfig: kubeconfig,
187216
kubeCommand: util.GetAvailabeKubeCli(),
@@ -479,8 +508,8 @@ func printTestsSummary(folderName string) error {
479508
scanner := bufio.NewScanner(file)
480509
shouldPrint := false
481510
// this is a printing that appears if it fails configuring or after the tests run (in the core repo)
482-
prefixToSearchFailed := "Test Diagnose Resource Failed"
483-
prefixToSearchSummary := "Analyze Resource Tests Result"
511+
prefixToSearchFailed := "Test Diagnose Network Failed"
512+
prefixToSearchSummary := "Analyze Network Tests Result"
484513
var indexToExtractLine int
485514
for scanner.Scan() {
486515
line := scanner.Text()

pkg/diagnostics/diagnostics.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ func CmdDbDump() *cobra.Command {
5858
func CmdAnalyze() *cobra.Command {
5959
cmd := &cobra.Command{
6060
Use: "analyze",
61-
Short: "Analyze the resource status by running tests on it",
61+
Short: "Analyze the resource/network status by running tests on it",
6262
}
6363
cmd.AddCommand(
6464
CmdAnalyzeBackingStore(),
6565
CmdAnalyzeNamespaceStore(),
6666
CmdAnalyzeResources(),
67+
CmdAnalyzeNetwork(),
6768
)
6869
return cmd
6970
}
@@ -79,6 +80,18 @@ func CmdReport() *cobra.Command {
7980
return cmd
8081
}
8182

83+
// CmdAnalyzeNetwork returns a CLI command
84+
func CmdAnalyzeNetwork() *cobra.Command {
85+
cmd := &cobra.Command{
86+
Use: "network",
87+
Short: "Run network analyze",
88+
Run: RunAnalyzeNetwork,
89+
}
90+
cmd.Flags().String("job-resources", "", "Analyze job resources JSON")
91+
cmd.Flags().String("dir", "", "collect analyze network tar file into destination directory")
92+
return cmd
93+
}
94+
8295
// CmdAnalyzeBackingStore returns a CLI command
8396
func CmdAnalyzeBackingStore() *cobra.Command {
8497
cmd := &cobra.Command{

0 commit comments

Comments
 (0)