diff --git a/go.mod b/go.mod index 922f0e5..f8734e3 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/mittwald/go-helm-client v0.12.17 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.9.1 - golang.org/x/crypto v0.35.0 gopkg.in/yaml.v2 v2.4.0 helm.sh/helm/v3 v3.17.1 ) @@ -128,6 +127,7 @@ require ( go.opentelemetry.io/otel v1.28.0 // indirect go.opentelemetry.io/otel/metric v1.28.0 // indirect go.opentelemetry.io/otel/trace v1.28.0 // indirect + golang.org/x/crypto v0.35.0 // indirect golang.org/x/net v0.36.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.11.0 // indirect diff --git a/internal/config/config.go b/internal/config/config.go index 97856b4..2c81d2b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 } diff --git a/internal/config/errors.go b/internal/config/errors.go new file mode 100644 index 0000000..10be367 --- /dev/null +++ b/internal/config/errors.go @@ -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) +} diff --git a/internal/config/utility.go b/internal/config/utility.go index 860ae3d..29f6726 100644 --- a/internal/config/utility.go +++ b/internal/config/utility.go @@ -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 }