Skip to content

Commit

Permalink
Added proxy check for endpoint and removed duplicate code
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Oct 7, 2024
1 parent 6d82940 commit 07b1f1a
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions pkg/diagnostics/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/noobaa/noobaa-operator/v5/pkg/util"
"github.com/spf13/cobra"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)

const (
appNoobaaCore = "NOOBAA-CORE"
appNoobaaEndpoint = "NOOBAA-ENDPOINT"
)

// RunReport runs a CLI command
Expand All @@ -33,60 +39,66 @@ func RunReport(cmd *cobra.Command, args []string) {
fmt.Println("")

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

// retrieving the overridden env variables using `CONFIG_JS_` prefix
OverriddenEnvVar(coreApp, endpointApp)
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(coreApp *appsv1.StatefulSet) {
func proxyStatus(coreApp *appsv1.StatefulSet, endpointApp *appsv1.Deployment) {
log := util.Logger()

log.Print("⏳ Retrieving proxy environment variable details...\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 != "" {
fmt.Printf(" ✅ %-12s : %s\n", envVar.Name, envVar.Value)
} else {
fmt.Printf(" ❌ %-12s : not set or empty.\n", proxyName)
}
}

printProxyStatus(appNoobaaCore, coreApp.Spec.Template.Spec.Containers[0].Env)

printProxyStatus(appNoobaaEndpoint, endpointApp.Spec.Template.Spec.Containers[0].Env)

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) {
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
printOverriddenEnvVar(appNoobaaCore, coreApp.Spec.Template.Spec.Containers[0].Env)

printOverriddenEnvVar(appNoobaaEndpoint, endpointApp.Spec.Template.Spec.Containers[0].Env)

fmt.Println("")
}

// printProxyStatus prints the proxy status
func printProxyStatus(appName string, envVars []corev1.EnvVar) {
fmt.Printf("Proxy Environment Variables Check (%s):\n----------------------------------\n", appName)
for _, proxyName := range []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"} {
envVar := util.GetEnvVariable(&envVars, 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)
}
}
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 {
// printOverriddenEnvVar prints the overridden envVars
func printOverriddenEnvVar(appName string, envVars []corev1.EnvVar) {
fmt.Printf("Overridden Environment Variables Check (%s):\n----------------------------------\n", appName)
foundOverriddenEnv := false
for _, envVar := range envVars {
if strings.HasPrefix(envVar.Name, "CONFIG_JS_") {
fmt.Printf(" ✔ %s : %s\n", envVar.Name, envVar.Value)
foundEndpointEnv = true
foundOverriddenEnv = true
}
}
if !foundEndpointEnv {
fmt.Printf(" ❌ No overridden environment variables found.")
if !foundOverriddenEnv {
fmt.Print(" ❌ No overridden environment variables found.\n")
}
fmt.Println("")
}

0 comments on commit 07b1f1a

Please sign in to comment.