mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #48538 from GheRivero/kubeadm_nodename
Automatic merge from submit-queue Add node-name flag to `join` phase **What this PR does / why we need it**: Allow to specify a node-name instead of relaying in `os.Hostname()` This is useful where kubelet use the name given by the cloud-provider to register the node. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: partially fixes kubernetes/kubeadm#64 **Special notes for your reviewer**: **Release note**: ```release-note Added new flag to `kubeadm join`: --node-name, that lets you specify the name of the Node object that's gonna be created ```
This commit is contained in:
		@@ -93,6 +93,7 @@ type NodeConfiguration struct {
 | 
				
			|||||||
	DiscoveryToken string
 | 
						DiscoveryToken string
 | 
				
			||||||
	// Currently we only pay attention to one api server but hope to support >1 in the future
 | 
						// Currently we only pay attention to one api server but hope to support >1 in the future
 | 
				
			||||||
	DiscoveryTokenAPIServers []string
 | 
						DiscoveryTokenAPIServers []string
 | 
				
			||||||
 | 
						NodeName                 string
 | 
				
			||||||
	TLSBootstrapToken        string
 | 
						TLSBootstrapToken        string
 | 
				
			||||||
	Token                    string
 | 
						Token                    string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -85,6 +85,7 @@ type NodeConfiguration struct {
 | 
				
			|||||||
	DiscoveryFile            string   `json:"discoveryFile"`
 | 
						DiscoveryFile            string   `json:"discoveryFile"`
 | 
				
			||||||
	DiscoveryToken           string   `json:"discoveryToken"`
 | 
						DiscoveryToken           string   `json:"discoveryToken"`
 | 
				
			||||||
	DiscoveryTokenAPIServers []string `json:"discoveryTokenAPIServers"`
 | 
						DiscoveryTokenAPIServers []string `json:"discoveryTokenAPIServers"`
 | 
				
			||||||
 | 
						NodeName                 string   `json:"nodeName"`
 | 
				
			||||||
	TLSBootstrapToken        string   `json:"tlsBootstrapToken"`
 | 
						TLSBootstrapToken        string   `json:"tlsBootstrapToken"`
 | 
				
			||||||
	Token                    string   `json:"token"`
 | 
						Token                    string   `json:"token"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -112,6 +112,9 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
 | 
				
			|||||||
	cmd.PersistentFlags().StringVar(
 | 
						cmd.PersistentFlags().StringVar(
 | 
				
			||||||
		&cfg.DiscoveryToken, "discovery-token", "",
 | 
							&cfg.DiscoveryToken, "discovery-token", "",
 | 
				
			||||||
		"A token used to validate cluster information fetched from the master")
 | 
							"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(
 | 
						cmd.PersistentFlags().StringVar(
 | 
				
			||||||
		&cfg.TLSBootstrapToken, "tls-bootstrap-token", "",
 | 
							&cfg.TLSBootstrapToken, "tls-bootstrap-token", "",
 | 
				
			||||||
		"A token used for TLS bootstrapping")
 | 
							"A token used for TLS bootstrapping")
 | 
				
			||||||
@@ -175,9 +178,12 @@ func (j *Join) Run(out io.Writer) error {
 | 
				
			|||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	hostname, err := os.Hostname()
 | 
						hostname := j.cfg.NodeName
 | 
				
			||||||
	if err != nil {
 | 
						if hostname == "" {
 | 
				
			||||||
		return err
 | 
							hostname, err = os.Hostname()
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	client, err := kubeconfigutil.KubeConfigToClientSet(cfg)
 | 
						client, err := kubeconfigutil.KubeConfigToClientSet(cfg)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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) {
 | 
					func TestCmdJoinTLSBootstrapToken(t *testing.T) {
 | 
				
			||||||
	if *kubeadmCmdSkip {
 | 
						if *kubeadmCmdSkip {
 | 
				
			||||||
		t.Log("kubeadm cmd tests being skipped")
 | 
							t.Log("kubeadm cmd tests being skipped")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user