add supported k8s version check
This commit is contained in:
2
go.mod
2
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
|
||||
|
||||
@@ -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
11
internal/config/errors.go
Normal 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)
|
||||
}
|
||||
@@ -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)
|
||||
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",
|
||||
}
|
||||
return string(hashedPassword)
|
||||
|
||||
func validateConfig(cfg Config) error {
|
||||
if !slices.Contains(kubernetesVersions, cfg.Orchestrator.Version) {
|
||||
return &UnsupportedK8sVersion{Version: cfg.Orchestrator.Version}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user