Skip to content

Commit

Permalink
Printing overrided vars in cli command noobaa diagnostics report
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Sep 25, 2024
1 parent 5ffa9d3 commit b51b8f5
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions pkg/diagnostics/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package diagnostics

import (
"fmt"
"strings"

"github.com/noobaa/noobaa-operator/v5/pkg/bundle"
"github.com/noobaa/noobaa-operator/v5/pkg/options"
Expand All @@ -12,26 +13,32 @@ import (

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

// Fetching coreApp configurations
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.Println("")

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

// retrieving the overriden env variables using `CONFIG_JS_` prefix
overridenEnvVar(coreApp)

// TODO: Add support for additional features
}

// proxyStatus returns the status of the environment variables: HTTP_PROXY, HTTPS_PROXY, and NO_PROXY
func proxyStatus() {
func proxyStatus(coreApp *appsv1.StatefulSet) {
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")
fmt.Print("Proxy 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 != "" {
Expand All @@ -40,4 +47,19 @@ func proxyStatus() {
fmt.Printf(" ❌ %-12s : not set or empty.\n", proxyName)
}
}
fmt.Println("")
}

// overridedEnvVar retrieves and displays overridden environment variables with the prefix `CONFIG_JS_` from the noobaa-core-0 pod
func overridenEnvVar(coreApp *appsv1.StatefulSet) {
log := util.Logger()

log.Print("⏳ Retrieving overridden environment variables from the pod `noobaa-core-0`...\n")
fmt.Print("Overriden Environment Variables Check:\n----------------------------------\n")
for _, envVar := range coreApp.Spec.Template.Spec.Containers[0].Env {
if strings.HasPrefix(envVar.Name, "CONFIG_JS_") {
fmt.Printf(" ✔ %-12s : %s\n", envVar.Name, envVar.Value)
}
}
fmt.Println("")
}

0 comments on commit b51b8f5

Please sign in to comment.