mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #40628 from skriss/kubeadm_multi_endpoint_bugfix
Automatic merge from submit-queue (batch tested with PRs 40392, 39242, 40579, 40628, 40713) fixed bug #36988 -- kubeadm join crashes when using multiple API endpoints **What this PR does / why we need it**: Simple bug fix for #36988 (kubeadm crashes when trying to join nodes to a master with multiple API endpoints) -- stopChan was getting closed multiple times, once per endpoint. Moved the close into the once.Do(...) **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #36988 **Special notes for your reviewer**: this is my first kubernetes commit, just getting familiar with the process, so any/all feedback is appreciated **Release note**:
This commit is contained in:
commit
41684eb22b
@ -80,9 +80,10 @@ func EstablishMasterConnection(c *kubeadmapi.TokenDiscovery, clusterInfo *kubead
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("[bootstrap] Successfully established connection with endpoint %q\n", apiEndpoint)
|
fmt.Printf("[bootstrap] Successfully established connection with endpoint %q\n", apiEndpoint)
|
||||||
|
|
||||||
// connection established, stop all wait threads
|
// connection established, stop all wait threads
|
||||||
close(stopChan)
|
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
|
close(stopChan)
|
||||||
clientConfig = ac.clientConfig
|
clientConfig = ac.clientConfig
|
||||||
})
|
})
|
||||||
}, retryTimeout*time.Second, stopChan)
|
}, retryTimeout*time.Second, stopChan)
|
||||||
|
@ -31,6 +31,63 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestEstablishMasterConnection(t *testing.T) {
|
func TestEstablishMasterConnection(t *testing.T) {
|
||||||
|
srv := stubServer(t)
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
c string
|
||||||
|
e string
|
||||||
|
expect bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
c: "",
|
||||||
|
e: "",
|
||||||
|
expect: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
c: "",
|
||||||
|
e: srv.URL,
|
||||||
|
expect: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
c: "foo",
|
||||||
|
e: srv.URL,
|
||||||
|
expect: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, rt := range tests {
|
||||||
|
s := &kubeadmapi.TokenDiscovery{}
|
||||||
|
c := &kubeadmapi.ClusterInfo{Endpoints: []string{rt.e}, CertificateAuthorities: []string{rt.c}}
|
||||||
|
_, actual := EstablishMasterConnection(s, c)
|
||||||
|
if (actual == nil) != rt.expect {
|
||||||
|
t.Errorf(
|
||||||
|
"failed EstablishMasterConnection:\n\texpected: %t\n\t actual: %t",
|
||||||
|
rt.expect,
|
||||||
|
(actual == nil),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEstablishMasterConnectionWithMultipleEndpoints(t *testing.T) {
|
||||||
|
// ref. https://github.com/kubernetes/kubernetes/issues/36988
|
||||||
|
|
||||||
|
srv := stubServer(t)
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
s := &kubeadmapi.TokenDiscovery{}
|
||||||
|
c := &kubeadmapi.ClusterInfo{Endpoints: []string{srv.URL, srv.URL}, CertificateAuthorities: []string{"foo"}}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
t.Errorf("failed EstablishMasterConnectionWithMultipleEndpoints; got a panic.")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
EstablishMasterConnection(s, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func stubServer(t *testing.T) *httptest.Server {
|
||||||
expect := version.Info{
|
expect := version.Info{
|
||||||
Major: "foo",
|
Major: "foo",
|
||||||
Minor: "bar",
|
Minor: "bar",
|
||||||
@ -83,41 +140,8 @@ func TestEstablishMasterConnection(t *testing.T) {
|
|||||||
w.Write(output)
|
w.Write(output)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
tests := []struct {
|
return srv
|
||||||
c string
|
|
||||||
e string
|
|
||||||
expect bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
c: "",
|
|
||||||
e: "",
|
|
||||||
expect: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
c: "",
|
|
||||||
e: srv.URL,
|
|
||||||
expect: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
c: "foo",
|
|
||||||
e: srv.URL,
|
|
||||||
expect: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, rt := range tests {
|
|
||||||
s := &kubeadmapi.TokenDiscovery{}
|
|
||||||
c := &kubeadmapi.ClusterInfo{Endpoints: []string{rt.e}, CertificateAuthorities: []string{rt.c}}
|
|
||||||
_, actual := EstablishMasterConnection(s, c)
|
|
||||||
if (actual == nil) != rt.expect {
|
|
||||||
t.Errorf(
|
|
||||||
"failed EstablishMasterConnection:\n\texpected: %t\n\t actual: %t",
|
|
||||||
rt.expect,
|
|
||||||
(actual == nil),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateClients(t *testing.T) {
|
func TestCreateClients(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user