/
loki_app.go
101 lines (75 loc) · 3.16 KB
/
loki_app.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
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) arkade author(s) 2022. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package apps
import (
"log"
"github.com/alexellis/arkade/pkg"
"github.com/alexellis/arkade/pkg/apps"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/types"
"github.com/spf13/cobra"
)
func MakeInstallLoki() *cobra.Command {
var lokiApp = &cobra.Command{
Use: "loki",
Short: "Install Loki for monitoring and tracing",
Long: "Install Loki, part of the Grafana products for Logging and Tracing",
Example: "arkade install loki",
SilenceUsage: true,
}
lokiApp.Flags().StringP("namespace", "n", "default", "The namespace to install loki (default: default")
lokiApp.Flags().Bool("update-repo", true, "Update the helm repo")
lokiApp.Flags().Bool("persistence", false, "Use a 10Gi Persistent Volume to store data")
lokiApp.Flags().StringArray("set", []string{}, "Use custom flags or override existing flags \n(example --set grafana.enabled=true)")
lokiApp.Flags().Bool("grafana", false, "Install Grafana alongside Loki (default: false)")
lokiApp.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath, _ := command.Flags().GetString("kubeconfig")
log.Println(kubeConfigPath)
namespace, _ := lokiApp.Flags().GetString("namespace")
persistence, _ := lokiApp.Flags().GetBool("persistence")
installGrafana, _ := lokiApp.Flags().GetBool("grafana")
updateRepo, _ := lokiApp.Flags().GetBool("update-repo")
overrides := map[string]string{}
if installGrafana {
overrides["grafana.enabled"] = "true"
}
if persistence {
overrides["loki.persistence.enabled"] = "true"
}
customFlags, _ := command.Flags().GetStringArray("set")
if err := config.MergeFlags(overrides, customFlags); err != nil {
return err
}
lokiOptions := types.DefaultInstallOptions().
WithNamespace(namespace).
WithHelmRepo("grafana/loki-stack").
WithHelmURL("https://grafana.github.io/helm-charts").
WithHelmUpdateRepo(updateRepo).
WithOverrides(overrides).
WithKubeconfigPath(kubeConfigPath)
_, err := apps.MakeInstallChart(lokiOptions)
if err != nil {
return err
}
println(lokiInstallMsg)
return nil
}
return lokiApp
}
const LokiInfoMsg = `# Get started with loki here:
# https://grafana.com/docs/loki/latest
# See how to integrate loki with Grafana here
# https://grafana.com/docs/loki/latest/getting-started/grafana
# Check loki's logs with:
kubectl logs svc/loki-stack
kubectl logs svc/loki-stack-headless
# If you installed with Grafana you can access the dashboard with the username "admin" and password shown below
# To get password
kubectl get secret loki-stack-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
# Forward traffic to your localhost
kubectl port-forward service/loki-stack-grafana 3000:80
`
const lokiInstallMsg = `=======================================================================
= loki has been installed. =
=======================================================================` +
"\n\n" + LokiInfoMsg + "\n\n" + pkg.SupportMessageShort