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 17, 2024
1 parent bab395a commit 46c85f3
Show file tree
Hide file tree
Showing 2 changed files with 55 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: "Run reports of the status and setup",
Run: RunReport,
Args: cobra.NoArgs,
}
return cmd
}

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

import (
"fmt"

"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) {

// retrieving the status of proxy environment variables
proxyStatus()

// TODO: Add support for additional features
}

// proxyStatus returns the status of the environment variables: HTTP_PROXY, HTTPS_PROXY, and NO_PROXY
func proxyStatus() {
log := util.Logger()

log.Print("⏳ Retrieving proxy environment variable details...\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)
}

fmt.Print("\nProxy Environment Variables Check:\n----------------------------------\n")
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 != "" {
fmt.Printf(" ✅ %-12s : %s\n", envVar.Name, envVar.Value)
} else {
fmt.Printf(" ❌ %-12s : not set or empty.\n", proxyName)
}
}
}

0 comments on commit 46c85f3

Please sign in to comment.