fix(clustertool): ensure zerolog is used in more places
This commit is contained in:
@@ -112,7 +112,8 @@ func InstallCharts(charts []HelmChart, HelmRepos map[string]*HelmRepo, async boo
|
||||
if err := HelmInstall(HelmRepos[helmRelease.Spec.Chart.Spec.SourceRef.Name].Spec.URL, helmRelease.Spec.Chart.Spec.Chart, releaseName, helmRelease.Metadata.Namespace, valuesFile, helmRelease.Spec.Chart.Spec.Version, chart.Retry, chart.Wait, true); err != nil {
|
||||
if strings.Contains(err.Error(), "webhook") {
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
log.Error().Err(err).Msgf("Error: %v\n", err)
|
||||
|
||||
if !async {
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -143,14 +144,16 @@ func UpgradeCharts(charts []HelmChart, HelmRepos map[string]*HelmRepo, async boo
|
||||
// Load Helm release
|
||||
helmRelease, err := LoadHelmRelease(helmreleaseFile)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error loading Helm release for chart at %s: %v\n", chart.ChartPath, err)
|
||||
log.Error().Err(err).Msgf("Error loading Helm release for chart at %s: %v\n", chart.ChartPath)
|
||||
|
||||
if !async {
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
if helmRelease == nil {
|
||||
fmt.Fprintf(os.Stderr, "Empty Helm release for chart at %s\n", chart.ChartPath)
|
||||
log.Error().Msgf("Empty Helm release for chart at %s\n", chart.ChartPath)
|
||||
|
||||
if !async {
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -170,7 +173,8 @@ func UpgradeCharts(charts []HelmChart, HelmRepos map[string]*HelmRepo, async boo
|
||||
repoName := helmRelease.Spec.Chart.Spec.SourceRef.Name
|
||||
repo, ok := HelmRepos[repoName]
|
||||
if !ok || repo.Spec.URL == "" {
|
||||
fmt.Fprintf(os.Stderr, "Empty or invalid Helm repository for %s\n", repoName)
|
||||
log.Error().Msgf("Empty or invalid Helm repository for %s\n", repoName)
|
||||
|
||||
if !async {
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -181,7 +185,8 @@ func UpgradeCharts(charts []HelmChart, HelmRepos map[string]*HelmRepo, async boo
|
||||
log.Info().Msgf("Upgrading %s\n", helmRelease.Metadata.Name)
|
||||
err = HelmUpgrade(repo.Spec.URL, chartName, releaseName, helmRelease.Metadata.Namespace, valuesFile, helmRelease.Spec.Chart.Spec.Version, chart.Wait, true)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error upgrading %s: %v\n", helmRelease.Metadata.Name, err)
|
||||
log.Error().Err(err).Msgf("Error upgrading %s\n", helmRelease.Metadata.Name)
|
||||
|
||||
if !async {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package gencmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -90,7 +89,8 @@ func RunBootstrap(args []string) {
|
||||
|
||||
log.Info().Msgf("Bootstrap: Waiting for system Pods to be running for: %v", helper.TalEnv["VIP_IP"])
|
||||
if err := kubectlcmds.CheckStatus(requiredPods, []string{}, 600); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
log.Error().Err(err).Msgf("Error: %v\n", err)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ func RunBootstrap(args []string) {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error walking the path: %v\n", err)
|
||||
log.Info().Msgf("Error walking the path: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -196,7 +196,8 @@ func RunBootstrap(args []string) {
|
||||
|
||||
log.Info().Msgf("Bootstrap: Waiting for MetalLB Pods to be running for: %v", helper.TalEnv["VIP_IP"])
|
||||
if err := kubectlcmds.CheckStatus(requiredMLBPods, []string{}, 600); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
log.Error().Err(err).Msgf("Error: %v\n", err)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func ExportApps() {
|
||||
@@ -16,21 +18,24 @@ func ExportApps() {
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error executing command: %v\n", err)
|
||||
log.Error().Err(err).Msgf("Error executing command: %v\n", err)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Parse the JSON output
|
||||
var releases []map[string]interface{}
|
||||
if err := json.Unmarshal(out.Bytes(), &releases); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing JSON: %v\n", err)
|
||||
log.Error().Err(err).Msgf("Error parsing JSON: %v\n", err)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Ensure the directory exists
|
||||
outputDir := "./truenas_exports"
|
||||
if err := os.MkdirAll(outputDir, 0755); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating directory: %v\n", err)
|
||||
log.Error().Err(err).Msgf("Error creating directory: %v\n", err)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -46,14 +51,16 @@ func ExportApps() {
|
||||
// Marshal the release data to JSON
|
||||
data, err := json.MarshalIndent(release, "", " ")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error marshaling JSON: %v\n", err)
|
||||
log.Error().Err(err).Msgf("Error marshaling JSON: %v\n", err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
// Create the filename using the release name
|
||||
filename := filepath.Join(outputDir, fmt.Sprintf("%s.json", name))
|
||||
if err := ioutil.WriteFile(filename, data, 0644); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error writing file: %v\n", err)
|
||||
log.Error().Err(err).Msgf("Error writing file: %v\n", err)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user