feat(clustertool): actually fully block genconfig unless first init is finished

This commit is contained in:
Kjeld Schouten
2024-11-06 10:37:16 +01:00
parent d707b498ab
commit 269a895ab1
4 changed files with 44 additions and 5 deletions
-5
View File
@@ -3,10 +3,8 @@ package cmd
import (
"strings"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/truecharts/public/clustertool/pkg/gencmd"
"github.com/truecharts/public/clustertool/pkg/sops"
)
var genConfigLongHelp = strings.TrimSpace(`
@@ -24,9 +22,6 @@ var genConfig = &cobra.Command{
Long: genConfigLongHelp,
Example: "clustertool genconfig",
Run: func(cmd *cobra.Command, args []string) {
if err := sops.DecryptFiles(); err != nil {
log.Info().Msgf("Error decrypting files: %v\n", err)
}
gencmd.GenConfig(args)
},
+2
View File
@@ -28,9 +28,11 @@ func RunBootstrap(args []string) {
if len(args) > 1 {
extraArgs = args[1:]
}
if err := sops.DecryptFiles(); err != nil {
log.Info().Msgf("Error decrypting files: %v\n", err)
}
bootstrapNode := talassist.TalConfig.Nodes[0].IPAddress
bootstrapcmds := GenPlain("bootstrap", bootstrapNode, extraArgs)
+8
View File
@@ -11,10 +11,18 @@ import (
"github.com/truecharts/public/clustertool/pkg/fluxhandler"
"github.com/truecharts/public/clustertool/pkg/helper"
"github.com/truecharts/public/clustertool/pkg/initfiles"
"github.com/truecharts/public/clustertool/pkg/sops"
"github.com/truecharts/public/clustertool/pkg/talassist"
)
func GenConfig(args []string) error {
if initfiles.CheckRunAgainFileExists() {
log.Fatal().Msg("You need to re-run Init. Exiting...")
os.Exit(1)
}
if err := sops.DecryptFiles(); err != nil {
log.Info().Msgf("Error decrypting files: %v\n", err)
}
talassist.LoadTalConfig()
talassist.GenSchema()
initfiles.GenTalEnvConfigMap()
+34
View File
@@ -23,6 +23,7 @@ import (
)
func InitFiles() error {
removeRunAgainFile()
ageGen()
genRootFiles()
genBaseFiles()
@@ -145,6 +146,7 @@ func genBaseFiles() error {
clusterEnvPresent = true
log.Debug().Msg("Detected existing cluster, continuing")
} else if os.IsNotExist(err) {
createRunAgainFile()
log.Warn().Msg("New cluster detected, creating clusterenv.yaml\n Please fill out ClusterEnv.yaml and run init again!")
} else {
log.Fatal().Err(err).Msgf("Error checking clusterenv file: %s", err)
@@ -166,6 +168,38 @@ func genBaseFiles() error {
return nil
}
// Create the "RUNAGAIN" file
func createRunAgainFile() {
file, err := os.Create("RUNAGAIN")
if err != nil {
log.Err(err).Msg("error creating runagain file...")
return
}
defer file.Close()
return
}
// Remove the "RUNAGAIN" file if it exists
func removeRunAgainFile() error {
if CheckRunAgainFileExists() {
err := os.Remove("RUNAGAIN")
if err != nil {
log.Err(err).Msg("error removing runagain file...")
return err
}
log.Debug().Msg("RUNAGAIN file removed.")
} else {
log.Debug().Msg("RUNAGAIN file does not exist.")
}
return nil
}
// Check if the "RUNAGAIN" file exists
func CheckRunAgainFileExists() bool {
_, err := os.Stat("RUNAGAIN")
return !os.IsNotExist(err)
}
func UpdateBaseFiles() error {
log.Info().Msg("Updating Base files for cluster: helper.ClusterPath")
// Read filenames in source directory