add supported k8s version check

This commit is contained in:
2025-08-09 17:00:02 +03:00
parent 5e8b03ff10
commit 5466c3e36f
4 changed files with 57 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package config
import (
"fmt"
"kube-forge/internal/files"
"kube-forge/internal/logging"
"path/filepath"
"github.com/ilyakaznacheev/cleanenv"
@@ -72,6 +73,11 @@ func createConfig(configFile string, out string, password string, verbose bool)
}
instance.Verbose = verbose
err := validateConfig(*instance)
if err != nil {
logging.Log.Fatal(err.Error())
}
return instance
}

11
internal/config/errors.go Normal file
View File

@@ -0,0 +1,11 @@
package config
import "fmt"
type UnsupportedK8sVersion struct {
Version string
}
func (e *UnsupportedK8sVersion) Error() string {
return fmt.Sprintf("kubernetes version %s is not supported\n\ncurrently supported: %v", e.Version, kubernetesVersions)
}

View File

@@ -1,13 +1,45 @@
package config
import (
"golang.org/x/crypto/bcrypt"
"slices"
)
func getBcryptHash(input string) string {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(input), bcrypt.DefaultCost)
if err != nil {
panic(err)
}
return string(hashedPassword)
var kubernetesVersions = []string{
"1.32.5",
"1.32.4",
"1.32.3",
"1.32.2",
"1.32.1",
"1.32.0",
"1.31.9",
"1.31.8",
"1.31.7",
"1.31.6",
"1.31.5",
"1.31.4",
"1.31.3",
"1.31.2",
"1.31.1",
"1.31.0",
"1.30.13",
"1.30.12",
"1.30.11",
"1.30.10",
"1.30.9",
"1.30.8",
"1.30.7",
"1.30.6",
"1.30.5",
"1.30.4",
"1.30.3",
"1.30.2",
"1.30.1",
"1.30.0",
}
func validateConfig(cfg Config) error {
if !slices.Contains(kubernetesVersions, cfg.Orchestrator.Version) {
return &UnsupportedK8sVersion{Version: cfg.Orchestrator.Version}
}
return nil
}