Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/rke2/rke2_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
package rke2

import (
"bytes"
"fmt"
"os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -59,6 +61,15 @@ func initExecutor(clx *cli.Context, cfg Config, dataDir string, disableETCD bool
Name: cfg.CloudProviderName,
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 == "" {
Expand Down Expand Up @@ -173,3 +184,16 @@ func initExecutor(clx *cli.Context, cfg Config, dataDir string, disableETCD bool
ControlPlaneMounts: extraMounts,
}, 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
}