Skip to content

Commit

Permalink
Remove bind-address from k3s bootstrap for the communcation between k…
Browse files Browse the repository at this point in the history
…ubelet and apiserver
  • Loading branch information
innobead committed Jun 17, 2022
1 parent 62adfdd commit 5b7f6c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions pkg/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/avast/retry-go"
"github.com/goccy/go-yaml"
"github.com/hashicorp/go-multierror"
"github.com/innobead/kubefire/internal/config"
interr "github.com/innobead/kubefire/internal/error"
"github.com/innobead/kubefire/pkg/bootstrap/versionfinder"
pkgconfig "github.com/innobead/kubefire/pkg/config"
Expand Down Expand Up @@ -228,26 +227,30 @@ func downloadKubeConfig(nodeManager node.Manager, cluster *data.Cluster, remoteK
return "", err
}

// for k0s, need to modify the downloaded kubeconfig
if config.Bootstrapper == constants.K0s {
rawBytes, err := ioutil.ReadFile(destPath)
if err != nil {
return "", errors.WithStack(err)
}
// for k0s and k3s, need to modify the downloaded kubeconfig
updateKubeConfig := func(f string, ipaddrs ...string) (string, error) {
for _, ipaddr := range ipaddrs {
rawBytes, err := ioutil.ReadFile(f)
if err != nil {
return "", errors.WithStack(err)
}

result := strings.Replace(
string(rawBytes),
"https://localhost:6443",
fmt.Sprintf("https://%s:6443", firstMaster.Status.IPAddresses),
1,
)
result := strings.Replace(
string(rawBytes),
fmt.Sprintf("https://%s:", ipaddr),
fmt.Sprintf("https://%s:", firstMaster.Status.IPAddresses),
1,
)

if err := ioutil.WriteFile(destPath, []byte(result), 0755); err != nil {
return "", errors.WithStack(err)
if err := ioutil.WriteFile(f, []byte(result), 0755); err != nil {
return f, errors.WithStack(err)
}
}

return f, nil
}

return destPath, nil
return updateKubeConfig(destPath, "localhost", "127.0.0.1")
}

func getSupportedBootstrapperVersion(versionFinder versionfinder.Finder, configManager pkgconfig.Manager, bootstrapper Bootstrapper, version string) (pkgconfig.BootstrapperVersioner, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/bootstrap/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (k *K3sBootstrapper) bootstrap(node *data.Node, isSingleNode bool, extraOpt
defer sshClient.Close()

deployCmdOpts := []string{
fmt.Sprintf("--bind-address=%s", node.Status.IPAddresses),
fmt.Sprintf(`--node-name=%s`, node.Status.IPAddresses),
}
tokenBuf := bytes.Buffer{}

Expand Down

0 comments on commit 5b7f6c0

Please sign in to comment.