mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-31 08:33:17 +00:00
robot: Make linter happy
This commit is contained in:
committed by
Itxaka
parent
1a12a26876
commit
b62a3fc892
@@ -13,11 +13,10 @@ import (
|
||||
"github.com/nxadm/tail"
|
||||
)
|
||||
|
||||
// setup needs edgevpn and k3s installed locally
|
||||
// (both k3s and k3s-agent systemd services)
|
||||
// setup needs edgevpn and k3s installed locally (both k3s and k3s-agent systemd services).
|
||||
func Run(apiAddress string, dir []string, force bool) error {
|
||||
|
||||
os.MkdirAll("/usr/local/.c3os", 0600)
|
||||
os.MkdirAll("/usr/local/.c3os", 0600) //nolint:errcheck
|
||||
|
||||
// Reads config
|
||||
c, err := config.Scan(config.Directories(dir...))
|
||||
@@ -31,7 +30,7 @@ func Run(apiAddress string, dir []string, force bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
os.MkdirAll("/var/log/c3os", 0600)
|
||||
os.MkdirAll("/var/log/c3os", 0600) //nolint:errcheck
|
||||
fileName := filepath.Join("/var/log/c3os", "agent-provider.log")
|
||||
err = ioutil.WriteFile(fileName, []byte{}, os.ModePerm)
|
||||
if err != nil {
|
||||
@@ -58,7 +57,10 @@ func Run(apiAddress string, dir []string, force bool) error {
|
||||
|
||||
// Re-load providers
|
||||
bus.Manager.LoadProviders()
|
||||
machine.CreateSentinel("bundles")
|
||||
err = machine.CreateSentinel("bundles")
|
||||
if !c.IgnoreBundleErrors && err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = bus.Manager.Publish(events.EventBootstrap, events.BootstrapPayload{APIAddress: apiAddress, Config: c.String(), Logfile: fileName})
|
||||
|
@@ -27,7 +27,7 @@ func LoadConfig(path ...string) (*Config, error) {
|
||||
for _, p := range path {
|
||||
f, err := ioutil.ReadFile(p)
|
||||
if err == nil {
|
||||
yaml.Unmarshal(f, cfg)
|
||||
yaml.Unmarshal(f, cfg) //nolint:errcheck
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package agent
|
||||
|
||||
var DefaultBanner []byte = []byte{
|
||||
var DefaultBanner = []byte{
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
|
||||
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||
0x08, 0x06, 0x00, 0x00, 0x00, 0xf4, 0x78, 0xd4, 0xfa, 0x00, 0x00, 0x02,
|
||||
|
@@ -28,7 +28,7 @@ func optsToArgs(options map[string]string) (res []string) {
|
||||
for k, v := range options {
|
||||
if k != "device" && k != "cc" && k != "reboot" && k != "poweroff" {
|
||||
res = append(res, fmt.Sprintf("--%s", k))
|
||||
res = append(res, fmt.Sprintf("%s", v))
|
||||
res = append(res, v)
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -38,7 +38,7 @@ func Install(dir ...string) error {
|
||||
utils.OnSignal(func() {
|
||||
svc, err := machine.Getty(1)
|
||||
if err == nil {
|
||||
svc.Start()
|
||||
svc.Start() //nolint:errcheck
|
||||
}
|
||||
}, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
@@ -47,7 +47,7 @@ func Install(dir ...string) error {
|
||||
|
||||
mergeOption := func(cloudConfig string) {
|
||||
c := &config.Config{}
|
||||
yaml.Unmarshal([]byte(cloudConfig), c)
|
||||
yaml.Unmarshal([]byte(cloudConfig), c) //nolint:errcheck
|
||||
for k, v := range c.Options {
|
||||
if k == "cc" {
|
||||
continue
|
||||
@@ -80,11 +80,14 @@ func Install(dir ...string) error {
|
||||
r["device"] = cc.Install.Device
|
||||
mergeOption(cc.String())
|
||||
|
||||
RunInstall(r)
|
||||
err = RunInstall(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
svc, err := machine.Getty(1)
|
||||
if err == nil {
|
||||
svc.Start()
|
||||
svc.Start() //nolint:errcheck
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -133,10 +136,10 @@ func Install(dir ...string) error {
|
||||
header = head
|
||||
}
|
||||
|
||||
// What we receive take precedence over the one in the system
|
||||
yaml.Unmarshal([]byte(cc.String()), &ccData)
|
||||
// What we receive take precedence over the one in the system. best-effort
|
||||
yaml.Unmarshal([]byte(cc.String()), &ccData) //nolint:errcheck
|
||||
if exists {
|
||||
yaml.Unmarshal([]byte(cloudConfig), &ccData)
|
||||
yaml.Unmarshal([]byte(cloudConfig), &ccData) //nolint:errcheck
|
||||
if hasHeader, head := config.HasHeader(cloudConfig, ""); hasHeader {
|
||||
header = head
|
||||
}
|
||||
@@ -150,19 +153,21 @@ func Install(dir ...string) error {
|
||||
r["cc"] = config.AddHeader(header, string(out))
|
||||
|
||||
pterm.Info.Println("Starting installation")
|
||||
utils.SH("elemental run-stage c3os-install.pre")
|
||||
bus.RunHookScript("/usr/bin/c3os-agent.install.pre.hook")
|
||||
utils.SH("elemental run-stage c3os-install.pre") //nolint:errcheck
|
||||
bus.RunHookScript("/usr/bin/c3os-agent.install.pre.hook") //nolint:errcheck
|
||||
|
||||
RunInstall(r)
|
||||
if err := RunInstall(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pterm.Info.Println("Installation completed, press enter to go back to the shell.")
|
||||
|
||||
utils.Prompt("")
|
||||
utils.Prompt("") //nolint:errcheck
|
||||
|
||||
// give tty1 back
|
||||
svc, err := machine.Getty(1)
|
||||
if err == nil {
|
||||
svc.Start()
|
||||
svc.Start() //nolint: errcheck
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -185,15 +190,19 @@ func RunInstall(options map[string]string) error {
|
||||
}
|
||||
|
||||
c := &config.Config{}
|
||||
yaml.Unmarshal([]byte(cloudInit), c)
|
||||
yaml.Unmarshal([]byte(cloudInit), c) //nolint:errcheck
|
||||
|
||||
_, reboot := options["reboot"]
|
||||
_, poweroff := options["poweroff"]
|
||||
|
||||
ioutil.WriteFile(f.Name(), []byte(cloudInit), os.ModePerm)
|
||||
err := ioutil.WriteFile(f.Name(), []byte(cloudInit), os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Printf("could not write cloud init: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
args := []string{"install"}
|
||||
args = append(args, optsToArgs(options)...)
|
||||
args = append(args, "-c", f.Name(), fmt.Sprintf("%s", device))
|
||||
args = append(args, "-c", f.Name(), device)
|
||||
|
||||
cmd := exec.Command("elemental", args...)
|
||||
cmd.Env = os.Environ()
|
||||
@@ -204,8 +213,8 @@ func RunInstall(options map[string]string) error {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
utils.SH("elemental run-stage c3os-install.after")
|
||||
bus.RunHookScript("/usr/bin/c3os-agent.install.after.hook")
|
||||
utils.SH("elemental run-stage c3os-install.after") //nolint:errcheck
|
||||
bus.RunHookScript("/usr/bin/c3os-agent.install.after.hook") //nolint:errcheck
|
||||
|
||||
if reboot || c.Install != nil && c.Install.Reboot {
|
||||
utils.Reboot()
|
||||
|
@@ -76,7 +76,9 @@ func Recovery() error {
|
||||
serviceUUID := utils.RandStringRunes(10)
|
||||
generatedPassword := utils.RandStringRunes(7)
|
||||
|
||||
startRecoveryService(ctx, tk, serviceUUID, recoveryAddr, "fatal")
|
||||
if err := startRecoveryService(ctx, tk, serviceUUID, recoveryAddr, "fatal"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.PrintText(agentConfig.Branding.Recovery, "Recovery")
|
||||
|
||||
@@ -90,12 +92,12 @@ func Recovery() error {
|
||||
go sshServer(recoveryAddr, generatedPassword)
|
||||
|
||||
// Wait for user input and go back to shell
|
||||
utils.Prompt("")
|
||||
utils.Prompt("") //nolint:errcheck
|
||||
cancel()
|
||||
// give tty1 back
|
||||
svc, err := machine.Getty(1)
|
||||
if err == nil {
|
||||
svc.Start()
|
||||
svc.Start() //nolint:errcheck
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -117,13 +119,13 @@ func sshServer(listenAdddr, password string) {
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
io.Copy(f, s) // stdin
|
||||
io.Copy(f, s) //nolint:errcheck
|
||||
}()
|
||||
io.Copy(s, f) // stdout
|
||||
cmd.Wait()
|
||||
io.Copy(s, f) //nolint:errcheck
|
||||
cmd.Wait() //nolint:errcheck
|
||||
} else {
|
||||
io.WriteString(s, "No PTY requested.\n")
|
||||
s.Exit(1)
|
||||
io.WriteString(s, "No PTY requested.\n") //nolint:errcheck
|
||||
s.Exit(1) //nolint:errcheck
|
||||
}
|
||||
})
|
||||
|
||||
|
@@ -7,6 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func setWinsize(f *os.File, w, h int) {
|
||||
syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ),
|
||||
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0})))
|
||||
syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ), //nolint:errcheck
|
||||
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0}))) //nolint:errcheck
|
||||
}
|
||||
|
@@ -28,11 +28,11 @@ func Reset() error {
|
||||
lock := sync.Mutex{}
|
||||
go func() {
|
||||
// Wait for user input and go back to shell
|
||||
utils.Prompt("")
|
||||
utils.Prompt("") //nolint:errcheck
|
||||
// give tty1 back
|
||||
svc, err := machine.Getty(1)
|
||||
if err == nil {
|
||||
svc.Start()
|
||||
svc.Start() //nolint:errcheck
|
||||
}
|
||||
|
||||
lock.Lock()
|
||||
@@ -61,11 +61,11 @@ func Reset() error {
|
||||
lock2 := sync.Mutex{}
|
||||
go func() {
|
||||
// Wait for user input and go back to shell
|
||||
utils.Prompt("")
|
||||
utils.Prompt("") //nolint:errcheck
|
||||
// give tty1 back
|
||||
svc, err := machine.Getty(1)
|
||||
if err == nil {
|
||||
svc.Start()
|
||||
svc.Start() //nolint:errcheck
|
||||
}
|
||||
|
||||
lock2.Lock()
|
||||
|
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/mudler/go-pluggable"
|
||||
)
|
||||
|
||||
// Manager is the bus instance manager, which subscribes plugins to events emitted
|
||||
var Manager *Bus = &Bus{
|
||||
// Manager is the bus instance manager, which subscribes plugins to events emitted.
|
||||
var Manager = &Bus{
|
||||
Manager: pluggable.NewManager(
|
||||
[]pluggable.EventType{
|
||||
bus.EventBootstrap,
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
@@ -84,5 +84,5 @@ func dotToYAML(v map[string]interface{}) ([]byte, error) {
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
return out, err
|
||||
return out, errs
|
||||
}
|
||||
|
@@ -18,10 +18,10 @@ type BundleConfig struct {
|
||||
RootPath string
|
||||
}
|
||||
|
||||
// BundleOption defines a configuration option for a bundle
|
||||
// BundleOption defines a configuration option for a bundle.
|
||||
type BundleOption func(bc *BundleConfig) error
|
||||
|
||||
// Apply applies bundle options to the config
|
||||
// Apply applies bundle options to the config.
|
||||
func (bc *BundleConfig) Apply(opts ...BundleOption) error {
|
||||
for _, o := range opts {
|
||||
if err := o(bc); err != nil {
|
||||
@@ -32,7 +32,7 @@ func (bc *BundleConfig) Apply(opts ...BundleOption) error {
|
||||
}
|
||||
|
||||
// WithDBPath sets the DB path for package installs.
|
||||
// In case of luet packages will contain the db of the installed packages
|
||||
// In case of luet packages will contain the db of the installed packages.
|
||||
func WithDBPath(r string) BundleOption {
|
||||
return func(bc *BundleConfig) error {
|
||||
bc.DBPath = r
|
||||
@@ -82,7 +82,7 @@ type BundleInstaller interface {
|
||||
}
|
||||
|
||||
// RunBundles runs bundles in a system.
|
||||
// Accept a list of bundles options, which gets applied based on the bundle configuration
|
||||
// Accept a list of bundles options, which gets applied based on the bundle configuration.
|
||||
func RunBundles(bundles ...[]BundleOption) error {
|
||||
|
||||
// TODO:
|
||||
@@ -92,7 +92,10 @@ func RunBundles(bundles ...[]BundleOption) error {
|
||||
var resErr error
|
||||
for _, b := range bundles {
|
||||
config := defaultConfig()
|
||||
config.Apply(b...)
|
||||
if err := config.Apply(b...); err != nil {
|
||||
resErr = multierror.Append(err)
|
||||
continue
|
||||
}
|
||||
|
||||
installer, err := NewBundleInstaller(*config)
|
||||
if err != nil {
|
||||
@@ -102,7 +105,6 @@ func RunBundles(bundles ...[]BundleOption) error {
|
||||
dat := strings.Split(config.Target, "://")
|
||||
if len(dat) != 2 {
|
||||
resErr = multierror.Append(fmt.Errorf("invalid target"))
|
||||
|
||||
continue
|
||||
}
|
||||
config.Target = dat[1]
|
||||
@@ -136,7 +138,7 @@ func NewBundleInstaller(bc BundleConfig) (BundleInstaller, error) {
|
||||
return &LuetInstaller{}, nil
|
||||
}
|
||||
|
||||
// BundleInstall installs a bundle from a luet repo or a container image
|
||||
// BundleInstall installs a bundle from a luet repo or a container image.
|
||||
type ContainerRunner struct{}
|
||||
|
||||
func (l *ContainerRunner) Install(config *BundleConfig) error {
|
||||
|
@@ -30,7 +30,7 @@ const (
|
||||
UnknownBoot = "unknown"
|
||||
)
|
||||
|
||||
// BootFrom returns the booting partition of the SUT
|
||||
// BootFrom returns the booting partition of the SUT.
|
||||
func BootFrom() string {
|
||||
out, err := utils.SH("cat /proc/cmdline")
|
||||
if err != nil {
|
||||
@@ -59,14 +59,14 @@ func EdgeVPN(instance, rootDir string) (Service, error) {
|
||||
openrc.WithUnitContent(openrc.EdgevpnUnit),
|
||||
openrc.WithRoot(rootDir),
|
||||
)
|
||||
} else {
|
||||
return systemd.NewService(
|
||||
systemd.WithName("edgevpn"),
|
||||
systemd.WithInstance(instance),
|
||||
systemd.WithUnitContent(systemd.EdgevpnUnit),
|
||||
systemd.WithRoot(rootDir),
|
||||
)
|
||||
}
|
||||
|
||||
return systemd.NewService(
|
||||
systemd.WithName("edgevpn"),
|
||||
systemd.WithInstance(instance),
|
||||
systemd.WithUnitContent(systemd.EdgevpnUnit),
|
||||
systemd.WithRoot(rootDir),
|
||||
)
|
||||
}
|
||||
|
||||
const EdgeVPNDefaultInstance string = "c3os"
|
||||
@@ -79,19 +79,19 @@ func (fakegetty) OverrideCmd(string) error { return nil }
|
||||
func (fakegetty) SetEnvFile(string) error { return nil }
|
||||
func (fakegetty) WriteUnit() error { return nil }
|
||||
func (fakegetty) Start() error {
|
||||
utils.SH("chvt 2")
|
||||
utils.SH("chvt 2") //nolint:errcheck
|
||||
return nil
|
||||
}
|
||||
|
||||
func Getty(i int) (Service, error) {
|
||||
if utils.IsOpenRCBased() {
|
||||
return &fakegetty{}, nil
|
||||
} else {
|
||||
return systemd.NewService(
|
||||
systemd.WithName("getty"),
|
||||
systemd.WithInstance(fmt.Sprintf("tty%d", i)),
|
||||
)
|
||||
}
|
||||
|
||||
return systemd.NewService(
|
||||
systemd.WithName("getty"),
|
||||
systemd.WithInstance(fmt.Sprintf("tty%d", i)),
|
||||
)
|
||||
}
|
||||
|
||||
func K3s() (Service, error) {
|
||||
@@ -99,11 +99,11 @@ func K3s() (Service, error) {
|
||||
return openrc.NewService(
|
||||
openrc.WithName("k3s"),
|
||||
)
|
||||
} else {
|
||||
return systemd.NewService(
|
||||
systemd.WithName("k3s"),
|
||||
)
|
||||
}
|
||||
|
||||
return systemd.NewService(
|
||||
systemd.WithName("k3s"),
|
||||
)
|
||||
}
|
||||
|
||||
func K3sAgent() (Service, error) {
|
||||
@@ -111,19 +111,19 @@ func K3sAgent() (Service, error) {
|
||||
return openrc.NewService(
|
||||
openrc.WithName("k3s-agent"),
|
||||
)
|
||||
} else {
|
||||
return systemd.NewService(
|
||||
systemd.WithName("k3s-agent"),
|
||||
)
|
||||
}
|
||||
|
||||
return systemd.NewService(
|
||||
systemd.WithName("k3s-agent"),
|
||||
)
|
||||
}
|
||||
|
||||
func K3sEnvUnit(unit string) string {
|
||||
if utils.IsOpenRCBased() {
|
||||
return fmt.Sprintf("/etc/rancher/k3s/%s.env", unit)
|
||||
} else {
|
||||
return fmt.Sprintf("/etc/sysconfig/%s", unit)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("/etc/sysconfig/%s", unit)
|
||||
}
|
||||
|
||||
func UUID() string {
|
||||
|
@@ -58,7 +58,7 @@ func (s ServiceUnit) WriteUnit() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: This is too much k3s specific
|
||||
// TODO: This is too much k3s specific.
|
||||
func (s ServiceUnit) OverrideCmd(cmd string) error {
|
||||
k3sbin := utils.K3sBin()
|
||||
if k3sbin == "" {
|
||||
@@ -73,13 +73,19 @@ func (s ServiceUnit) OverrideCmd(cmd string) error {
|
||||
}
|
||||
|
||||
func (s ServiceUnit) Start() error {
|
||||
_, err := utils.SH(fmt.Sprintf("/etc/init.d/%s start", s.name))
|
||||
return err
|
||||
out, err := utils.SH(fmt.Sprintf("/etc/init.d/%s start", s.name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed starting service: %s. %s (%w)", s.name, out, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s ServiceUnit) Restart() error {
|
||||
_, err := utils.SH(fmt.Sprintf("/etc/init.d/%s restart", s.name))
|
||||
return err
|
||||
out, err := utils.SH(fmt.Sprintf("/etc/init.d/%s restart", s.name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed restarting service: %s. %s (%w)", s.name, out, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s ServiceUnit) Enable() error {
|
||||
|
@@ -72,13 +72,13 @@ func (s ServiceUnit) WriteUnit() error {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.SH("systemctl daemon-reload")
|
||||
return nil
|
||||
_, err := utils.SH("systemctl daemon-reload")
|
||||
return err
|
||||
}
|
||||
|
||||
func (s ServiceUnit) OverrideCmd(cmd string) error {
|
||||
svcDir := filepath.Join(s.rootdir, fmt.Sprintf("/etc/systemd/system/%s.service.d/", s.name))
|
||||
os.MkdirAll(svcDir, 0600)
|
||||
os.MkdirAll(svcDir, 0600) //nolint:errcheck
|
||||
|
||||
return ioutil.WriteFile(filepath.Join(svcDir, "override.conf"), []byte(fmt.Sprintf(overrideCmdTemplate, cmd)), 0600)
|
||||
}
|
||||
|
@@ -50,8 +50,8 @@ func Bootstrap(e *pluggable.Event) pluggable.EventResponse {
|
||||
return pluggable.EventResponse{State: "no c3os or k3s configuration. nothing to do"}
|
||||
}
|
||||
|
||||
utils.SH("elemental run-stage c3os-agent.bootstrap")
|
||||
eventBus.RunHookScript("/usr/bin/c3os-agent.bootstrap.hook")
|
||||
utils.SH("elemental run-stage c3os-agent.bootstrap") //nolint:errcheck
|
||||
eventBus.RunHookScript("/usr/bin/c3os-agent.bootstrap.hook") //nolint:errcheck
|
||||
|
||||
logLevel := "debug"
|
||||
|
||||
@@ -61,7 +61,7 @@ func Bootstrap(e *pluggable.Event) pluggable.EventResponse {
|
||||
|
||||
lvl, err := logging.LevelFromString(logLevel)
|
||||
if err != nil {
|
||||
return ErrorEvent("Failed setup VPN: %s", err.Error())
|
||||
return ErrorEvent("Failed setup logger: %s", err.Error())
|
||||
}
|
||||
|
||||
// TODO: Fixup Logging to file
|
||||
@@ -71,7 +71,7 @@ func Bootstrap(e *pluggable.Event) pluggable.EventResponse {
|
||||
}
|
||||
logger, err := loggerCfg.Build()
|
||||
if err != nil {
|
||||
return ErrorEvent("Failed setup VPN: %s", err.Error())
|
||||
return ErrorEvent("Failed setup logger: %s", err.Error())
|
||||
}
|
||||
|
||||
logging.SetAllLoggers(lvl)
|
||||
@@ -94,7 +94,6 @@ func Bootstrap(e *pluggable.Event) pluggable.EventResponse {
|
||||
}
|
||||
|
||||
logger.Info("Configuring VPN")
|
||||
|
||||
if err := SetupVPN(machine.EdgeVPNDefaultInstance, cfg.APIAddress, "/", true, providerConfig); err != nil {
|
||||
return ErrorEvent("Failed setup VPN: %s", err.Error())
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ func SetupVPN(instance, apiAddress, rootDir string, start bool, c *providerConfi
|
||||
|
||||
svc, err := machine.EdgeVPN(instance, rootDir)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("could not create svc: %w", err)
|
||||
}
|
||||
|
||||
apiAddress = strings.ReplaceAll(apiAddress, "https://", "")
|
||||
@@ -47,14 +47,14 @@ func SetupVPN(instance, apiAddress, rootDir string, start bool, c *providerConfi
|
||||
vpnOpts["DNSFORWARD"] = "true"
|
||||
if !utils.IsOpenRCBased() {
|
||||
if _, err := os.Stat("/etc/sysconfig/network/config"); err == nil {
|
||||
utils.WriteEnv("/etc/sysconfig/network/config", map[string]string{
|
||||
utils.WriteEnv("/etc/sysconfig/network/config", map[string]string{ //nolint:errcheck
|
||||
"NETCONFIG_DNS_STATIC_SERVERS": "127.0.0.1",
|
||||
})
|
||||
if utils.Flavor() == "opensuse" {
|
||||
// TODO: This is dependant on wickedd, move this out in its own network detection block
|
||||
svc, err := systemd.NewService(systemd.WithName("wickedd"))
|
||||
if err == nil {
|
||||
svc.Restart()
|
||||
svc.Restart() //nolint:errcheck
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,26 +64,26 @@ func SetupVPN(instance, apiAddress, rootDir string, start bool, c *providerConfi
|
||||
Stages: map[string][]yip.Stage{
|
||||
config.NetworkStage.String(): {{Dns: yip.DNS{Nameservers: []string{"127.0.0.1"}}}}},
|
||||
}); err != nil {
|
||||
fmt.Println("Failed installing DNS")
|
||||
return fmt.Errorf("could not create dns config: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
os.MkdirAll("/etc/systemd/system.conf.d/", 0600)
|
||||
os.MkdirAll("/etc/systemd/system.conf.d/", 0600) //nolint:errcheck
|
||||
// Setup edgevpn instance
|
||||
err = utils.WriteEnv(filepath.Join(rootDir, "/etc/systemd/system.conf.d/edgevpn-c3os.env"), vpnOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("could not create write env file: %w", err)
|
||||
}
|
||||
|
||||
err = svc.WriteUnit()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("could not create write unit file: %w", err)
|
||||
}
|
||||
|
||||
if start {
|
||||
err = svc.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("could not start svc: %w", err)
|
||||
}
|
||||
|
||||
return svc.Enable()
|
||||
|
@@ -44,7 +44,10 @@ func Auto(cc *config.Config, pconfig *providerConfig.Config) Role {
|
||||
}
|
||||
|
||||
if shouldBeLeader == c.UUID && (lead == "" || !contains(nodes, lead)) {
|
||||
c.Client.Set("auto", "leader", c.UUID)
|
||||
if err := c.Client.Set("auto", "leader", c.UUID); err != nil {
|
||||
c.Logger.Error(err)
|
||||
return err
|
||||
}
|
||||
c.Logger.Info("Announcing ourselves as leader, backing off")
|
||||
return nil
|
||||
}
|
||||
|
@@ -28,7 +28,10 @@ func propagateMasterData(ip string, c *service.RoleConfig) error {
|
||||
}()
|
||||
|
||||
// If we are configured as master, always signal our role
|
||||
c.Client.Set("role", c.UUID, "master")
|
||||
if err := c.Client.Set("role", c.UUID, "master"); err != nil {
|
||||
c.Logger.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
tokenB, err := ioutil.ReadFile("/var/lib/rancher/k3s/server/node-token")
|
||||
if err != nil {
|
||||
@@ -39,7 +42,10 @@ func propagateMasterData(ip string, c *service.RoleConfig) error {
|
||||
nodeToken := string(tokenB)
|
||||
nodeToken = strings.TrimRight(nodeToken, "\n")
|
||||
if nodeToken != "" {
|
||||
c.Client.Set("nodetoken", "token", nodeToken)
|
||||
err := c.Client.Set("nodetoken", "token", nodeToken)
|
||||
if err != nil {
|
||||
c.Logger.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
kubeB, err := ioutil.ReadFile("/etc/rancher/k3s/k3s.yaml")
|
||||
@@ -49,9 +55,15 @@ func propagateMasterData(ip string, c *service.RoleConfig) error {
|
||||
}
|
||||
kubeconfig := string(kubeB)
|
||||
if kubeconfig != "" {
|
||||
c.Client.Set("kubeconfig", "master", base64.RawURLEncoding.EncodeToString(kubeB))
|
||||
err := c.Client.Set("kubeconfig", "master", base64.RawURLEncoding.EncodeToString(kubeB))
|
||||
if err != nil {
|
||||
c.Logger.Error(err)
|
||||
}
|
||||
}
|
||||
err = c.Client.Set("master", "ip", ip)
|
||||
if err != nil {
|
||||
c.Logger.Error(err)
|
||||
}
|
||||
c.Client.Set("master", "ip", ip)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -66,7 +78,9 @@ func Master(cc *config.Config, pconfig *providerConfig.Config) Role {
|
||||
if pconfig.C3OS.Role != "" {
|
||||
// propagate role if we were forced by configuration
|
||||
// This unblocks eventual auto instances to try to assign roles
|
||||
c.Client.Set("role", c.UUID, pconfig.C3OS.Role)
|
||||
if err := c.Client.Set("role", c.UUID, pconfig.C3OS.Role); err != nil {
|
||||
c.Logger.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if SentinelExist() {
|
||||
@@ -127,11 +141,11 @@ func Master(cc *config.Config, pconfig *providerConfig.Config) Role {
|
||||
return err
|
||||
}
|
||||
|
||||
propagateMasterData(ip, c)
|
||||
if err := propagateMasterData(ip, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
CreateSentinel()
|
||||
|
||||
return nil
|
||||
return CreateSentinel()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// scheduleRoles assigns roles to nodes. Meant to be called only by leaders
|
||||
// TODO: HA-Auto
|
||||
// TODO: HA-Auto.
|
||||
func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pconfig *providerConfig.Config) error {
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
@@ -55,7 +55,9 @@ func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pco
|
||||
selected = toSelect[rand.Intn(len(toSelect)-1)]
|
||||
}
|
||||
|
||||
c.Client.Set("role", selected, "master")
|
||||
if err := c.Client.Set("role", selected, "master"); err != nil {
|
||||
return err
|
||||
}
|
||||
c.Logger.Info("-> Set master to", selected)
|
||||
currentRoles[selected] = "master"
|
||||
// Return here, so next time we get called
|
||||
@@ -65,7 +67,10 @@ func scheduleRoles(nodes []string, c *service.RoleConfig, cc *config.Config, pco
|
||||
|
||||
// cycle all empty roles and assign worker roles
|
||||
for _, uuid := range unassignedNodes {
|
||||
c.Client.Set("role", uuid, "worker")
|
||||
if err := c.Client.Set("role", uuid, "worker"); err != nil {
|
||||
c.Logger.Error(err)
|
||||
return err
|
||||
}
|
||||
c.Logger.Info("-> Set worker to", uuid)
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,9 @@ func Worker(cc *config.Config, pconfig *providerConfig.Config) Role {
|
||||
if pconfig.C3OS.Role != "" {
|
||||
// propagate role if we were forced by configuration
|
||||
// This unblocks eventual auto instances to try to assign roles
|
||||
c.Client.Set("role", c.UUID, pconfig.C3OS.Role)
|
||||
if err := c.Client.Set("role", c.UUID, pconfig.C3OS.Role); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if SentinelExist() {
|
||||
@@ -106,8 +108,6 @@ func Worker(cc *config.Config, pconfig *providerConfig.Config) Role {
|
||||
return err
|
||||
}
|
||||
|
||||
CreateSentinel()
|
||||
|
||||
return nil
|
||||
return CreateSentinel()
|
||||
}
|
||||
}
|
||||
|
@@ -12,15 +12,15 @@ import (
|
||||
|
||||
func Reboot() {
|
||||
pterm.Info.Println("Rebooting node")
|
||||
SH("reboot")
|
||||
SH("reboot") //nolint:errcheck
|
||||
}
|
||||
|
||||
func PowerOFF() {
|
||||
pterm.Info.Println("Shutdown node")
|
||||
if IsOpenRCBased() {
|
||||
SH("poweroff")
|
||||
SH("poweroff") //nolint:errcheck
|
||||
} else {
|
||||
SH("shutdown")
|
||||
SH("shutdown") //nolint:errcheck
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user