mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
kubeadm: update unit tests to support dynamic version updates
Tests under /app and /test would fail if the current/minimum k8s version is dynamically populated from the version in the kubeadm binary. Adapt the tests to support that.
This commit is contained in:
parent
207ffa7bdc
commit
e3538edc22
@ -208,8 +208,8 @@ func TestConfigImagesListRunWithoutPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestConfigImagesListOutput(t *testing.T) {
|
func TestConfigImagesListOutput(t *testing.T) {
|
||||||
|
|
||||||
etcdVersion, ok := constants.SupportedEtcdVersion[uint8(dummyKubernetesVersion.Minor())]
|
etcdVersion, _, err := constants.EtcdSupportedVersion(constants.SupportedEtcdVersion, dummyKubernetesVersionStr)
|
||||||
if !ok {
|
if err != nil {
|
||||||
t.Fatalf("cannot determine etcd version for Kubernetes version %s", dummyKubernetesVersionStr)
|
t.Fatalf("cannot determine etcd version for Kubernetes version %s", dummyKubernetesVersionStr)
|
||||||
}
|
}
|
||||||
versionMapping := struct {
|
versionMapping := struct {
|
||||||
@ -218,7 +218,7 @@ func TestConfigImagesListOutput(t *testing.T) {
|
|||||||
PauseVersion string
|
PauseVersion string
|
||||||
CoreDNSVersion string
|
CoreDNSVersion string
|
||||||
}{
|
}{
|
||||||
EtcdVersion: etcdVersion,
|
EtcdVersion: etcdVersion.String(),
|
||||||
KubeVersion: "v" + dummyKubernetesVersionStr,
|
KubeVersion: "v" + dummyKubernetesVersionStr,
|
||||||
PauseVersion: constants.PauseVersion,
|
PauseVersion: constants.PauseVersion,
|
||||||
CoreDNSVersion: constants.CoreDNSVersion,
|
CoreDNSVersion: constants.CoreDNSVersion,
|
||||||
|
@ -85,7 +85,8 @@ spec:
|
|||||||
image: k8s.gcr.io/etcd:` + fakeCurrentEtcdVersion
|
image: k8s.gcr.io/etcd:` + fakeCurrentEtcdVersion
|
||||||
|
|
||||||
func getEtcdVersion(v *versionutil.Version) string {
|
func getEtcdVersion(v *versionutil.Version) string {
|
||||||
return constants.SupportedEtcdVersion[uint8(v.Minor())]
|
etcdVer, _, _ := constants.EtcdSupportedVersion(constants.SupportedEtcdVersion, v.String())
|
||||||
|
return etcdVer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
const fakeCurrentCoreDNSVersion = "1.0.6"
|
const fakeCurrentCoreDNSVersion = "1.0.6"
|
||||||
|
@ -76,7 +76,7 @@ func TestEnforceVersionPolicies(t *testing.T) {
|
|||||||
kubeletVersion: "v1.12.3",
|
kubeletVersion: "v1.12.3",
|
||||||
kubeadmVersion: "v1.12.3",
|
kubeadmVersion: "v1.12.3",
|
||||||
},
|
},
|
||||||
newK8sVersion: "v1.11.10",
|
newK8sVersion: "v1.10.10",
|
||||||
expectedMandatoryErrs: 1, // version must be higher than v1.12.0
|
expectedMandatoryErrs: 1, // version must be higher than v1.12.0
|
||||||
expectedSkippableErrs: 1, // can't upgrade old k8s with newer kubeadm
|
expectedSkippableErrs: 1, // can't upgrade old k8s with newer kubeadm
|
||||||
},
|
},
|
||||||
@ -85,9 +85,9 @@ func TestEnforceVersionPolicies(t *testing.T) {
|
|||||||
vg: &fakeVersionGetter{
|
vg: &fakeVersionGetter{
|
||||||
clusterVersion: "v1.11.3",
|
clusterVersion: "v1.11.3",
|
||||||
kubeletVersion: "v1.11.3",
|
kubeletVersion: "v1.11.3",
|
||||||
kubeadmVersion: constants.CurrentKubernetesVersion.String(),
|
kubeadmVersion: "v1.13.0",
|
||||||
},
|
},
|
||||||
newK8sVersion: constants.CurrentKubernetesVersion.String(),
|
newK8sVersion: "v1.13.0",
|
||||||
expectedMandatoryErrs: 1, // can't upgrade two minor versions
|
expectedMandatoryErrs: 1, // can't upgrade two minor versions
|
||||||
expectedSkippableErrs: 1, // kubelet <-> apiserver skew too large
|
expectedSkippableErrs: 1, // kubelet <-> apiserver skew too large
|
||||||
},
|
},
|
||||||
@ -124,11 +124,11 @@ func TestEnforceVersionPolicies(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "the maximum skew between the cluster version and the kubelet versions should be one minor version. This may be forced through though.",
|
name: "the maximum skew between the cluster version and the kubelet versions should be one minor version. This may be forced through though.",
|
||||||
vg: &fakeVersionGetter{
|
vg: &fakeVersionGetter{
|
||||||
clusterVersion: constants.MinimumControlPlaneVersion.WithPatch(3).String(),
|
clusterVersion: "v1.12.0",
|
||||||
kubeletVersion: "v1.12.8",
|
kubeletVersion: "v1.10.8",
|
||||||
kubeadmVersion: constants.CurrentKubernetesVersion.String(),
|
kubeadmVersion: "v1.12.0",
|
||||||
},
|
},
|
||||||
newK8sVersion: constants.CurrentKubernetesVersion.String(),
|
newK8sVersion: "v1.12.0",
|
||||||
expectedSkippableErrs: 1,
|
expectedSkippableErrs: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -793,7 +793,7 @@ func TestKubeletVersionCheck(t *testing.T) {
|
|||||||
expectWarnings bool
|
expectWarnings bool
|
||||||
}{
|
}{
|
||||||
{"v" + constants.CurrentKubernetesVersion.WithPatch(2).String(), "", false, false}, // check minimally supported version when there is no information about control plane
|
{"v" + constants.CurrentKubernetesVersion.WithPatch(2).String(), "", false, false}, // check minimally supported version when there is no information about control plane
|
||||||
{"v1.11.3", "v1.11.8", true, false}, // too old kubelet (older than kubeadmconstants.MinimumKubeletVersion), should fail.
|
{"v1.1.0", "v1.11.8", true, false}, // too old kubelet, should fail.
|
||||||
{"v" + constants.MinimumKubeletVersion.String(), constants.MinimumControlPlaneVersion.WithPatch(5).String(), false, false}, // kubelet within same major.minor as control plane
|
{"v" + constants.MinimumKubeletVersion.String(), constants.MinimumControlPlaneVersion.WithPatch(5).String(), false, false}, // kubelet within same major.minor as control plane
|
||||||
{"v" + constants.MinimumKubeletVersion.WithPatch(5).String(), constants.MinimumControlPlaneVersion.WithPatch(1).String(), false, false}, // kubelet is newer, but still within same major.minor as control plane
|
{"v" + constants.MinimumKubeletVersion.WithPatch(5).String(), constants.MinimumControlPlaneVersion.WithPatch(1).String(), false, false}, // kubelet is newer, but still within same major.minor as control plane
|
||||||
{"v" + constants.MinimumKubeletVersion.String(), constants.CurrentKubernetesVersion.WithPatch(1).String(), false, false}, // kubelet is lower than control plane, but newer than minimally supported
|
{"v" + constants.MinimumKubeletVersion.String(), constants.CurrentKubernetesVersion.WithPatch(1).String(), false, false}, // kubelet is lower than control plane, but newer than minimally supported
|
||||||
|
@ -19,9 +19,10 @@ package kubeadm
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/apimachinery/pkg/util/version"
|
||||||
|
|
||||||
"github.com/lithammer/dedent"
|
"github.com/lithammer/dedent"
|
||||||
)
|
)
|
||||||
@ -37,6 +38,16 @@ func runKubeadmInit(args ...string) (string, string, int, error) {
|
|||||||
return RunCmd(kubeadmPath, kubeadmArgs...)
|
return RunCmd(kubeadmPath, kubeadmArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getKubeadmVersion() *version.Version {
|
||||||
|
kubeadmPath := getKubeadmPath()
|
||||||
|
kubeadmArgs := []string{"version", "-o=short"}
|
||||||
|
out, _, _, err := RunCmd(kubeadmPath, kubeadmArgs...)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("could not run 'kubeadm version -o=short': %v", err))
|
||||||
|
}
|
||||||
|
return version.MustParseSemantic(strings.TrimSpace(out))
|
||||||
|
}
|
||||||
|
|
||||||
func TestCmdInitToken(t *testing.T) {
|
func TestCmdInitToken(t *testing.T) {
|
||||||
initTest := []struct {
|
initTest := []struct {
|
||||||
name string
|
name string
|
||||||
@ -94,7 +105,7 @@ func TestCmdInitKubernetesVersion(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid version is accepted",
|
name: "valid version is accepted",
|
||||||
args: "--kubernetes-version=" + constants.CurrentKubernetesVersion.String(),
|
args: "--kubernetes-version=" + getKubeadmVersion().String(),
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user