-
Notifications
You must be signed in to change notification settings - Fork 165
/
install.go
90 lines (70 loc) · 2.54 KB
/
install.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package k3s
import (
"os"
"github.com/defenseunicorns/zarf/cli/config"
"github.com/defenseunicorns/zarf/cli/internal/git"
"github.com/defenseunicorns/zarf/cli/internal/packager"
"github.com/defenseunicorns/zarf/cli/internal/utils"
"github.com/sirupsen/logrus"
)
type InstallOptions struct {
PKI utils.PKIConfig
Confirmed bool
Components string
}
func Install(options InstallOptions) {
utils.RunPreflightChecks()
logrus.Info("Installing K3s")
packager.Deploy(config.PackageInitName, options.Confirmed, options.Components)
// Install RHEL RPMs if applicable
if utils.IsRHEL() {
configureRHEL()
}
// Create the K3s systemd service
createService()
createK3sSymlinks()
utils.HandlePKI(options.PKI)
gitSecret := git.GetOrCreateZarfSecret()
// Now that we have what the password will be, we should add the login entry to the system's registry config
err := utils.Login(config.ZarfLocalIP, config.ZarfGitUser, gitSecret)
if err != nil {
logrus.Debug(err)
logrus.Fatal("Unable to add login credentials for the utility registry")
}
logrus.Info("Installation complete. You can run \"/usr/local/bin/k9s\" to monitor the status of the deployment.")
logrus.WithFields(logrus.Fields{
"Gitea Username (if installed)": config.ZarfGitUser,
"Grafana Username": "zarf-admin",
"Password (all)": gitSecret,
}).Warn("Credentials stored in ~/.git-credentials")
}
func createK3sSymlinks() {
logrus.Info("Creating kube config symlink")
// Make the k3s kubeconfig available to other standard K8s tools that bind to the default ~/.kube/config
err := utils.CreateDirectory("/root/.kube", 0700)
if err != nil {
logrus.Debug(err)
logrus.Warn("Unable to create the root kube config directory")
} else {
// Dont log an error for now since re-runs throw an invalid error
_ = os.Symlink("/etc/rancher/k3s/k3s.yaml", "/root/.kube/config")
}
// Add aliases for k3s
_ = os.Symlink(config.K3sBinary, "/usr/local/bin/kubectl")
_ = os.Symlink(config.K3sBinary, "/usr/local/bin/ctr")
_ = os.Symlink(config.K3sBinary, "/usr/local/bin/crictl")
}
func createService() {
servicePath := "/etc/systemd/system/k3s.service"
_ = os.Symlink(servicePath, "/etc/systemd/system/multi-user.target.wants/k3s.service")
_, err := utils.ExecCommand(nil, "systemctl", "daemon-reload")
if err != nil {
logrus.Debug(err)
logrus.Warn("Unable to reload systemd")
}
_, err = utils.ExecCommand(nil, "systemctl", "enable", "--now", "k3s")
if err != nil {
logrus.Debug(err)
logrus.Warn("Unable to enable or start k3s via systemd")
}
}