mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
kubeadm: fix unit tests for v1beta1 removal
This commit is contained in:
parent
02b455b565
commit
c2bddf3998
@ -379,14 +379,14 @@ func TestGenCSRConfig(t *testing.T) {
|
||||
// A minimal kubeadm config with just enough values to avoid triggering
|
||||
// auto-detection of config values at runtime.
|
||||
var kubeadmConfig = `
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: InitConfiguration
|
||||
localAPIEndpoint:
|
||||
advertiseAddress: 192.0.2.1
|
||||
nodeRegistration:
|
||||
criSocket: /path/to/dockershim.sock
|
||||
---
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
certificatesDir: /custom/config/certificates-dir
|
||||
kubernetesVersion: ` + kubeadmconstants.MinimumControlPlaneVersion.String()
|
||||
|
@ -81,7 +81,7 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
|
||||
constants.CurrentKubernetesVersion.String(),
|
||||
},
|
||||
configContents: []byte(dedent.Dedent(fmt.Sprintf(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: %s
|
||||
`, constants.CurrentKubernetesVersion))),
|
||||
@ -93,7 +93,7 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
|
||||
"coredns",
|
||||
},
|
||||
configContents: []byte(dedent.Dedent(fmt.Sprintf(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: %s
|
||||
`, constants.MinimumControlPlaneVersion))),
|
||||
@ -384,7 +384,7 @@ func TestImagesPull(t *testing.T) {
|
||||
func TestMigrate(t *testing.T) {
|
||||
cfg := []byte(dedent.Dedent(`
|
||||
# This is intentionally testing an old API version. Sometimes this may be the latest version (if no old configs are supported).
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: InitConfiguration
|
||||
`))
|
||||
configFile, cleanup := tempConfig(t, cfg)
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
|
||||
const (
|
||||
testInitConfig = `---
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: InitConfiguration
|
||||
localAPIEndpoint:
|
||||
advertiseAddress: "1.2.3.4"
|
||||
@ -41,7 +41,7 @@ nodeRegistration:
|
||||
- c
|
||||
- d
|
||||
---
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
controlPlaneEndpoint: "3.4.5.6"
|
||||
`
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
testJoinConfig = `apiVersion: kubeadm.k8s.io/v1beta2
|
||||
testJoinConfig = `apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: JoinConfiguration
|
||||
discovery:
|
||||
bootstrapToken:
|
||||
|
@ -43,7 +43,7 @@ func TestRunDiff(t *testing.T) {
|
||||
currentVersion := "v" + constants.CurrentKubernetesVersion.String()
|
||||
|
||||
// create a temporary file with valid ClusterConfiguration
|
||||
testUpgradeDiffConfigContents := []byte("apiVersion: kubeadm.k8s.io/v1beta2\n" +
|
||||
testUpgradeDiffConfigContents := []byte("apiVersion: kubeadm.k8s.io/v1beta3\n" +
|
||||
"kind: ClusterConfiguration\n" +
|
||||
"kubernetesVersion: " + currentVersion)
|
||||
testUpgradeDiffConfig, err := createTestRunDiffFile(testUpgradeDiffConfigContents)
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
clientsetfake "k8s.io/client-go/kubernetes/fake"
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
|
||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
|
||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||
outputapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/output"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||
@ -206,7 +206,7 @@ var (
|
||||
yaml: dedent.Dedent(`
|
||||
apiServer:
|
||||
timeoutForControlPlane: 4m
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
certificatesDir: /etc/kubernetes/pki
|
||||
clusterName: LeCluster
|
||||
controllerManager: {}
|
||||
@ -277,7 +277,7 @@ func TestConfigBaseMarshal(t *testing.T) {
|
||||
got := strings.TrimSpace(string(b))
|
||||
expected := strings.TrimSpace(dedent.Dedent(`
|
||||
apiServer: {}
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
clusterName: LeCluster
|
||||
controllerManager: {}
|
||||
dns:
|
||||
@ -327,7 +327,7 @@ func TestConfigBaseUnmarshal(t *testing.T) {
|
||||
func TestGeneratedConfigFromCluster(t *testing.T) {
|
||||
fakeKnownContext(func() {
|
||||
testYAML := dedent.Dedent(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
`)
|
||||
testYAMLHash := fmt.Sprintf("sha256:%x", sha256.Sum256([]byte(testYAML)))
|
||||
@ -406,7 +406,7 @@ func runClusterConfigFromTest(t *testing.T, perform func(t *testing.T, in string
|
||||
{
|
||||
name: "Unknown kind returns an error",
|
||||
in: dedent.Dedent(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: Configuration
|
||||
`),
|
||||
expectErr: true,
|
||||
|
@ -55,7 +55,7 @@ const (
|
||||
waitForPodsWithLabel = "wait-for-pods-with-label"
|
||||
|
||||
testConfiguration = `
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: InitConfiguration
|
||||
nodeRegistration:
|
||||
name: foo
|
||||
@ -67,7 +67,7 @@ bootstrapTokens:
|
||||
- token: ce3aa5.5ec8455bb76b379f
|
||||
ttl: 24h
|
||||
---
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
|
||||
apiServer:
|
||||
|
@ -46,15 +46,6 @@ var k8sVersionString = kubeadmconstants.MinimumControlPlaneVersion.String()
|
||||
var k8sVersion = version.MustParseGeneric(k8sVersionString)
|
||||
var nodeName = "mynode"
|
||||
var cfgFiles = map[string][]byte{
|
||||
"InitConfiguration_v1beta1": []byte(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
kind: InitConfiguration
|
||||
`),
|
||||
"ClusterConfiguration_v1beta1": []byte(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: ` + k8sVersionString + `
|
||||
`),
|
||||
"InitConfiguration_v1beta2": []byte(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: InitConfiguration
|
||||
@ -63,6 +54,15 @@ kind: InitConfiguration
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: ` + k8sVersionString + `
|
||||
`),
|
||||
"InitConfiguration_v1beta3": []byte(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: InitConfiguration
|
||||
`),
|
||||
"ClusterConfiguration_v1beta3": []byte(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: ` + k8sVersionString + `
|
||||
`),
|
||||
"Kube-proxy_componentconfig": []byte(`
|
||||
apiVersion: kubeproxy.config.k8s.io/v1alpha1
|
||||
@ -541,83 +541,6 @@ func TestGetInitConfigurationFromCluster(t *testing.T) {
|
||||
},
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
name: "valid v1beta1 - new control plane == false", // InitConfiguration composed with data from different places, with also node specific information from ClusterStatus and node
|
||||
staticPods: []testresources.FakeStaticPod{
|
||||
{
|
||||
NodeName: nodeName,
|
||||
Component: kubeadmconstants.KubeAPIServer,
|
||||
Annotations: map[string]string{
|
||||
kubeadmconstants.KubeAPIServerAdvertiseAddressEndpointAnnotationKey: "1.2.3.4:1234",
|
||||
},
|
||||
},
|
||||
},
|
||||
configMaps: []testresources.FakeConfigMap{
|
||||
{
|
||||
Name: kubeadmconstants.KubeadmConfigConfigMap, // ClusterConfiguration from kubeadm-config.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.ClusterConfigurationConfigMapKey: string(cfgFiles["ClusterConfiguration_v1beta1"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: kubeadmconstants.KubeProxyConfigMap, // Kube-proxy component config from corresponding ConfigMap.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.KubeProxyConfigMapKey: string(cfgFiles["Kube-proxy_componentconfig"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: kubeadmconstants.GetKubeletConfigMapName(k8sVersion), // Kubelet component config from corresponding ConfigMap.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.KubeletBaseConfigurationConfigMapKey: string(cfgFiles["Kubelet_componentconfig"]),
|
||||
},
|
||||
},
|
||||
},
|
||||
fileContents: kubeletConfFiles["configWithEmbeddedCert"],
|
||||
node: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: nodeName,
|
||||
Annotations: map[string]string{
|
||||
kubeadmconstants.AnnotationKubeadmCRISocket: "myCRIsocket",
|
||||
},
|
||||
},
|
||||
Spec: v1.NodeSpec{
|
||||
Taints: []v1.Taint{kubeadmconstants.OldControlPlaneTaint},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid v1beta1 - new control plane == true", // InitConfiguration composed with data from different places, without node specific information
|
||||
staticPods: []testresources.FakeStaticPod{
|
||||
{
|
||||
NodeName: nodeName,
|
||||
Component: kubeadmconstants.KubeAPIServer,
|
||||
Annotations: map[string]string{
|
||||
kubeadmconstants.KubeAPIServerAdvertiseAddressEndpointAnnotationKey: "1.2.3.4:1234",
|
||||
},
|
||||
},
|
||||
},
|
||||
configMaps: []testresources.FakeConfigMap{
|
||||
{
|
||||
Name: kubeadmconstants.KubeadmConfigConfigMap, // ClusterConfiguration from kubeadm-config.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.ClusterConfigurationConfigMapKey: string(cfgFiles["ClusterConfiguration_v1beta1"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: kubeadmconstants.KubeProxyConfigMap, // Kube-proxy component config from corresponding ConfigMap.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.KubeProxyConfigMapKey: string(cfgFiles["Kube-proxy_componentconfig"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: kubeadmconstants.GetKubeletConfigMapName(k8sVersion), // Kubelet component config from corresponding ConfigMap.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.KubeletBaseConfigurationConfigMapKey: string(cfgFiles["Kubelet_componentconfig"]),
|
||||
},
|
||||
},
|
||||
},
|
||||
newControlPlane: true,
|
||||
},
|
||||
{
|
||||
name: "valid v1beta2 - new control plane == false", // InitConfiguration composed with data from different places, with also node specific information from ClusterStatus and node
|
||||
staticPods: []testresources.FakeStaticPod{
|
||||
@ -695,6 +618,83 @@ func TestGetInitConfigurationFromCluster(t *testing.T) {
|
||||
},
|
||||
newControlPlane: true,
|
||||
},
|
||||
{
|
||||
name: "valid v1beta3 - new control plane == false", // InitConfiguration composed with data from different places, with also node specific information from ClusterStatus and node
|
||||
staticPods: []testresources.FakeStaticPod{
|
||||
{
|
||||
NodeName: nodeName,
|
||||
Component: kubeadmconstants.KubeAPIServer,
|
||||
Annotations: map[string]string{
|
||||
kubeadmconstants.KubeAPIServerAdvertiseAddressEndpointAnnotationKey: "1.2.3.4:1234",
|
||||
},
|
||||
},
|
||||
},
|
||||
configMaps: []testresources.FakeConfigMap{
|
||||
{
|
||||
Name: kubeadmconstants.KubeadmConfigConfigMap, // ClusterConfiguration from kubeadm-config.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.ClusterConfigurationConfigMapKey: string(cfgFiles["ClusterConfiguration_v1beta3"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: kubeadmconstants.KubeProxyConfigMap, // Kube-proxy component config from corresponding ConfigMap.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.KubeProxyConfigMapKey: string(cfgFiles["Kube-proxy_componentconfig"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: kubeadmconstants.GetKubeletConfigMapName(k8sVersion), // Kubelet component config from corresponding ConfigMap.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.KubeletBaseConfigurationConfigMapKey: string(cfgFiles["Kubelet_componentconfig"]),
|
||||
},
|
||||
},
|
||||
},
|
||||
fileContents: kubeletConfFiles["configWithEmbeddedCert"],
|
||||
node: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: nodeName,
|
||||
Annotations: map[string]string{
|
||||
kubeadmconstants.AnnotationKubeadmCRISocket: "myCRIsocket",
|
||||
},
|
||||
},
|
||||
Spec: v1.NodeSpec{
|
||||
Taints: []v1.Taint{kubeadmconstants.OldControlPlaneTaint},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid v1beta3 - new control plane == true", // InitConfiguration composed with data from different places, without node specific information
|
||||
staticPods: []testresources.FakeStaticPod{
|
||||
{
|
||||
NodeName: nodeName,
|
||||
Component: kubeadmconstants.KubeAPIServer,
|
||||
Annotations: map[string]string{
|
||||
kubeadmconstants.KubeAPIServerAdvertiseAddressEndpointAnnotationKey: "1.2.3.4:1234",
|
||||
},
|
||||
},
|
||||
},
|
||||
configMaps: []testresources.FakeConfigMap{
|
||||
{
|
||||
Name: kubeadmconstants.KubeadmConfigConfigMap, // ClusterConfiguration from kubeadm-config.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.ClusterConfigurationConfigMapKey: string(cfgFiles["ClusterConfiguration_v1beta3"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: kubeadmconstants.KubeProxyConfigMap, // Kube-proxy component config from corresponding ConfigMap.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.KubeProxyConfigMapKey: string(cfgFiles["Kube-proxy_componentconfig"]),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: kubeadmconstants.GetKubeletConfigMapName(k8sVersion), // Kubelet component config from corresponding ConfigMap.
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.KubeletBaseConfigurationConfigMapKey: string(cfgFiles["Kubelet_componentconfig"]),
|
||||
},
|
||||
},
|
||||
},
|
||||
newControlPlane: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, rt := range tests {
|
||||
@ -773,17 +773,6 @@ func TestGetGetClusterStatus(t *testing.T) {
|
||||
{
|
||||
name: "invalid missing config map",
|
||||
},
|
||||
{
|
||||
name: "valid v1beta1",
|
||||
configMaps: []testresources.FakeConfigMap{
|
||||
{
|
||||
Name: kubeadmconstants.KubeadmConfigConfigMap,
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.ClusterStatusConfigMapKey: string(cfgFiles["ClusterStatus_v1beta1"]),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid v1beta2",
|
||||
configMaps: []testresources.FakeConfigMap{
|
||||
@ -795,6 +784,17 @@ func TestGetGetClusterStatus(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid v1beta3",
|
||||
configMaps: []testresources.FakeConfigMap{
|
||||
{
|
||||
Name: kubeadmconstants.KubeadmConfigConfigMap,
|
||||
Data: map[string]string{
|
||||
kubeadmconstants.ClusterStatusConfigMapKey: string(cfgFiles["ClusterStatus_v1beta3"]),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid missing ClusterStatusConfigMapKey in the config map",
|
||||
configMaps: []testresources.FakeConfigMap{
|
||||
|
@ -56,16 +56,16 @@ func validateSupportedVersion(gv schema.GroupVersion, allowDeprecated bool) erro
|
||||
// v1.13: v1alpha3 read-only, writes only v1beta1 config. Errors if the user tries to use v1alpha1 or v1alpha2
|
||||
// v1.14: v1alpha3 convert only, writes only v1beta1 config. Errors if the user tries to use v1alpha1 or v1alpha2
|
||||
// v1.15: v1beta1 read-only, writes only v1beta2 config. Errors if the user tries to use v1alpha1, v1alpha2 or v1alpha3
|
||||
// v1.22: v1beta2 read-only, writes only v1beta3 config. Errors if the user tries to use v1beta1 and older
|
||||
oldKnownAPIVersions := map[string]string{
|
||||
"kubeadm.k8s.io/v1alpha1": "v1.11",
|
||||
"kubeadm.k8s.io/v1alpha2": "v1.12",
|
||||
"kubeadm.k8s.io/v1alpha3": "v1.14",
|
||||
"kubeadm.k8s.io/v1beta1": "v1.15",
|
||||
}
|
||||
|
||||
// Deprecated API versions are supported by us, but can only be used for migration.
|
||||
deprecatedAPIVersions := map[string]struct{}{
|
||||
"kubeadm.k8s.io/v1beta1": {},
|
||||
}
|
||||
deprecatedAPIVersions := map[string]struct{}{}
|
||||
|
||||
gvString := gv.String()
|
||||
|
||||
|
@ -57,21 +57,12 @@ func TestValidateSupportedVersion(t *testing.T) {
|
||||
},
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
gv: schema.GroupVersion{
|
||||
Group: KubeadmGroupName,
|
||||
Version: "v1alpha3",
|
||||
},
|
||||
allowDeprecated: true,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
gv: schema.GroupVersion{
|
||||
Group: KubeadmGroupName,
|
||||
Version: "v1beta1",
|
||||
},
|
||||
allowDeprecated: true,
|
||||
expectedErr: true,
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
gv: schema.GroupVersion{
|
||||
@ -79,6 +70,12 @@ func TestValidateSupportedVersion(t *testing.T) {
|
||||
Version: "v1beta2",
|
||||
},
|
||||
},
|
||||
{
|
||||
gv: schema.GroupVersion{
|
||||
Group: KubeadmGroupName,
|
||||
Version: "v1beta3",
|
||||
},
|
||||
},
|
||||
{
|
||||
gv: schema.GroupVersion{
|
||||
Group: "foo.k8s.io",
|
||||
@ -213,7 +210,7 @@ func TestMigrateOldConfigFromFile(t *testing.T) {
|
||||
{
|
||||
desc: "bad config produces error",
|
||||
oldCfg: dedent.Dedent(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
`),
|
||||
expectErr: true,
|
||||
},
|
||||
@ -341,13 +338,13 @@ func TestMigrateOldConfigFromFile(t *testing.T) {
|
||||
{
|
||||
desc: "component configs are not migrated",
|
||||
oldCfg: dedent.Dedent(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: InitConfiguration
|
||||
---
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: ClusterConfiguration
|
||||
---
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: JoinConfiguration
|
||||
discovery:
|
||||
bootstrapToken:
|
||||
|
@ -23,9 +23,9 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
|
||||
kubeadmapiv1beta3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
@ -44,23 +44,6 @@ func TestLoadInitConfigurationFromFile(t *testing.T) {
|
||||
fileContents []byte
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
name: "v1beta1.partial1",
|
||||
fileContents: cfgFiles["InitConfiguration_v1beta1"],
|
||||
},
|
||||
{
|
||||
name: "v1beta1.partial2",
|
||||
fileContents: cfgFiles["ClusterConfiguration_v1beta1"],
|
||||
},
|
||||
{
|
||||
name: "v1beta1.full",
|
||||
fileContents: bytes.Join([][]byte{
|
||||
cfgFiles["InitConfiguration_v1beta1"],
|
||||
cfgFiles["ClusterConfiguration_v1beta1"],
|
||||
cfgFiles["Kube-proxy_componentconfig"],
|
||||
cfgFiles["Kubelet_componentconfig"],
|
||||
}, []byte(constants.YAMLDocumentSeparator)),
|
||||
},
|
||||
{
|
||||
name: "v1beta2.partial1",
|
||||
fileContents: cfgFiles["InitConfiguration_v1beta2"],
|
||||
@ -78,6 +61,23 @@ func TestLoadInitConfigurationFromFile(t *testing.T) {
|
||||
cfgFiles["Kubelet_componentconfig"],
|
||||
}, []byte(constants.YAMLDocumentSeparator)),
|
||||
},
|
||||
{
|
||||
name: "v1beta3.partial1",
|
||||
fileContents: cfgFiles["InitConfiguration_v1beta3"],
|
||||
},
|
||||
{
|
||||
name: "v1beta3.partial2",
|
||||
fileContents: cfgFiles["ClusterConfiguration_v1beta3"],
|
||||
},
|
||||
{
|
||||
name: "v1beta3.full",
|
||||
fileContents: bytes.Join([][]byte{
|
||||
cfgFiles["InitConfiguration_v1beta3"],
|
||||
cfgFiles["ClusterConfiguration_v1beta3"],
|
||||
cfgFiles["Kube-proxy_componentconfig"],
|
||||
cfgFiles["Kubelet_componentconfig"],
|
||||
}, []byte(constants.YAMLDocumentSeparator)),
|
||||
},
|
||||
}
|
||||
|
||||
for _, rt := range tests {
|
||||
@ -111,14 +111,14 @@ func TestLoadInitConfigurationFromFile(t *testing.T) {
|
||||
func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
cfg kubeadmapiv1beta2.InitConfiguration
|
||||
cfg kubeadmapiv1beta3.InitConfiguration
|
||||
expectedTaintCnt int
|
||||
}{
|
||||
{
|
||||
desc: "Uninitialized nodeRegistration field produces a single taint (the master one)",
|
||||
cfg: kubeadmapiv1beta2.InitConfiguration{
|
||||
cfg: kubeadmapiv1beta3.InitConfiguration{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "kubeadm.k8s.io/v1beta2",
|
||||
APIVersion: "kubeadm.k8s.io/v1beta3",
|
||||
Kind: constants.InitConfigurationKind,
|
||||
},
|
||||
},
|
||||
@ -126,23 +126,23 @@ func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Uninitialized taints field produces a single taint (the master one)",
|
||||
cfg: kubeadmapiv1beta2.InitConfiguration{
|
||||
cfg: kubeadmapiv1beta3.InitConfiguration{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "kubeadm.k8s.io/v1beta2",
|
||||
APIVersion: "kubeadm.k8s.io/v1beta3",
|
||||
Kind: constants.InitConfigurationKind,
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1beta2.NodeRegistrationOptions{},
|
||||
NodeRegistration: kubeadmapiv1beta3.NodeRegistrationOptions{},
|
||||
},
|
||||
expectedTaintCnt: 1,
|
||||
},
|
||||
{
|
||||
desc: "Forsing taints to an empty slice produces no taints",
|
||||
cfg: kubeadmapiv1beta2.InitConfiguration{
|
||||
cfg: kubeadmapiv1beta3.InitConfiguration{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "kubeadm.k8s.io/v1beta2",
|
||||
APIVersion: "kubeadm.k8s.io/v1beta3",
|
||||
Kind: constants.InitConfigurationKind,
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1beta2.NodeRegistrationOptions{
|
||||
NodeRegistration: kubeadmapiv1beta3.NodeRegistrationOptions{
|
||||
Taints: []v1.Taint{},
|
||||
},
|
||||
},
|
||||
@ -150,12 +150,12 @@ func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "Custom taints are used",
|
||||
cfg: kubeadmapiv1beta2.InitConfiguration{
|
||||
cfg: kubeadmapiv1beta3.InitConfiguration{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "kubeadm.k8s.io/v1beta2",
|
||||
APIVersion: "kubeadm.k8s.io/v1beta3",
|
||||
Kind: constants.InitConfigurationKind,
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1beta2.NodeRegistrationOptions{
|
||||
NodeRegistration: kubeadmapiv1beta3.NodeRegistrationOptions{
|
||||
Taints: []v1.Taint{
|
||||
{Key: "taint1"},
|
||||
{Key: "taint2"},
|
||||
|
@ -44,17 +44,17 @@ func TestLoadJoinConfigurationFromFile(t *testing.T) {
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "Invalid v1beta1 causes error",
|
||||
name: "Invalid v1beta2 causes error",
|
||||
fileContents: dedent.Dedent(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: JoinConfiguration
|
||||
`),
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid v1beta1 is loaded",
|
||||
name: "valid v1beta2 is loaded",
|
||||
fileContents: dedent.Dedent(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta1
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: JoinConfiguration
|
||||
caCertPath: /etc/kubernetes/pki/ca.crt
|
||||
discovery:
|
||||
@ -67,17 +67,17 @@ func TestLoadJoinConfigurationFromFile(t *testing.T) {
|
||||
`),
|
||||
},
|
||||
{
|
||||
name: "Invalid v1beta2 causes error",
|
||||
name: "Invalid v1beta3 causes error",
|
||||
fileContents: dedent.Dedent(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: JoinConfiguration
|
||||
`),
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid v1beta2 is loaded",
|
||||
name: "valid v1beta3 is loaded",
|
||||
fileContents: dedent.Dedent(`
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: JoinConfiguration
|
||||
caCertPath: /etc/kubernetes/pki/ca.crt
|
||||
discovery:
|
||||
|
@ -137,28 +137,13 @@ func TestCmdInitConfig(t *testing.T) {
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "can't load old v1alpha1 config",
|
||||
args: "--config=testdata/init/v1alpha1.yaml",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "can't load old v1alpha2 config",
|
||||
args: "--config=testdata/init/v1alpha2.yaml",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "can't load old v1alpha3 config",
|
||||
args: "--config=testdata/init/v1alpha3.yaml",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "can load v1beta1 config",
|
||||
name: "can't load v1beta1 config",
|
||||
args: "--config=testdata/init/v1beta1.yaml",
|
||||
expected: true,
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "don't allow mixed arguments v1beta1",
|
||||
args: "--kubernetes-version=1.11.0 --config=testdata/init/v1beta1.yaml",
|
||||
name: "don't allow mixed arguments v1beta2",
|
||||
args: "--kubernetes-version=1.11.0 --config=testdata/init/v1beta2.yaml",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
@ -167,8 +152,13 @@ func TestCmdInitConfig(t *testing.T) {
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "don't allow mixed arguments v1beta2",
|
||||
args: "--kubernetes-version=1.11.0 --config=testdata/init/v1beta2.yaml",
|
||||
name: "can load v1beta3 config",
|
||||
args: "--config=testdata/init/v1beta3.yaml",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "don't allow mixed arguments v1beta3",
|
||||
args: "--kubernetes-version=1.11.0 --config=testdata/init/v1beta3.yaml",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
---
|
||||
apiVersion: kubelet.config.k8s.io/v1beta1
|
||||
|
@ -1,4 +1,4 @@
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: ClusterConfiguration
|
||||
---
|
||||
apiVersion: kubelet.config.k8s.io/v1alpha1
|
||||
|
@ -1,2 +0,0 @@
|
||||
apiVersion: kubeadm.k8s.io/v1alpha1
|
||||
kind: MasterConfiguration
|
@ -1,2 +0,0 @@
|
||||
apiVersion: kubeadm.k8s.io/v1alpha2
|
||||
kind: MasterConfiguration
|
@ -1,2 +0,0 @@
|
||||
apiVersion: kubeadm.k8s.io/v1alpha3
|
||||
kind: InitConfiguration
|
2
cmd/kubeadm/test/cmd/testdata/init/v1beta3.yaml
vendored
Normal file
2
cmd/kubeadm/test/cmd/testdata/init/v1beta3.yaml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: InitConfiguration
|
Loading…
Reference in New Issue
Block a user