forked from alexellis/arkade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathof_loki.go
92 lines (70 loc) · 3.45 KB
/
of_loki.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
// Copyright (c) arkade author(s) 2020. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package apps
import (
"fmt"
"github.com/alexellis/arkade/pkg/k8s"
"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 MakeInstallOpenFaaSLoki() *cobra.Command {
var OpenFaaSlokiApp = &cobra.Command{
Use: "openfaas-loki",
Short: "Install Loki-OpenFaaS and Configure Loki logs provider for OpenFaaS",
Long: "Install Loki-OpenFaaS and Configure Loki logs provider for OpenFaaS",
Example: "arkade install openfaas-loki",
SilenceUsage: true,
}
OpenFaaSlokiApp.Flags().StringP("namespace", "n", "default", "The namespace to install loki (default: default")
OpenFaaSlokiApp.Flags().Bool("update-repo", true, "Update the helm repo")
OpenFaaSlokiApp.Flags().String("openfaas-namespace", "openfaas", "set the namespace that OpenFaaS is installed into")
OpenFaaSlokiApp.Flags().String("loki-url", "http://loki-stack.default:3100", "set the loki url (default http://loki-stack.default:3100)")
OpenFaaSlokiApp.Flags().StringArray("set", []string{}, "Use custom flags or override existing flags \n(example --set grafana.enabled=true)")
OpenFaaSlokiApp.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath, _ := command.Flags().GetString("kubeconfig")
namespace, _ := OpenFaaSlokiApp.Flags().GetString("namespace")
openfaasNamespace, _ := OpenFaaSlokiApp.Flags().GetString("openfaas-namespace")
lokiURL, _ := OpenFaaSlokiApp.Flags().GetString("loki-url")
overrides := map[string]string{}
overrides["lokiURL"] = lokiURL
customFlags, _ := command.Flags().GetStringArray("set")
if err := config.MergeFlags(overrides, customFlags); err != nil {
return err
}
lokiOptions := types.DefaultInstallOptions().
WithNamespace(namespace).
WithHelmRepo("lucas/openfaas-loki").
WithHelmURL("https://lucasroesler.com/openfaas-loki").
WithOverrides(overrides).
WithKubeconfigPath(kubeConfigPath)
_, err := apps.MakeInstallChart(lokiOptions)
if err != nil {
return err
}
// Post install config of openfaas-loki
k8s.Kubectl("-n", openfaasNamespace,
"set", "env", "deployment/gateway",
"-c", "gateway",
"-e", fmt.Sprintf("logs_provider_url=http://openfaas-loki.%s:9191/", namespace))
println(lokiOFInstallMsg)
return nil
}
return OpenFaaSlokiApp
}
const LokiOFInfoMsg = `# Get started with openfaas-loki here:
# If you are authenticated with your openfaas gateway
faas-cli logs
# If you installed loki with grafana, with 'arkade install loki --grafana'
# You can use the grafana dashboard to see the OpenFaaS Logs, you can see
# how to get your grafana password with 'arkade info loki'
# We have automatically configured OpenFaaS to use the Loki logs URL, you can set 'gateway.logsProviderURL'
# When installing openfaas with Helm or use the '--log-provider-url' flag in arkade.
# The url is in the format 'http://loki-stack.namespace:3100/' (where namespace is the installed namespace for loki-stack)
`
const lokiOFInstallMsg = `=======================================================================
= OpenFaaS loki has been installed. =
=======================================================================` +
"\n\n" + LokiOFInfoMsg + "\n\n" + pkg.ThanksForUsing