fix(clustertool): fix some talhelper-connectivity mistakes
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
|||||||
|
|
||||||
talhelperCfg "github.com/budimanjojo/talhelper/v3/pkg/config"
|
talhelperCfg "github.com/budimanjojo/talhelper/v3/pkg/config"
|
||||||
"github.com/budimanjojo/talhelper/v3/pkg/generate"
|
"github.com/budimanjojo/talhelper/v3/pkg/generate"
|
||||||
|
"github.com/budimanjojo/talhelper/v3/pkg/substitute"
|
||||||
"github.com/budimanjojo/talhelper/v3/pkg/talos"
|
"github.com/budimanjojo/talhelper/v3/pkg/talos"
|
||||||
"github.com/fatih/color"
|
|
||||||
sideroConfig "github.com/siderolabs/talos/pkg/machinery/config"
|
sideroConfig "github.com/siderolabs/talos/pkg/machinery/config"
|
||||||
"github.com/siderolabs/talos/pkg/machinery/config/generate/secrets"
|
"github.com/siderolabs/talos/pkg/machinery/config/generate/secrets"
|
||||||
"github.com/truecharts/public/clustertool/pkg/fluxhandler"
|
"github.com/truecharts/public/clustertool/pkg/fluxhandler"
|
||||||
@@ -28,7 +28,6 @@ func GenConfig(args []string) error {
|
|||||||
genTalSecret()
|
genTalSecret()
|
||||||
validateTalConfig(args)
|
validateTalConfig(args)
|
||||||
talhelperGenConfig()
|
talhelperGenConfig()
|
||||||
validateTalConfig(args)
|
|
||||||
initfiles.UpdateGitRepo()
|
initfiles.UpdateGitRepo()
|
||||||
|
|
||||||
if err := fluxhandler.ProcessDirectory(path.Join(helper.ClusterPath, "kubernetes")); err != nil {
|
if err := fluxhandler.ProcessDirectory(path.Join(helper.ClusterPath, "kubernetes")); err != nil {
|
||||||
@@ -95,11 +94,10 @@ func talhelperGenConfig() error {
|
|||||||
genconfigDryRun := false
|
genconfigDryRun := false
|
||||||
genconfigOfflineMode := false
|
genconfigOfflineMode := false
|
||||||
|
|
||||||
cfg, err := talhelperCfg.LoadAndValidateFromFile(helper.TalConfigFile, []string{helper.ClusterEnvFile}, true)
|
cfg, err := talhelperCfg.LoadAndValidateFromFile(helper.TalConfigFile, []string{helper.ClusterEnvFile}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msgf("failed to parse TalConfig or talenv file: %s", err)
|
log.Fatal().Err(err).Msgf("failed to parse TalConfig or talenv file: %s", err)
|
||||||
}
|
}
|
||||||
log.Info().Msg("Start Generating Config File...")
|
|
||||||
|
|
||||||
err = generate.GenerateConfig(cfg, genconfigDryRun, helper.TalosGenerated, helper.TalSecretFile, genconfigTalosMode, genconfigOfflineMode)
|
err = generate.GenerateConfig(cfg, genconfigDryRun, helper.TalosGenerated, helper.TalSecretFile, genconfigTalosMode, genconfigOfflineMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -125,38 +123,52 @@ func validateTalConfig(argsInt []string) error {
|
|||||||
log.Fatal().Err(err).Msgf("failed to read Talconfig file %s: %s", helper.TalConfigFile, err)
|
log.Fatal().Err(err).Msgf("failed to read Talconfig file %s: %s", helper.TalConfigFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := substitute.LoadEnvFromFiles([]string{helper.ClusterEnvFile}); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("failed to load env file: %s")
|
||||||
|
}
|
||||||
|
cfgByte, err = substitute.SubstituteEnvFromByte(cfgByte)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("failed trying to substitute env: %s")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debug().Msg("Checking configfile after substitution...")
|
||||||
|
|
||||||
errs, warns, err := talhelperCfg.ValidateFromByte(cfgByte)
|
errs, warns, err := talhelperCfg.ValidateFromByte(cfgByte)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msgf("failed to validate talhelper config file: %s", err)
|
log.Fatal().Err(err).Msgf("failed to validate talhelper config file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
|
log.Trace().Msg("running talconfig validation errs...")
|
||||||
log.Error().Msg("There are issues with your talhelper config file:")
|
log.Error().Msg("There are issues with your talhelper config file:")
|
||||||
groupedWarns := make(map[string][]string)
|
groupedErr := make(map[string][]string)
|
||||||
for _, v := range errs {
|
for _, v := range errs {
|
||||||
groupedWarns[v.Field] = append(groupedWarns[v.Field], v.Message.Error())
|
groupedErr[v.Field] = append(groupedErr[v.Field], v.Message.Error())
|
||||||
}
|
}
|
||||||
for field, list := range groupedWarns {
|
for field, list := range groupedErr {
|
||||||
color.Yellow("field: %q\n", field)
|
log.Error().Msgf("field: %q\n", field)
|
||||||
for _, l := range list {
|
for _, l := range list {
|
||||||
log.Error().Msgf(l + "\n")
|
log.Error().Msgf(l + "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(warns) > 0 {
|
os.Exit(1)
|
||||||
log.Warn().Msg("There might be some issues with your talhelper config file:")
|
} else if len(warns) > 0 {
|
||||||
groupedErr := make(map[string][]string)
|
log.Trace().Msg("running talconfig validation warns...")
|
||||||
for _, v := range warns {
|
log.Warn().Msg("There might be some issues with your talhelper config file:")
|
||||||
groupedErr[v.Field] = append(groupedErr[v.Field], v.Message)
|
groupedWarn := make(map[string][]string)
|
||||||
}
|
for _, v := range warns {
|
||||||
for field, list := range groupedErr {
|
groupedWarn[v.Field] = append(groupedWarn[v.Field], v.Message)
|
||||||
color.Yellow("field: %q\n", field)
|
|
||||||
for _, l := range list {
|
}
|
||||||
log.Warn().Msgf(l + "\n")
|
for field, list := range groupedWarn {
|
||||||
}
|
log.Warn().Msgf("field: %q\n", field)
|
||||||
|
for _, l := range list {
|
||||||
|
log.Warn().Msgf(l + "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Info().Msg("Your talhelper config file is looking great!")
|
log.Info().Msg("Your talhelper config file is looking great!")
|
||||||
}
|
}
|
||||||
|
log.Info().Msg("Finished validating talconfig")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
// TODO: remove talhelper dependency for cmd creation
|
// TODO: remove talhelper dependency for cmd creation
|
||||||
func GenUpgrade(node string, extraFlags []string) []string {
|
func GenUpgrade(node string, extraFlags []string) []string {
|
||||||
|
// TODO: get rid of this, due to double uncontrollable log output
|
||||||
cfg, err := talhelperCfg.LoadAndValidateFromFile(helper.TalConfigFile, []string{helper.ClusterEnvFile}, false)
|
cfg, err := talhelperCfg.LoadAndValidateFromFile(helper.TalConfigFile, []string{helper.ClusterEnvFile}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msgf("failed to parse talconfig or talenv file: %s", err)
|
log.Fatal().Err(err).Msgf("failed to parse talconfig or talenv file: %s", err)
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ func LoadTalEnv(noFail bool) error {
|
|||||||
} else if os.IsNotExist(err) {
|
} else if os.IsNotExist(err) {
|
||||||
// If the file doesn't exist, check noFail to determine next steps
|
// If the file doesn't exist, check noFail to determine next steps
|
||||||
if noFail {
|
if noFail {
|
||||||
log.Info().Msg("clusterenv.yaml file not found, but skipping due to noFail being true.")
|
log.Debug().Msg("clusterenv.yaml file not found, but skipping due to noFail being true.")
|
||||||
return nil // Skip execution without error
|
return nil // Skip execution without error
|
||||||
} else {
|
} else {
|
||||||
log.Info().Msg("clusterenv.yaml file not found, exiting as noFail is false.")
|
log.Fatal().Msg("clusterenv.yaml file not found, exiting...")
|
||||||
os.Exit(1) // Exit with error code 1
|
os.Exit(1) // Exit with error code 1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -141,13 +141,29 @@ func FormatGitURL(input string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genBaseFiles() error {
|
func genBaseFiles() error {
|
||||||
|
clusterEnvPresent := false
|
||||||
|
|
||||||
|
if _, err := os.Stat(helper.ClusterEnvFile); err == nil {
|
||||||
|
clusterEnvPresent = true
|
||||||
|
log.Debug().Msg("Detected existing cluster, continuing")
|
||||||
|
} else if os.IsNotExist(err) {
|
||||||
|
log.Warn().Msg("New cluster detected, creating clusterenv.yaml\n Please fill out ClusterEnv.yaml and run again!")
|
||||||
|
} else {
|
||||||
|
log.Fatal().Err(err).Msgf("Error checking clusterenv file: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err := helper.CopyDir(helper.BaseCache, helper.ClusterPath+"", false)
|
err := helper.CopyDir(helper.BaseCache, helper.ClusterPath+"", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info().Msgf("Error: %v", err)
|
log.Error().Msgf("Error: %v", err)
|
||||||
} else {
|
} else {
|
||||||
log.Info().Msg("Base files copied successfully.")
|
log.Info().Msg("Base files copied successfully.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !clusterEnvPresent {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
log.Info().Msg("basefiles successfully altered.")
|
log.Info().Msg("basefiles successfully altered.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user