Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/kubeadm/app/apis/kubeadm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type NodeConfiguration struct {
DiscoveryToken string
// Currently we only pay attention to one api server but hope to support >1 in the future
DiscoveryTokenAPIServers []string
NodeName string
TLSBootstrapToken string
Token string
}
1 change: 1 addition & 0 deletions cmd/kubeadm/app/apis/kubeadm/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type NodeConfiguration struct {
DiscoveryFile string `json:"discoveryFile"`
DiscoveryToken string `json:"discoveryToken"`
DiscoveryTokenAPIServers []string `json:"discoveryTokenAPIServers"`
NodeName string `json:"nodeName"`
TLSBootstrapToken string `json:"tlsBootstrapToken"`
Token string `json:"token"`
}
12 changes: 9 additions & 3 deletions cmd/kubeadm/app/cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
cmd.PersistentFlags().StringVar(
&cfg.DiscoveryToken, "discovery-token", "",
"A token used to validate cluster information fetched from the master")
cmd.PersistentFlags().StringVar(
&cfg.NodeName, "node-name", "",
"Specify the node name")
cmd.PersistentFlags().StringVar(
&cfg.TLSBootstrapToken, "tls-bootstrap-token", "",
"A token used for TLS bootstrapping")
Expand Down Expand Up @@ -175,9 +178,12 @@ func (j *Join) Run(out io.Writer) error {
return err
}

hostname, err := os.Hostname()
if err != nil {
return err
hostname := j.cfg.NodeName
if hostname == "" {
hostname, err = os.Hostname()
if err != nil {
return err
}
}
client, err := kubeconfigutil.KubeConfigToClientSet(cfg)
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions cmd/kubeadm/test/cmd/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,34 @@ func TestCmdJoinDiscoveryToken(t *testing.T) {
}
}

func TestCmdJoinNodeName(t *testing.T) {
if *kubeadmCmdSkip {
t.Log("kubeadm cmd tests being skipped")
t.Skip()
}

var initTest = []struct {
args string
expected bool
}{
{"--node-name=foobar", false},
}

for _, rt := range initTest {
_, _, actual := RunCmd(*kubeadmPath, "join", rt.args, "--skip-preflight-checks")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinNodeName running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
}
}

func TestCmdJoinTLSBootstrapToken(t *testing.T) {
if *kubeadmCmdSkip {
t.Log("kubeadm cmd tests being skipped")
Expand Down