mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-26 08:45:19 -04:00
fixup! init
This commit is contained in:
parent
a812abea68
commit
3f824b4ace
6 changed files with 29 additions and 12 deletions
|
@ -133,7 +133,7 @@ func parseGenerateFlags(cmd *cobra.Command) (generateFlags, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return generateFlags{}, fmt.Errorf("parsing Kubernetes flag: %w", err)
|
return generateFlags{}, fmt.Errorf("parsing Kubernetes flag: %w", err)
|
||||||
}
|
}
|
||||||
resolvedVersion, err := versions.NewValidK8sVersion(k8sVersion, true) // allow versions without specified patch
|
resolvedVersion, err := versions.NewValidK8sVersion(k8sVersion, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return generateFlags{}, fmt.Errorf("resolving Kubernetes version from flag: %w", err)
|
return generateFlags{}, fmt.Errorf("resolving Kubernetes version from flag: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,9 +149,7 @@ func (u *upgradeApplyCmd) upgradeApply(cmd *cobra.Command, upgradeDir string, fl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if versions.IsPreviewK8sVersion(conf.KubernetesVersion) {
|
conf.KubernetesVersion, err = validK8sVersion(cmd, string(conf.KubernetesVersion), flags.yes)
|
||||||
cmd.PrintErrf("Warning: Constellation with Kubernetes %q is still in preview. Use only for evaluation purposes.\n", conf.KubernetesVersion)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -307,6 +305,27 @@ func (u *upgradeApplyCmd) migrateTerraform(cmd *cobra.Command, conf *config.Conf
|
||||||
return tfOutput, nil
|
return tfOutput, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validK8sVersion checks if the Kubernetes patch version is supported and asks for confirmation if not.
|
||||||
|
func validK8sVersion(cmd *cobra.Command, version string, yes bool) (validVersion versions.ValidK8sVersion, err error) {
|
||||||
|
validVersion, err = versions.NewValidK8sVersion(version, true)
|
||||||
|
if versions.IsPreviewK8sVersion(validVersion) {
|
||||||
|
cmd.PrintErrf("Warning: Constellation with Kubernetes %v is still in preview. Use only for evaluation purposes.\n", validVersion)
|
||||||
|
}
|
||||||
|
valid := err == nil
|
||||||
|
|
||||||
|
if !valid && !yes {
|
||||||
|
confirmed, err := askToConfirm(cmd, fmt.Sprintf("WARNING: The Kubernetes patch version %s is not supported. If you continue, Kubernetes upgrades will be skipped. Do you want to continue anyway?", version))
|
||||||
|
if err != nil {
|
||||||
|
return validVersion, fmt.Errorf("asking for confirmation: %w", err)
|
||||||
|
}
|
||||||
|
if !confirmed {
|
||||||
|
return validVersion, fmt.Errorf("aborted by user")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return validVersion, nil
|
||||||
|
}
|
||||||
|
|
||||||
// confirmAndUpgradeAttestationConfig checks if the locally configured measurements are different from the cluster's measurements.
|
// confirmAndUpgradeAttestationConfig checks if the locally configured measurements are different from the cluster's measurements.
|
||||||
// If so the function will ask the user to confirm (if --yes is not set) and upgrade the cluster's config.
|
// If so the function will ask the user to confirm (if --yes is not set) and upgrade the cluster's config.
|
||||||
func (u *upgradeApplyCmd) confirmAndUpgradeAttestationConfig(
|
func (u *upgradeApplyCmd) confirmAndUpgradeAttestationConfig(
|
||||||
|
|
|
@ -115,8 +115,8 @@ func TestUpgradeApply(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return semver.NewFromInt(v.Major(), v.Minor(), v.Patch()-1, "").String()
|
return semver.NewFromInt(v.Major(), v.Minor(), v.Patch()-1, "").String()
|
||||||
}(),
|
}(),
|
||||||
wantErr: false,
|
|
||||||
flags: upgradeApplyFlags{yes: true},
|
flags: upgradeApplyFlags{yes: true},
|
||||||
|
wantErr: false,
|
||||||
},
|
},
|
||||||
"outdated K8s version": {
|
"outdated K8s version": {
|
||||||
kubeUpgrader: &stubKubernetesUpgrader{
|
kubeUpgrader: &stubKubernetesUpgrader{
|
||||||
|
@ -125,8 +125,8 @@ func TestUpgradeApply(t *testing.T) {
|
||||||
helmUpgrader: stubApplier{},
|
helmUpgrader: stubApplier{},
|
||||||
terraformUpgrader: &stubTerraformUpgrader{},
|
terraformUpgrader: &stubTerraformUpgrader{},
|
||||||
customK8sVersion: "v1.20.0",
|
customK8sVersion: "v1.20.0",
|
||||||
wantErr: true,
|
|
||||||
flags: upgradeApplyFlags{yes: true},
|
flags: upgradeApplyFlags{yes: true},
|
||||||
|
wantErr: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,6 @@ func (k *KubeCmd) UpgradeNodeVersion(ctx context.Context, conf *config.Config, f
|
||||||
nodeVersion.Spec.ImageReference = imageReference
|
nodeVersion.Spec.ImageReference = imageReference
|
||||||
nodeVersion.Spec.ImageVersion = imageVersion.Version()
|
nodeVersion.Spec.ImageVersion = imageVersion.Version()
|
||||||
|
|
||||||
// TODO(elchead): why?
|
|
||||||
// We have to allow users to specify outdated k8s patch versions.
|
// We have to allow users to specify outdated k8s patch versions.
|
||||||
// Therefore, this code has to skip k8s updates if a user configures an outdated (i.e. invalid) k8s version.
|
// Therefore, this code has to skip k8s updates if a user configures an outdated (i.e. invalid) k8s version.
|
||||||
var components *corev1.ConfigMap
|
var components *corev1.ConfigMap
|
||||||
|
|
|
@ -277,8 +277,7 @@ func writeUpgradeConfig(require *require.Assertions, image string, kubernetes st
|
||||||
if kubernetes == "" {
|
if kubernetes == "" {
|
||||||
kubernetesVersion = defaultConfig.KubernetesVersion
|
kubernetesVersion = defaultConfig.KubernetesVersion
|
||||||
} else {
|
} else {
|
||||||
kubernetesVersion, err = versions.NewValidK8sVersion(kubernetes, true)
|
kubernetesVersion = versions.ValidK8sVersion(kubernetes) // ignore validation because the config is only written to file
|
||||||
require.NoError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var microserviceVersion semver.Semver
|
var microserviceVersion semver.Semver
|
||||||
|
|
|
@ -48,10 +48,11 @@ func SupportedValidK8sVersions() (res []ValidK8sVersion) {
|
||||||
type ValidK8sVersion string
|
type ValidK8sVersion string
|
||||||
|
|
||||||
// NewValidK8sVersion validates the given string and produces a new ValidK8sVersion object.
|
// NewValidK8sVersion validates the given string and produces a new ValidK8sVersion object.
|
||||||
|
// It accepts a major minor version (e.g. 1.26) and transforms it into a supported patch version (e.g. 1.26.7).
|
||||||
|
// It also accepts a full version (e.g. 1.26.7) and validates it.
|
||||||
// Returns an empty string if the given version is invalid.
|
// Returns an empty string if the given version is invalid.
|
||||||
// strict controls whether the patch version is checked or not.
|
// strict controls whether the patch version is checked or not.
|
||||||
// If strict is false, the patch version is ignored and the returned
|
// If strict is false, the patch version is ignored and the returned.
|
||||||
// TODO(elchead): only allow strict mode?
|
|
||||||
func NewValidK8sVersion(k8sVersion string, strict bool) (ValidK8sVersion, error) {
|
func NewValidK8sVersion(k8sVersion string, strict bool) (ValidK8sVersion, error) {
|
||||||
prefixedVersion := compatibility.EnsurePrefixV(k8sVersion)
|
prefixedVersion := compatibility.EnsurePrefixV(k8sVersion)
|
||||||
parsedVersion, err := resolveK8sPatchVersion(prefixedVersion)
|
parsedVersion, err := resolveK8sPatchVersion(prefixedVersion)
|
||||||
|
@ -86,7 +87,6 @@ func (v *ValidK8sVersion) UnmarshalYAML(unmarshal func(interface{}) error) error
|
||||||
|
|
||||||
// resolveK8sPatchVersion takes the user input from --kubernetes and transforms a MAJOR.MINOR definition into a supported
|
// resolveK8sPatchVersion takes the user input from --kubernetes and transforms a MAJOR.MINOR definition into a supported
|
||||||
// MAJOR.MINOR.PATCH release.
|
// MAJOR.MINOR.PATCH release.
|
||||||
// TODO(elchead): should we support this resolvement also for the config?
|
|
||||||
func resolveK8sPatchVersion(k8sVersion string) (string, error) {
|
func resolveK8sPatchVersion(k8sVersion string) (string, error) {
|
||||||
if !semver.IsValid(k8sVersion) {
|
if !semver.IsValid(k8sVersion) {
|
||||||
return "", fmt.Errorf("kubernetes flag does not specify a valid semantic version: %s", k8sVersion)
|
return "", fmt.Errorf("kubernetes flag does not specify a valid semantic version: %s", k8sVersion)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue