UNCLASSIFIED

Unverified Commit d3968327 authored by Hussein Galal's avatar Hussein Galal Committed by GitHub
Browse files

Use FQDN for node name if cloud provider is set to AWS (#1631)

* Use fqdn if cloud provider is set to aws

* fix comments
parent 8739bec8
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
package rke2 package rke2
import ( import (
"bytes"
"fmt" "fmt"
"os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -59,6 +61,15 @@ func initExecutor(clx *cli.Context, cfg Config, dataDir string, disableETCD bool ...@@ -59,6 +61,15 @@ func initExecutor(clx *cli.Context, cfg Config, dataDir string, disableETCD bool
Name: cfg.CloudProviderName, Name: cfg.CloudProviderName,
Path: cfg.CloudProviderConfig, Path: cfg.CloudProviderConfig,
} }
if clx.String("node-name") == "" && cfg.CloudProviderName == "aws" {
fqdn, err := hostnameFQDN()
if err != nil {
return nil, err
}
if err := clx.Set("node-name", fqdn); err != nil {
return nil, err
}
}
} }
if cfg.KubeletPath == "" { if cfg.KubeletPath == "" {
...@@ -175,3 +186,16 @@ func initExecutor(clx *cli.Context, cfg Config, dataDir string, disableETCD bool ...@@ -175,3 +186,16 @@ func initExecutor(clx *cli.Context, cfg Config, dataDir string, disableETCD bool
ControlPlaneMounts: extraMounts, ControlPlaneMounts: extraMounts,
}, nil }, nil
} }
func hostnameFQDN() (string, error) {
cmd := exec.Command("hostname", "-f")
var b bytes.Buffer
cmd.Stdout = &b
if err := cmd.Run(); err != nil {
return "", err
}
return strings.TrimSpace(b.String()), nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment