Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network Analyzer - Operator side #1488

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions deploy/job_analyze_network.yml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 32 additions & 3 deletions pkg/diagnostics/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion pkg/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{
Expand Down
Loading