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 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") {
|
if strings.Contains(err.Error(), "webhook") {
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
log.Error().Err(err).Msgf("Error: %v\n", err)
|
||||||
|
|
||||||
if !async {
|
if !async {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@@ -143,14 +144,16 @@ func UpgradeCharts(charts []HelmChart, HelmRepos map[string]*HelmRepo, async boo
|
|||||||
// Load Helm release
|
// Load Helm release
|
||||||
helmRelease, err := LoadHelmRelease(helmreleaseFile)
|
helmRelease, err := LoadHelmRelease(helmreleaseFile)
|
||||||
if err != nil {
|
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 {
|
if !async {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if helmRelease == nil {
|
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 {
|
if !async {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@@ -170,7 +173,8 @@ func UpgradeCharts(charts []HelmChart, HelmRepos map[string]*HelmRepo, async boo
|
|||||||
repoName := helmRelease.Spec.Chart.Spec.SourceRef.Name
|
repoName := helmRelease.Spec.Chart.Spec.SourceRef.Name
|
||||||
repo, ok := HelmRepos[repoName]
|
repo, ok := HelmRepos[repoName]
|
||||||
if !ok || repo.Spec.URL == "" {
|
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 {
|
if !async {
|
||||||
os.Exit(1)
|
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)
|
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)
|
err = HelmUpgrade(repo.Spec.URL, chartName, releaseName, helmRelease.Metadata.Namespace, valuesFile, helmRelease.Spec.Chart.Spec.Version, chart.Wait, true)
|
||||||
if err != nil {
|
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 {
|
if !async {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package gencmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"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"])
|
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 {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ func RunBootstrap(args []string) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error walking the path: %v\n", err)
|
log.Info().Msgf("Error walking the path: %v\n", err)
|
||||||
return
|
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"])
|
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 {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExportApps() {
|
func ExportApps() {
|
||||||
@@ -16,21 +18,24 @@ func ExportApps() {
|
|||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
if err := cmd.Run(); err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the JSON output
|
// Parse the JSON output
|
||||||
var releases []map[string]interface{}
|
var releases []map[string]interface{}
|
||||||
if err := json.Unmarshal(out.Bytes(), &releases); err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the directory exists
|
// Ensure the directory exists
|
||||||
outputDir := "./truenas_exports"
|
outputDir := "./truenas_exports"
|
||||||
if err := os.MkdirAll(outputDir, 0755); err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,14 +51,16 @@ func ExportApps() {
|
|||||||
// Marshal the release data to JSON
|
// Marshal the release data to JSON
|
||||||
data, err := json.MarshalIndent(release, "", " ")
|
data, err := json.MarshalIndent(release, "", " ")
|
||||||
if err != nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the filename using the release name
|
// Create the filename using the release name
|
||||||
filename := filepath.Join(outputDir, fmt.Sprintf("%s.json", name))
|
filename := filepath.Join(outputDir, fmt.Sprintf("%s.json", name))
|
||||||
if err := ioutil.WriteFile(filename, data, 0644); err != nil {
|
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