mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
Merge pull request #117614 from chendave/multi_cri
kubeadm: fix unit test failure on node with multiple cri endpoints
This commit is contained in:
commit
9924dc65b7
@ -82,10 +82,14 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
|
||||
constants.CurrentKubernetesVersion.String(),
|
||||
},
|
||||
configContents: []byte(dedent.Dedent(fmt.Sprintf(`
|
||||
apiVersion: %s
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: %s
|
||||
`, kubeadmapiv1.SchemeGroupVersion.String(), constants.CurrentKubernetesVersion))),
|
||||
apiVersion: %s
|
||||
kind: InitConfiguration
|
||||
nodeRegistration:
|
||||
criSocket: %s
|
||||
---
|
||||
apiVersion: %[1]s
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: %[3]s`, kubeadmapiv1.SchemeGroupVersion.String(), constants.UnknownCRISocket, constants.CurrentKubernetesVersion))),
|
||||
},
|
||||
{
|
||||
name: "use coredns",
|
||||
@ -94,10 +98,14 @@ func TestImagesListRunWithCustomConfigPath(t *testing.T) {
|
||||
"coredns",
|
||||
},
|
||||
configContents: []byte(dedent.Dedent(fmt.Sprintf(`
|
||||
apiVersion: %s
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: %s
|
||||
`, kubeadmapiv1.SchemeGroupVersion.String(), constants.MinimumControlPlaneVersion))),
|
||||
apiVersion: %s
|
||||
kind: InitConfiguration
|
||||
nodeRegistration:
|
||||
criSocket: %s
|
||||
---
|
||||
apiVersion: %[1]s
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: %[3]s`, kubeadmapiv1.SchemeGroupVersion.String(), constants.UnknownCRISocket, constants.MinimumControlPlaneVersion))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -384,10 +392,12 @@ func TestImagesPull(t *testing.T) {
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
cfg := []byte(dedent.Dedent(fmt.Sprintf(`
|
||||
# This is intentionally testing an old API version. Sometimes this may be the latest version (if no old configs are supported).
|
||||
apiVersion: %s
|
||||
kind: InitConfiguration
|
||||
`, kubeadmapiv1.SchemeGroupVersion.String())))
|
||||
# This is intentionally testing an old API version. Sometimes this may be the latest version (if no old configs are supported).
|
||||
apiVersion: %s
|
||||
kind: InitConfiguration
|
||||
nodeRegistration:
|
||||
criSocket: %s
|
||||
`, kubeadmapiv1.SchemeGroupVersion.String(), constants.UnknownCRISocket)))
|
||||
configFile, cleanup := tempConfig(t, cfg)
|
||||
defer cleanup()
|
||||
|
||||
|
@ -81,7 +81,7 @@ func TestNewInitData(t *testing.T) {
|
||||
}{
|
||||
// Init data passed using flags
|
||||
{
|
||||
name: "pass without any flag (use defaults)",
|
||||
name: "pass without any flag except the cri socket (use defaults)",
|
||||
},
|
||||
{
|
||||
name: "fail if unknown feature gates flag are passed",
|
||||
@ -190,6 +190,15 @@ func TestNewInitData(t *testing.T) {
|
||||
initOptions := newInitOptions()
|
||||
cmd := newCmdInit(nil, initOptions)
|
||||
|
||||
// set the cri socket here, otherwise the testcase might fail if is run on the node with multiple
|
||||
// cri endpoints configured, the failure caused by this is normally not an expected failure.
|
||||
if tc.flags == nil {
|
||||
tc.flags = make(map[string]string)
|
||||
}
|
||||
// set `cri-socket` only if `CfgPath` is not set
|
||||
if _, okay := tc.flags[options.CfgPath]; !okay {
|
||||
tc.flags[options.NodeCRISocket] = constants.UnknownCRISocket
|
||||
}
|
||||
// sets cmd flags (that will be reflected on the init options)
|
||||
for f, v := range tc.flags {
|
||||
cmd.Flags().Set(f, v)
|
||||
|
@ -35,6 +35,7 @@ import (
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||
)
|
||||
|
||||
@ -319,6 +320,15 @@ func TestNewJoinData(t *testing.T) {
|
||||
klog.LogToStderr(false)
|
||||
defer klog.LogToStderr(true)
|
||||
|
||||
// set the cri socket here, otherwise the testcase might fail if is run on the node with multiple
|
||||
// cri endpoints configured, the failure caused by this is normally not an expected failure.
|
||||
if tc.flags == nil {
|
||||
tc.flags = make(map[string]string)
|
||||
}
|
||||
// set `cri-socket` only if `CfgPath` is not set
|
||||
if _, okay := tc.flags[options.CfgPath]; !okay {
|
||||
tc.flags[options.NodeCRISocket] = constants.UnknownCRISocket
|
||||
}
|
||||
// sets cmd flags (that will be reflected on the join options)
|
||||
for f, v := range tc.flags {
|
||||
cmd.Flags().Set(f, v)
|
||||
|
@ -45,6 +45,9 @@ func generateTestKubeadmConfig(dir, id, certDir, clusterName string) (string, er
|
||||
AdvertiseAddress: "1.2.3.4",
|
||||
BindPort: 1234,
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1.NodeRegistrationOptions{
|
||||
CRISocket: kubeadmconstants.UnknownCRISocket,
|
||||
},
|
||||
}
|
||||
clusterCfg := kubeadmapiv1.ClusterConfiguration{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
|
@ -36,6 +36,7 @@ import (
|
||||
outputapischeme "k8s.io/kubernetes/cmd/kubeadm/app/apis/output/scheme"
|
||||
outputapiv1alpha2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/output/v1alpha2"
|
||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/output"
|
||||
)
|
||||
|
||||
@ -172,6 +173,9 @@ func TestRunCreateToken(t *testing.T) {
|
||||
Groups: tc.extraGroups,
|
||||
},
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1.NodeRegistrationOptions{
|
||||
CRISocket: constants.UnknownCRISocket,
|
||||
},
|
||||
}
|
||||
|
||||
err = RunCreateToken(&buf, fakeClient, "", cfg, tc.printJoin, "", "")
|
||||
|
@ -46,9 +46,15 @@ func TestRunDiff(t *testing.T) {
|
||||
currentVersion := "v" + constants.CurrentKubernetesVersion.String()
|
||||
|
||||
// create a temporary file with valid ClusterConfiguration
|
||||
testUpgradeDiffConfigContents := []byte(fmt.Sprintf("apiVersion: %s\n"+
|
||||
"kind: ClusterConfiguration\n"+
|
||||
"kubernetesVersion: %s", kubeadmapiv1.SchemeGroupVersion.String(), currentVersion))
|
||||
testUpgradeDiffConfigContents := []byte(fmt.Sprintf(`
|
||||
apiVersion: %s
|
||||
kind: InitConfiguration
|
||||
nodeRegistration:
|
||||
criSocket: %s
|
||||
---
|
||||
apiVersion: %[1]s
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: %[3]s`, kubeadmapiv1.SchemeGroupVersion.String(), constants.UnknownCRISocket, currentVersion))
|
||||
testUpgradeDiffConfig, err := createTestRunDiffFile(testUpgradeDiffConfigContents)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -61,7 +61,7 @@ apiVersion: %s
|
||||
kind: InitConfiguration
|
||||
nodeRegistration:
|
||||
name: foo
|
||||
criSocket: ""
|
||||
criSocket: %s
|
||||
localAPIEndpoint:
|
||||
advertiseAddress: 192.168.2.2
|
||||
bindPort: 6443
|
||||
@ -86,7 +86,7 @@ networking:
|
||||
dnsDomain: cluster.local
|
||||
podSubnet: ""
|
||||
serviceSubnet: 10.96.0.0/12
|
||||
`, kubeadmapiv1.SchemeGroupVersion.String())
|
||||
`, kubeadmapiv1.SchemeGroupVersion.String(), constants.UnknownCRISocket)
|
||||
|
||||
// fakeWaiter is a fake apiclient.Waiter that returns errors it was initialized with
|
||||
type fakeWaiter struct {
|
||||
|
@ -1070,6 +1070,9 @@ func TestJoinIPCheck(t *testing.T) {
|
||||
t.Skip("not a privileged user")
|
||||
}
|
||||
internalcfg, err := configutil.DefaultedJoinConfiguration(&kubeadmapiv1.JoinConfiguration{
|
||||
NodeRegistration: kubeadmapiv1.NodeRegistrationOptions{
|
||||
CRISocket: constants.UnknownCRISocket,
|
||||
},
|
||||
Discovery: kubeadmapiv1.Discovery{
|
||||
BootstrapToken: &kubeadmapiv1.BootstrapTokenDiscovery{
|
||||
Token: configutil.PlaceholderToken.Token.String(),
|
||||
|
@ -49,7 +49,9 @@ var cfgFiles = map[string][]byte{
|
||||
"InitConfiguration_v1beta3": []byte(fmt.Sprintf(`
|
||||
apiVersion: %s
|
||||
kind: InitConfiguration
|
||||
`, kubeadmapiv1.SchemeGroupVersion.String())),
|
||||
nodeRegistration:
|
||||
criSocket: %s
|
||||
`, kubeadmapiv1.SchemeGroupVersion.String(), kubeadmconstants.UnknownCRISocket)),
|
||||
"ClusterConfiguration_v1beta3": []byte(fmt.Sprintf(`
|
||||
apiVersion: %s
|
||||
kind: ClusterConfiguration
|
||||
|
@ -18,6 +18,7 @@ package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -26,11 +27,19 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
)
|
||||
|
||||
func TestLoadInitConfigurationFromFile(t *testing.T) {
|
||||
certDir := "/tmp/foo"
|
||||
clusterCfg := []byte(fmt.Sprintf(`
|
||||
apiVersion: %s
|
||||
kind: ClusterConfiguration
|
||||
certificatesDir: %s
|
||||
kubernetesVersion: %s`, kubeadmapiv1.SchemeGroupVersion.String(), certDir, constants.MinimumControlPlaneVersion.String()))
|
||||
|
||||
// Create temp folder for the test case
|
||||
tmpdir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
@ -43,14 +52,23 @@ func TestLoadInitConfigurationFromFile(t *testing.T) {
|
||||
name string
|
||||
fileContents []byte
|
||||
expectErr bool
|
||||
validate func(*testing.T, *kubeadm.InitConfiguration)
|
||||
}{
|
||||
{
|
||||
name: "v1beta3.partial1",
|
||||
fileContents: cfgFiles["InitConfiguration_v1beta3"],
|
||||
},
|
||||
{
|
||||
name: "v1beta3.partial2",
|
||||
fileContents: cfgFiles["ClusterConfiguration_v1beta3"],
|
||||
name: "v1beta3.partial2",
|
||||
fileContents: bytes.Join([][]byte{
|
||||
cfgFiles["InitConfiguration_v1beta3"],
|
||||
clusterCfg,
|
||||
}, []byte(constants.YAMLDocumentSeparator)),
|
||||
validate: func(t *testing.T, cfg *kubeadm.InitConfiguration) {
|
||||
if cfg.ClusterConfiguration.CertificatesDir != certDir {
|
||||
t.Errorf("CertificatesDir from ClusterConfiguration holds the wrong value, Expected: %v. Actual: %v", certDir, cfg.ClusterConfiguration.CertificatesDir)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "v1beta3.full",
|
||||
@ -87,6 +105,10 @@ func TestLoadInitConfigurationFromFile(t *testing.T) {
|
||||
t.Error("Unexpected nil return value")
|
||||
}
|
||||
}
|
||||
// exec additional validation on the returned value
|
||||
if rt.validate != nil {
|
||||
rt.validate(t, obj)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -104,6 +126,9 @@ func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
APIVersion: kubeadmapiv1.SchemeGroupVersion.String(),
|
||||
Kind: constants.InitConfigurationKind,
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1.NodeRegistrationOptions{
|
||||
CRISocket: constants.UnknownCRISocket,
|
||||
},
|
||||
},
|
||||
expectedTaintCnt: 1,
|
||||
},
|
||||
@ -114,7 +139,9 @@ func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
APIVersion: kubeadmapiv1.SchemeGroupVersion.String(),
|
||||
Kind: constants.InitConfigurationKind,
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1.NodeRegistrationOptions{},
|
||||
NodeRegistration: kubeadmapiv1.NodeRegistrationOptions{
|
||||
CRISocket: constants.UnknownCRISocket,
|
||||
},
|
||||
},
|
||||
expectedTaintCnt: 1,
|
||||
},
|
||||
@ -126,7 +153,8 @@ func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
Kind: constants.InitConfigurationKind,
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1.NodeRegistrationOptions{
|
||||
Taints: []v1.Taint{},
|
||||
Taints: []v1.Taint{},
|
||||
CRISocket: constants.UnknownCRISocket,
|
||||
},
|
||||
},
|
||||
expectedTaintCnt: 0,
|
||||
@ -143,6 +171,7 @@ func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
{Key: "taint1"},
|
||||
{Key: "taint2"},
|
||||
},
|
||||
CRISocket: constants.UnknownCRISocket,
|
||||
},
|
||||
},
|
||||
expectedTaintCnt: 2,
|
||||
|
@ -56,6 +56,8 @@ func TestLoadJoinConfigurationFromFile(t *testing.T) {
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
kind: JoinConfiguration
|
||||
caCertPath: /etc/kubernetes/pki/ca.crt
|
||||
nodeRegistration:
|
||||
criSocket: "unix:///var/run/unknown.sock"
|
||||
discovery:
|
||||
bootstrapToken:
|
||||
apiServerEndpoint: kube-apiserver:6443
|
||||
|
Loading…
Reference in New Issue
Block a user