Skip to content

Commit

Permalink
feat(kumactl) add install loki for log aggregation
Browse files Browse the repository at this point in the history
Add the Loki stack to `kumactl install` allowing to see logs
directly in Grafana. The yaml for loki was inspired by:
`https://grafana.github.io/loki/charts`

* Add a new install command to kubectl:
  `kubectl install logging`
* Upgrate Grafana version to 7.0.3 that accepts loki as a
  data source.
  • Loading branch information
xbauquet committed Jun 15, 2020
1 parent 9d9d764 commit 6a406c4
Show file tree
Hide file tree
Showing 13 changed files with 1,080 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/kumactl/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ func NewInstallCmd(pctx *kumactl_cmd.RootContext) *cobra.Command {
cmd.AddCommand(newInstallMetrics())
cmd.AddCommand(newInstallTracing())
cmd.AddCommand(newInstallDNS())
cmd.AddCommand(newInstallLogging())
return cmd
}
53 changes: 53 additions & 0 deletions app/kumactl/cmd/install/install_logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package install

import (
"github.com/Kong/kuma/app/kumactl/pkg/install/data"
"github.com/Kong/kuma/app/kumactl/pkg/install/k8s"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/Kong/kuma/app/kumactl/pkg/install/k8s/logging"
)

type loggingTemplateArgs struct {
Namespace string
}

func newInstallLogging() *cobra.Command {
args := struct {
Namespace string
}{
Namespace: "kuma-logging",
}
cmd := &cobra.Command{
Use: "logging",
Short: "Install Logging backend in Kubernetes cluster (Loki)",
Long: `Install Logging backend in Kubernetes cluster (Loki) in a 'kuma-logging' namespace`,
RunE: func(cmd *cobra.Command, _ []string) error {
templateArgs := loggingTemplateArgs{
Namespace: args.Namespace,
}

templateFiles, err := data.ReadFiles(logging.Templates)
if err != nil {
return errors.Wrap(err, "Failed to read template files")
}

renderedFiles, err := renderFiles(templateFiles, templateArgs, simpleTemplateRenderer)
if err != nil {
return errors.Wrap(err, "Failed to render template files")
}

sortedResources := k8s.SortResourcesByKind(renderedFiles)

singleFile := data.JoinYAML(sortedResources)

if _, err := cmd.OutOrStdout().Write(singleFile.Data); err != nil {
return errors.Wrap(err, "Failed to output rendered resources")
}
return nil
},
}
cmd.Flags().StringVar(&args.Namespace, "namespace", args.Namespace, "namespace to install logging to")
return cmd
}
Loading

0 comments on commit 6a406c4

Please sign in to comment.