forked from k3s-io/k3s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.go
43 lines (33 loc) · 926 Bytes
/
agent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package agent
import (
"context"
"fmt"
"os"
"github.com/rancher/k3s/pkg/agent"
"github.com/rancher/k3s/pkg/cli/cmds"
"github.com/rancher/norman/pkg/resolvehome"
"github.com/rancher/norman/signal"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func Run(ctx *cli.Context) error {
if os.Getuid() != 0 {
return fmt.Errorf("agent must be ran as root")
}
if cmds.AgentConfig.Token == "" && cmds.AgentConfig.ClusterSecret == "" {
return fmt.Errorf("--token is required")
}
if cmds.AgentConfig.ServerURL == "" {
return fmt.Errorf("--server is required")
}
logrus.Infof("Starting k3s agent %s", ctx.App.Version)
dataDir, err := resolvehome.Resolve(cmds.AgentConfig.DataDir)
if err != nil {
return err
}
cfg := cmds.AgentConfig
cfg.Debug = ctx.GlobalBool("debug")
cfg.DataDir = dataDir
contextCtx := signal.SigTermCancelContext(context.Background())
return agent.Run(contextCtx, cfg)
}