mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 21:25:09 +00:00
Merge pull request #39426 from apprenda/kubeadm_95-fix_token_discovery
Automatic merge from submit-queue kubeadm token discovery URL may not have valid input for url.Parse **What this PR does / why we need it**: **Which issue this PR fixes**: fixes https://github.com/kubernetes/kubeadm/issues/95 **Special notes for your reviewer**: /cc @dgoodwin @luxas @mikedanese this is a WIP! Need a couple things: * decide token separator, `.` or `:` * define error handling in `token.go::37`
This commit is contained in:
@@ -76,6 +76,15 @@ func ParseURL(d *kubeadm.Discovery, s string) error {
|
||||
case "file":
|
||||
return file.Parse(u, d)
|
||||
case "token":
|
||||
// Make sure a valid RFC 3986 URL has been passed and parsed.
|
||||
// See https://github.com/kubernetes/kubeadm/issues/95#issuecomment-270431296 for more details.
|
||||
if !strings.Contains(s, "@") {
|
||||
s := s + "@"
|
||||
u, err = url.Parse(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return token.Parse(u, d)
|
||||
default:
|
||||
return fmt.Errorf("unknown discovery scheme")
|
||||
|
@@ -37,6 +37,24 @@ func TestParseURL(t *testing.T) {
|
||||
Token: &kubeadm.TokenDiscovery{},
|
||||
},
|
||||
},
|
||||
{
|
||||
url: "token://c05de9:ab224260fb3cd718",
|
||||
expect: kubeadm.Discovery{
|
||||
Token: &kubeadm.TokenDiscovery{
|
||||
ID: "c05de9",
|
||||
Secret: "ab224260fb3cd718",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
url: "token://c05de9:ab224260fb3cd718@",
|
||||
expect: kubeadm.Discovery{
|
||||
Token: &kubeadm.TokenDiscovery{
|
||||
ID: "c05de9",
|
||||
Secret: "ab224260fb3cd718",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
url: "token://c05de9:ab224260fb3cd718@192.168.0.1:6555,191.168.0.2:6443",
|
||||
expect: kubeadm.Discovery{
|
||||
@@ -76,7 +94,7 @@ func TestParseURL(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(d, c.expect) {
|
||||
t.Errorf("expected discovery config to be equeal but got:\n\ta: %s\n\tb: %s", spew.Sdump(d), spew.Sdump(c.expect))
|
||||
t.Errorf("expected discovery config to be equal but got:\n\tactual: %s\n\texpected: %s", spew.Sdump(d), spew.Sdump(c.expect))
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user