Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Commit

Permalink
Refactor networking setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Shark committed May 24, 2020
1 parent 308a9c1 commit 3d03fd9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 0 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,13 @@ func main() {
log.Debug("SealedSecrets is disabled")
}

log.Info("Resetting network interfaces")
if _, err = cmd.Run(&cmd.Command{Name: "sh", Arg: []string{"-c", "for i in $(ls /sys/class/net/); do [ $i != lo ] && /usr/sbin/ip addr flush $i; done"}}, log, *dry); err != nil {
log.WithError(err).Error("Error resetting network interfaces")
}

log.Info("Configuring public IPv4")
cmds := []*cmd.Command{{Name: "ip", Arg: []string{"-4", "link", "set", "up", "dev", cfg.NodeConfig.PublicNetwork.NetDeviceName}}}
for _, ip := range cfg.NodeConfig.PublicNetwork.IPv4Addresses {
cmds = append(cmds, &cmd.Command{Name: "ip", Arg: []string{"-4", "addr", "add", ip.Net.String(), "dev", "eth0"}})
}
cmds = append(
cmds,
&cmd.Command{Name: "ip", Arg: []string{"-4", "route", "add", cfg.NodeConfig.PublicNetwork.GatewayIPv4.String(), "dev", "eth0", "src", cfg.NodeConfig.PublicNetwork.IPv4Addresses[0].Net.IP.String()}},
&cmd.Command{Name: "ip", Arg: []string{"-4", "route", "add", "default", "via", cfg.NodeConfig.PublicNetwork.GatewayIPv4.String()}},
)
if err = cmd.RunMultiple(log, *dry, cmds); err != nil {
Expand Down
8 changes: 5 additions & 3 deletions template/k3os.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func GenerateK3OSConfig(path string, cfg *model.HCloudK3OSConfig) (err error) {
type k3osCfg struct {
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
K3OS struct {
ServerURL string `yaml:"server_url"`
ServerURL *string `yaml:"server_url,omitempty"`
Token string `yaml:"token"`
K3SArgs []string `yaml:"k3s_args"`
} `yaml:"k3os"`
Expand All @@ -25,15 +25,17 @@ func GenerateK3OSConfig(path string, cfg *model.HCloudK3OSConfig) (err error) {
buf []byte
)
k3cfg.SSHAuthorizedKeys = cfg.NodeConfig.SSHAuthorizedKeys
k3cfg.K3OS.ServerURL = cfg.ClusterConfig.K3OSMasterJoinURL
if cfg.NodeConfig.Role == model.RoleAgent {
k3cfg.K3OS.ServerURL = &cfg.ClusterConfig.K3OSMasterJoinURL
}
k3cfg.K3OS.Token = cfg.ClusterConfig.K3OSToken
k3cfg.K3OS.K3SArgs = []string{}
if cfg.NodeConfig.Role == model.RoleMaster {
k3cfg.K3OS.K3SArgs = append(
k3cfg.K3OS.K3SArgs,
"server",
"--advertise-address",
cfg.NodeConfig.PrivateNetwork.IPv4Addresses[0].Net.String(),
cfg.NodeConfig.PrivateNetwork.IPv4Addresses[0].Net.IP.String(),
)
} else if cfg.NodeConfig.Role == model.RoleAgent {
k3cfg.K3OS.K3SArgs = append(
Expand Down

0 comments on commit 3d03fd9

Please sign in to comment.