diff --git a/bootstrapper/internal/kubernetes/k8sapi/kubeadm_config.go b/bootstrapper/internal/kubernetes/k8sapi/kubeadm_config.go index fd5984e0c..033a1931d 100644 --- a/bootstrapper/internal/kubernetes/k8sapi/kubeadm_config.go +++ b/bootstrapper/internal/kubernetes/k8sapi/kubeadm_config.go @@ -12,7 +12,6 @@ import ( "github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubelet" "github.com/edgelesssys/constellation/v2/internal/constants" "github.com/edgelesssys/constellation/v2/internal/kubernetes" - "github.com/edgelesssys/constellation/v2/internal/versions" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubeletconf "k8s.io/kubelet/config/v1beta1" @@ -33,7 +32,7 @@ const ( type KubdeadmConfiguration struct{} // InitConfiguration returns a new init configuration. -func (c *KubdeadmConfiguration) InitConfiguration(externalCloudProvider bool, k8sVersion versions.ValidK8sVersion) KubeadmInitYAML { +func (c *KubdeadmConfiguration) InitConfiguration(externalCloudProvider bool, clusterVersion string) KubeadmInitYAML { var cloudProvider string if externalCloudProvider { cloudProvider = "external" @@ -63,7 +62,7 @@ func (c *KubdeadmConfiguration) InitConfiguration(externalCloudProvider bool, k8 APIVersion: kubeadm.SchemeGroupVersion.String(), }, // Target kubernetes version of the control plane. - KubernetesVersion: versions.VersionConfigs[k8sVersion].PatchVersion, + KubernetesVersion: clusterVersion, // necessary to be able to access the kubeapi server through localhost APIServer: kubeadm.APIServer{ ControlPlaneComponent: kubeadm.ControlPlaneComponent{ diff --git a/bootstrapper/internal/kubernetes/k8sapi/kubeadm_config_test.go b/bootstrapper/internal/kubernetes/k8sapi/kubeadm_config_test.go index 79e8495f9..66a0d3dd3 100644 --- a/bootstrapper/internal/kubernetes/k8sapi/kubeadm_config_test.go +++ b/bootstrapper/internal/kubernetes/k8sapi/kubeadm_config_test.go @@ -28,11 +28,11 @@ func TestInitConfiguration(t *testing.T) { config KubeadmInitYAML }{ "kubeadm init config can be created": { - config: kubeadmConfig.InitConfiguration(true, versions.Default), + config: kubeadmConfig.InitConfiguration(true, versions.VersionConfigs[versions.Default].ClusterVersion), }, "kubeadm init config with all fields can be created": { config: func() KubeadmInitYAML { - c := kubeadmConfig.InitConfiguration(true, versions.Default) + c := kubeadmConfig.InitConfiguration(true, versions.VersionConfigs[versions.Default].ClusterVersion) c.SetNodeIP("192.0.2.0") c.SetNodeName("node") c.SetProviderID("somecloudprovider://instance-id") @@ -65,8 +65,8 @@ func TestInitConfigurationKubeadmCompatibility(t *testing.T) { wantErr bool }{ "Kubeadm accepts version 'Latest'": { - config: kubeadmConfig.InitConfiguration(true, versions.Default), - expectedVersion: versions.VersionConfigs[versions.Default].PatchVersion, + config: kubeadmConfig.InitConfiguration(true, versions.VersionConfigs[versions.Default].ClusterVersion), + expectedVersion: versions.VersionConfigs[versions.Default].ClusterVersion, }, "Kubeadm receives incompatible version": { config: kubeadmConfig.InitConfiguration(true, "1.19"), diff --git a/bootstrapper/internal/kubernetes/kubernetes.go b/bootstrapper/internal/kubernetes/kubernetes.go index ae50ed1f9..e24323d8f 100644 --- a/bootstrapper/internal/kubernetes/kubernetes.go +++ b/bootstrapper/internal/kubernetes/kubernetes.go @@ -46,7 +46,7 @@ type configReader interface { // configurationProvider provides kubeadm init and join configuration. type configurationProvider interface { - InitConfiguration(externalCloudProvider bool, k8sVersion versions.ValidK8sVersion) k8sapi.KubeadmInitYAML + InitConfiguration(externalCloudProvider bool, k8sVersion string) k8sapi.KubeadmInitYAML JoinConfiguration(externalCloudProvider bool) k8sapi.KubeadmJoinYAML } @@ -92,11 +92,7 @@ func (k *KubeWrapper) InitCluster( enforceIDKeyDigest bool, idKeyDigest []byte, azureCVM bool, helmReleasesRaw []byte, conformanceMode bool, kubernetesComponents versions.ComponentVersions, log *logger.Logger, ) ([]byte, error) { - k8sVersion, err := versions.NewValidK8sVersion(versionString) - if err != nil { - return nil, err - } - log.With(zap.String("version", string(k8sVersion))).Infof("Installing Kubernetes components") + log.With(zap.String("version", versionString)).Infof("Installing Kubernetes components") if err := k.clusterUtil.InstallComponents(ctx, kubernetesComponents); err != nil { return nil, err } @@ -141,7 +137,7 @@ func (k *KubeWrapper) InitCluster( // Step 2: configure kubeadm init config ccmSupported := cloudprovider.FromString(k.cloudProvider) == cloudprovider.Azure || cloudprovider.FromString(k.cloudProvider) == cloudprovider.GCP - initConfig := k.configProvider.InitConfiguration(ccmSupported, k8sVersion) + initConfig := k.configProvider.InitConfiguration(ccmSupported, versionString) initConfig.SetNodeIP(nodeIP) initConfig.SetCertSANs([]string{nodeIP}) initConfig.SetNodeName(nodeName) @@ -171,7 +167,7 @@ func (k *KubeWrapper) InitCluster( } // Setup the K8s components ConfigMap. - k8sComponentsConfigMap, err := k.setupK8sComponentsConfigMap(ctx, kubernetesComponents) + k8sComponentsConfigMap, err := k.setupK8sComponentsConfigMap(ctx, kubernetesComponents, versionString) if err != nil { return nil, fmt.Errorf("failed to setup k8s version ConfigMap: %w", err) } @@ -323,7 +319,7 @@ func (k *KubeWrapper) GetKubeconfig() ([]byte, error) { // setupK8sComponentsConfigMap applies a ConfigMap (cf. server-side apply) to store the installed k8s components. // It returns the name of the ConfigMap. -func (k *KubeWrapper) setupK8sComponentsConfigMap(ctx context.Context, components versions.ComponentVersions) (string, error) { +func (k *KubeWrapper) setupK8sComponentsConfigMap(ctx context.Context, components versions.ComponentVersions, clusterVersion string) (string, error) { componentsMarshalled, err := json.Marshal(components) if err != nil { return "", fmt.Errorf("marshalling component versions: %w", err) @@ -342,7 +338,8 @@ func (k *KubeWrapper) setupK8sComponentsConfigMap(ctx context.Context, component Namespace: "kube-system", }, Data: map[string]string{ - constants.K8sComponentsFieldName: string(componentsMarshalled), + constants.ComponentsListKey: string(componentsMarshalled), + constants.K8sVersionFieldName: clusterVersion, }, } diff --git a/bootstrapper/internal/kubernetes/kubernetes_test.go b/bootstrapper/internal/kubernetes/kubernetes_test.go index c024320a2..63adda648 100644 --- a/bootstrapper/internal/kubernetes/kubernetes_test.go +++ b/bootstrapper/internal/kubernetes/kubernetes_test.go @@ -556,7 +556,7 @@ type stubConfigProvider struct { joinConfig k8sapi.KubeadmJoinYAML } -func (s *stubConfigProvider) InitConfiguration(_ bool, _ versions.ValidK8sVersion) k8sapi.KubeadmInitYAML { +func (s *stubConfigProvider) InitConfiguration(_ bool, _ string) k8sapi.KubeadmInitYAML { return s.initConfig } diff --git a/cli/internal/cmd/init.go b/cli/internal/cmd/init.go index 9b670f1a8..4d11ad01d 100644 --- a/cli/internal/cmd/init.go +++ b/cli/internal/cmd/init.go @@ -148,7 +148,7 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud KeyEncryptionKeyId: "", UseExistingKek: false, CloudServiceAccountUri: serviceAccURI, - KubernetesVersion: conf.KubernetesVersion, + KubernetesVersion: versions.VersionConfigs[k8sVersion].ClusterVersion, KubernetesComponents: versions.VersionConfigs[k8sVersion].KubernetesComponents.ToInitProto(), HelmDeployments: helmDeployments, EnforcedPcrs: conf.EnforcedPCRs(), diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 2821c47fd..7240e8259 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -113,8 +113,8 @@ const ( // AzureCVM is the name of the file indicating whether the cluster is expected to run on CVMs or not. AzureCVM = "azureCVM" - // K8sComponentsFieldName is the name of the of the key holding the configMap name that holds the components configuration. - K8sComponentsFieldName = "components" + // K8sVersionFieldName is the name of the of the key holding the wanted Kubernetes version. + K8sVersionFieldName = "cluster-version" // ComponentsListKey is the name of the key holding the list of components in the components configMap. ComponentsListKey = "components" diff --git a/internal/versions/versions.go b/internal/versions/versions.go index ac8f921db..12389c308 100644 --- a/internal/versions/versions.go +++ b/internal/versions/versions.go @@ -103,7 +103,7 @@ const ( // VersionConfigs holds download URLs for all required kubernetes components for every supported version. var VersionConfigs = map[ValidK8sVersion]KubernetesVersion{ V1_23: { - PatchVersion: "v1.23.15", // renovate:kubernetes-release + ClusterVersion: "v1.23.15", // renovate:kubernetes-release KubernetesComponents: ComponentVersions{ { URL: "https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz", // renovate:cni-plugins-release @@ -149,7 +149,7 @@ var VersionConfigs = map[ValidK8sVersion]KubernetesVersion{ ClusterAutoscalerImage: "registry.k8s.io/autoscaling/cluster-autoscaler:v1.23.1@sha256:cd2101ba67f3d6ec719f7792d4bdaa3a50e1b716f3a9ccee8931086496c655b7", // renovate:container }, V1_24: { - PatchVersion: "v1.24.9", // renovate:kubernetes-release + ClusterVersion: "v1.24.9", // renovate:kubernetes-release KubernetesComponents: ComponentVersions{ { URL: "https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz", // renovate:cni-plugins-release @@ -195,7 +195,7 @@ var VersionConfigs = map[ValidK8sVersion]KubernetesVersion{ ClusterAutoscalerImage: "registry.k8s.io/autoscaling/cluster-autoscaler:v1.24.0@sha256:5bd22353ae7f30c9abfaa08189281367ef47ea1b3d09eb13eb26bd13de241e72", // renovate:container }, V1_25: { - PatchVersion: "v1.25.5", // renovate:kubernetes-release + ClusterVersion: "v1.25.5", // renovate:kubernetes-release KubernetesComponents: ComponentVersions{ { URL: "https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz", // renovate:cni-plugins-release @@ -244,7 +244,7 @@ var VersionConfigs = map[ValidK8sVersion]KubernetesVersion{ ClusterAutoscalerImage: "registry.k8s.io/autoscaling/cluster-autoscaler:v1.25.0@sha256:f509ffab618dbd07d129b69ec56963aac7f61aaa792851206b54a2f0bbe046df", // renovate:container }, V1_26: { - PatchVersion: "v1.26.0", // renovate:kubernetes-release + ClusterVersion: "v1.26.0", // renovate:kubernetes-release KubernetesComponents: ComponentVersions{ { URL: "https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz", // renovate:cni-plugins-release @@ -296,7 +296,7 @@ var VersionConfigs = map[ValidK8sVersion]KubernetesVersion{ // KubernetesVersion bundles download URLs to all version-releated binaries necessary for installing/deploying a particular Kubernetes version. type KubernetesVersion struct { - PatchVersion string + ClusterVersion string KubernetesComponents ComponentVersions CloudControllerManagerImageAWS string // k8s version dependency. CloudControllerManagerImageGCP string // Using self-built image until resolved: https://github.com/kubernetes/cloud-provider-gcp/issues/289