Skip to content

Commit

Permalink
Merge pull request #1445 from achouhan09/config_js_var
Browse files Browse the repository at this point in the history
Printing overrided  vars in  cli command `noobaa diagnostics report`
  • Loading branch information
achouhan09 authored Sep 30, 2024
2 parents c6727ce + 6eaff91 commit 7611fca
Showing 1 changed file with 59 additions and 10 deletions.
69 changes: 59 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,40 @@ 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)
}

// Fetching endpoint configurations
endpointApp := util.KubeObject(bundle.File_deploy_internal_deployment_endpoint_yaml).(*appsv1.Deployment)
endpointApp.Namespace = options.Namespace
if !util.KubeCheck(endpointApp) {
log.Fatalf(`❌ Could not get endpoint Deployment %q in Namespace %q`,
endpointApp.Name, endpointApp.Namespace)
}
fmt.Println("")

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

// retrieving the overridden env variables using `CONFIG_JS_` prefix
OverriddenEnvVar(coreApp, endpointApp)

// 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 +55,38 @@ func proxyStatus() {
fmt.Printf(" ❌ %-12s : not set or empty.\n", proxyName)
}
}
fmt.Println("")
}

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

log.Print("⏳ Retrieving overridden environment variable details...\n")

fmt.Print("Overridden Environment Variables Check (NOOBAA-CORE):\n----------------------------------\n")
foundCoreEnv := false
for _, envVar := range coreApp.Spec.Template.Spec.Containers[0].Env {
if strings.HasPrefix(envVar.Name, "CONFIG_JS_") {
fmt.Printf(" ✔ %s : %s\n", envVar.Name, envVar.Value)
foundCoreEnv = true
}
}
if !foundCoreEnv {
fmt.Printf(" ❌ No overridden environment variables found.")
}
fmt.Println("")

fmt.Print("Overridden Environment Variables Check (ENDPOINT):\n----------------------------------\n")
foundEndpointEnv := false
for _, envVar := range endpointApp.Spec.Template.Spec.Containers[0].Env {
if strings.HasPrefix(envVar.Name, "CONFIG_JS_") {
fmt.Printf(" ✔ %s : %s\n", envVar.Name, envVar.Value)
foundEndpointEnv = true
}
}
if !foundEndpointEnv {
fmt.Printf(" ❌ No overridden environment variables found.")
}
fmt.Println("")
}

0 comments on commit 7611fca

Please sign in to comment.