feat(clustertool/spegel): improve spegel behavior for clustertool and make kubedashboard optional on clustertool
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func GenApply(node string, extraFlags []string) []string {
|
||||
initfiles.LoadTalEnv()
|
||||
initfiles.LoadTalEnv(false)
|
||||
cfg, err := talhelperCfg.LoadAndValidateFromFile(helper.TalConfigFile, []string{helper.ClusterEnvFile}, false)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to parse talconfig or talenv file: %s")
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
)
|
||||
|
||||
func LoadTalEnv() error {
|
||||
// Check if talenv.yaml file exists
|
||||
func LoadTalEnv(noFail bool) error {
|
||||
// Check if clusterenv.yaml file exists
|
||||
if _, err := os.Stat(helper.ClusterPath + "/clusterenv.yaml"); err == nil {
|
||||
// Load environment variables from clusterenv.yaml
|
||||
err := helper.LoadEnvFromFile(helper.ClusterPath+"/clusterenv.yaml", helper.TalEnv)
|
||||
@@ -23,11 +23,20 @@ func LoadTalEnv() error {
|
||||
os.Exit(1)
|
||||
}
|
||||
} else if os.IsNotExist(err) {
|
||||
log.Info().Msg("clusterenv.yaml file not found, skipping environment variable loading.")
|
||||
// If the file doesn't exist, check noFail to determine next steps
|
||||
if noFail {
|
||||
log.Info().Msg("clusterenv.yaml file not found, but skipping due to noFail being true.")
|
||||
return nil // Skip execution without error
|
||||
} else {
|
||||
log.Info().Msg("clusterenv.yaml file not found, exiting as noFail is false.")
|
||||
os.Exit(1) // Exit with error code 1
|
||||
}
|
||||
} else {
|
||||
log.Info().Msgf("Error checking clusterenv.yaml file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// If file exists, continue with processing
|
||||
clusterName()
|
||||
checkQuotedNumbersInFile()
|
||||
PostProcessTalEnv()
|
||||
@@ -214,14 +223,13 @@ func normalizeIPNetmask(ipNetmask string) (string, error) {
|
||||
}
|
||||
|
||||
func CheckEnvVariables() {
|
||||
LoadTalEnv()
|
||||
LoadTalEnv(false)
|
||||
requiredKeys := []string{
|
||||
"VIP",
|
||||
"MASTER1IP_IP",
|
||||
"MASTER1IP_NETMASK",
|
||||
"GATEWAY",
|
||||
"METALLB_RANGE",
|
||||
"DASHBOARD_IP_IP",
|
||||
"PODNET",
|
||||
"SVCNET",
|
||||
}
|
||||
@@ -282,14 +290,16 @@ func CheckEnvVariables() {
|
||||
}
|
||||
|
||||
// Check DASHBOARD_IP against METALLB_RANGE
|
||||
inRange, err = helper.IPInRange(helper.TalEnv["DASHBOARD_IP"], helper.TalEnv["METALLB_RANGE"])
|
||||
if err != nil {
|
||||
log.Info().Msgf("Error checking DASHBOARD_IP against METALLB_RANGE: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !inRange {
|
||||
log.Info().Msg("Cannot proceed, DASHBOARD_IP must be in the METALLB_RANGE")
|
||||
os.Exit(1)
|
||||
if helper.TalEnv["DASHBOARD_IP"] != "" {
|
||||
inRange, err = helper.IPInRange(helper.TalEnv["DASHBOARD_IP"], helper.TalEnv["METALLB_RANGE"])
|
||||
if err != nil {
|
||||
log.Info().Msgf("Error checking DASHBOARD_IP against METALLB_RANGE: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !inRange {
|
||||
log.Info().Msg("Cannot proceed, DASHBOARD_IP must be in the METALLB_RANGE")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Validate other CIDR/IP checks with new netmask support
|
||||
|
||||
@@ -151,6 +151,7 @@ func genBaseFiles() error {
|
||||
}
|
||||
|
||||
func UpdateBaseFiles() error {
|
||||
log.Info().Msg("Updating Base files for cluster: helper.ClusterPath")
|
||||
// Read filenames in source directory
|
||||
sourceFiles, err := readFilenamesInDir(helper.BaseCache)
|
||||
if err != nil {
|
||||
@@ -244,7 +245,7 @@ func readFilenamesInDir(dir string) ([]string, error) {
|
||||
}
|
||||
|
||||
func ResetBootstrapValues() error {
|
||||
LoadTalEnv()
|
||||
LoadTalEnv(false)
|
||||
err := helper.CopyDirFiltered(helper.KubeCache, helper.ClusterPath+"/kubernetes", true, `^bootstrap-values\.yaml.ct$`)
|
||||
if err != nil {
|
||||
log.Info().Msg("Error:")
|
||||
@@ -309,18 +310,15 @@ func setDocker() {
|
||||
if helper.TalEnv["DOCKERHUB_USER"] != "" && helper.TalEnv["DOCKERHUB_PASSWORD"] != "" {
|
||||
// Prepare the content to append
|
||||
configContent := fmt.Sprintf(`# Add Dockerhub Login
|
||||
- operation: replace
|
||||
path: /machine/registries/config/registry-1.docker.io
|
||||
value:
|
||||
registry-1.docker.io:
|
||||
auth:
|
||||
username: %s
|
||||
password: %s
|
||||
- operation: replace
|
||||
path: /machine/registries/config/docker.io
|
||||
value:
|
||||
docker.io:
|
||||
auth:
|
||||
username: %s
|
||||
password: %s
|
||||
|
||||
`, helper.TalEnv["DOCKERHUB_USER"], helper.TalEnv["DOCKERHUB_PASSWORD"], helper.TalEnv["DOCKERHUB_USER"], helper.TalEnv["DOCKERHUB_PASSWORD"])
|
||||
|
||||
// Open the file in append mode or create it if it doesn't exist
|
||||
@@ -355,42 +353,62 @@ func setSpegel() {
|
||||
if helper.TalEnv["SPEGEL_IP"] != "" && helper.TalEnv["SPEGEL_IP"] != "" {
|
||||
// Prepare the content to append
|
||||
configContent := fmt.Sprintf(`# Add Dockerhub Login
|
||||
- operation: replace
|
||||
path: /machine/registries/mirrors/
|
||||
value:
|
||||
cgr.dev:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
docker.io:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
ghcr.io:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
quay.io:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
mcr.microsoft.com:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
public.ecr.aws:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
gcr.io:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
registry.k8s.io:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
k8s.gcr.io:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
tccr.io:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
factory.talos.dev:
|
||||
endpoints:
|
||||
- http://%s:5000
|
||||
mirrors:
|
||||
cgr.dev:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
docker.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
ghcr.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
quay.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
mcr.microsoft.com:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
public.ecr.aws:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
gcr.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
registry.k8s.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
k8s.gcr.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
tccr.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
factory.talos.dev:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
- http://%s:5000
|
||||
|
||||
`, helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"], helper.TalEnv["SPEGEL_IP"])
|
||||
|
||||
@@ -407,15 +425,62 @@ func setSpegel() {
|
||||
}
|
||||
} else {
|
||||
// Optional: Append a note if the environment variables are not set
|
||||
emptyContent := `# No Spegel_IP provided
|
||||
`
|
||||
configContent := fmt.Sprintf(`# No Spegel_IP provide
|
||||
mirrors:
|
||||
cgr.dev:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
docker.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
ghcr.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
quay.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
mcr.microsoft.com:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
public.ecr.aws:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
gcr.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
registry.k8s.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
k8s.gcr.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
tccr.io:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
factory.talos.dev:
|
||||
endpoints:
|
||||
- http://127.0.0.1:30020
|
||||
- http://127.0.0.1:30021
|
||||
|
||||
`)
|
||||
|
||||
file, err := os.OpenFile(filepath.Join(helper.ClusterPath+"/talos/patches", "all.yaml"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Error opening file: %s")
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err := file.Write([]byte(emptyContent)); err != nil {
|
||||
if _, err := file.Write([]byte(configContent)); err != nil {
|
||||
log.Fatal().Err(err).Msg("Error writing to file: %s")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func DecryptFiles() error {
|
||||
if !encryptedFound {
|
||||
log.Info().Msg("Nothing to decrypt")
|
||||
}
|
||||
initfiles.LoadTalEnv()
|
||||
initfiles.LoadTalEnv(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user