Skip to content

Commit

Permalink
Added a CLI sub-command in noobaa diagnostics to print proxy details
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Sep 12, 2024
1 parent 089b5af commit 6047c1f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Cmd() *cobra.Command {
CmdCollect(),
CmdDbDump(),
CmdAnalyze(),
CmdReport(),
)
return cmd
}
Expand Down Expand Up @@ -67,6 +68,17 @@ func CmdAnalyze() *cobra.Command {
return cmd
}

// CmdReport returns a CLI command
func CmdReport() *cobra.Command {
cmd := &cobra.Command{
Use: "report",
Short: "Reports the proxy status",
Run: RunReport,
Args: cobra.NoArgs,
}
return cmd
}

// CmdAnalyzeBackingStore returns a CLI command
func CmdAnalyzeBackingStore() *cobra.Command {
cmd := &cobra.Command{
Expand Down
32 changes: 32 additions & 0 deletions pkg/diagnostics/report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package diagnostics

import (
"github.com/noobaa/noobaa-operator/v5/pkg/bundle"
"github.com/noobaa/noobaa-operator/v5/pkg/options"
"github.com/noobaa/noobaa-operator/v5/pkg/util"
"github.com/spf13/cobra"
appsv1 "k8s.io/api/apps/v1"
)

// RunReport runs a CLI command
func RunReport(cmd *cobra.Command, args []string) {
log := util.Logger()

log.Printf("⏳ Retrieving proxy environment variable details...\n\n")

coreApp := util.KubeObject(bundle.File_deploy_internal_statefulset_core_yaml).(*appsv1.StatefulSet)
coreApp.Namespace = options.Namespace
if !util.KubeCheck(coreApp) {
log.Fatalf(`❌ Could not get core StatefulSet %q in Namespace %q`,
coreApp.Name, coreApp.Namespace)
}

for _, proxyName := range []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"} {
envVar := util.GetEnvVariable(&coreApp.Spec.Template.Spec.Containers[0].Env, proxyName)
if envVar != nil && envVar.Value != "" {
log.Printf("✅ %s is set to: %s\n", envVar.Name, envVar.Value)
} else {
log.Errorf("❌ %s is not set or is empty.\n", proxyName)
}
}
}

0 comments on commit 6047c1f

Please sign in to comment.