mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-25 13:33:41 +00:00
Split off cli into separate binaries (#37)
* 🎨 Split off cli into separate binaries This commit splits off the cli into 3 binaries: - agent - cli - provider The provider now is a separate component that can be tested by itself and have its own lifecycle. This paves the way to a ligher c3os variant, HA support and other features that can be provided on runtime. This is working, but still there are low hanging fruit to care about. Fixes #14 * 🤖 Add provider bin to releases * ⚙️ Handle signals * ⚙️ Reduce buildsize footprint * 🎨 Scan for providers also in /system/providers * 🤖 Run goreleaser * 🎨 Refactoring
This commit is contained in:
committed by
Itxaka
parent
74bfd373db
commit
63cd28d1cb
108
internal/role/worker.go
Normal file
108
internal/role/worker.go
Normal file
@@ -0,0 +1,108 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/c3os-io/c3os/internal/machine"
|
||||
"github.com/c3os-io/c3os/internal/utils"
|
||||
"github.com/c3os-io/c3os/pkg/config"
|
||||
|
||||
service "github.com/mudler/edgevpn/api/client/service"
|
||||
)
|
||||
|
||||
func Worker(cc *config.Config) Role {
|
||||
return func(c *service.RoleConfig) error {
|
||||
|
||||
if cc.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, cc.C3OS.Role)
|
||||
}
|
||||
|
||||
if SentinelExist() {
|
||||
c.Logger.Info("Node already configured, backing off")
|
||||
return nil
|
||||
}
|
||||
|
||||
masterIP, _ := c.Client.Get("master", "ip")
|
||||
if masterIP == "" {
|
||||
c.Logger.Info("MasterIP not there still..")
|
||||
return nil
|
||||
}
|
||||
|
||||
nodeToken, _ := c.Client.Get("nodetoken", "token")
|
||||
if masterIP == "" {
|
||||
c.Logger.Info("nodetoken not there still..")
|
||||
return nil
|
||||
}
|
||||
|
||||
nodeToken = strings.TrimRight(nodeToken, "\n")
|
||||
|
||||
ip := utils.GetInterfaceIP("edgevpn0")
|
||||
if ip == "" {
|
||||
return errors.New("node doesn't have an ip yet")
|
||||
}
|
||||
|
||||
c.Logger.Info("Configuring k3s-agent", ip, masterIP, nodeToken)
|
||||
|
||||
svc, err := machine.K3sAgent()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
k3sConfig := config.K3s{}
|
||||
if cc.K3sAgent.Enabled {
|
||||
k3sConfig = cc.K3sAgent
|
||||
}
|
||||
|
||||
env := map[string]string{
|
||||
"K3S_URL": fmt.Sprintf("https://%s:6443", masterIP),
|
||||
"K3S_TOKEN": nodeToken,
|
||||
}
|
||||
|
||||
if !k3sConfig.ReplaceEnv {
|
||||
// Override opts with user-supplied
|
||||
for k, v := range k3sConfig.Env {
|
||||
env[k] = v
|
||||
}
|
||||
} else {
|
||||
env = k3sConfig.Env
|
||||
}
|
||||
|
||||
// Setup systemd unit and starts it
|
||||
if err := utils.WriteEnv(machine.K3sEnvUnit("k3s-agent"),
|
||||
env,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"--with-node-id",
|
||||
fmt.Sprintf("--node-ip %s", ip),
|
||||
"--flannel-iface=edgevpn0",
|
||||
}
|
||||
if k3sConfig.ReplaceArgs {
|
||||
args = k3sConfig.Args
|
||||
} else {
|
||||
args = append(args, k3sConfig.Args...)
|
||||
}
|
||||
|
||||
if err := svc.OverrideCmd(fmt.Sprintf("/usr/bin/k3s agent %s", strings.Join(args, " "))); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := svc.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := svc.Enable(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
CreateSentinel()
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user