Skip to content

Commit

Permalink
Merge pull request #2052 from replicatedhq/divolgin/logging
Browse files Browse the repository at this point in the history
Send k8s logs to a file
  • Loading branch information
divolgin committed Aug 6, 2021
2 parents 3b42eb2 + 5717759 commit 05ca1e3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 120 deletions.
13 changes: 13 additions & 0 deletions cmd/kots/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cli
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
Expand All @@ -18,6 +19,8 @@ import (
"github.com/replicatedhq/kots/pkg/util"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/grpc/grpclog"
"k8s.io/klog/v2"
)

func RunCmd() *cobra.Command {
Expand All @@ -42,6 +45,16 @@ func RunCmd() *cobra.Command {
log := logger.NewCLILogger()
log.Info("Running application %s", slug)

k8sLogRoot := filepath.Join(v.GetString("data-dir"), "kubernetes", "log")
if err := os.MkdirAll(k8sLogRoot, 0755); err == nil {
if f, err := ioutil.TempFile(k8sLogRoot, "k8s-"); err == nil {
defer f.Close()
grpclog.SetLoggerV2(grpclog.NewLoggerV2(f, f, f))
klog.SetOutput(f)
klog.LogToStderr(false)
}
}

// TODO: @emosbaugh: im not sure i agree with this pattern. im not sure context is the best place for DI
loggerCtx := context.WithValue(context.Background(), "log", log)
ctx, cancelFunc := context.WithCancel(loggerCtx)
Expand Down
18 changes: 5 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,25 @@ require (
github.com/Azure/go-autorest/autorest/adal v0.9.5
github.com/Masterminds/semver v1.5.0
github.com/Masterminds/semver/v3 v3.1.1
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/Masterminds/sprig/v3 v3.2.2
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/ahmetalpbalkan/go-cursor v0.0.0-20131010032410-8136607ea412
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/aws/aws-sdk-go v1.38.2
github.com/bitnami-labs/sealed-secrets v0.14.1
github.com/blang/semver v3.5.1+incompatible
github.com/briandowns/spinner v1.12.0 // indirect
github.com/bshuster-repo/logrus-logstash-hook v0.4.1 // indirect
github.com/bugsnag/bugsnag-go v1.5.3 // indirect
github.com/bugsnag/panicwrap v1.2.0 // indirect
github.com/containerd/containerd v1.4.4
github.com/containers/image/v5 v5.10.4
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/deislabs/oras v0.11.1
github.com/denisbrodbeck/machineid v1.0.1 // indirect
github.com/dexidp/dex v0.0.0-20201105145354-71bbbee07527
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/distribution v2.7.1+incompatible
github.com/docker/go-units v0.4.0
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.10.0
github.com/foomo/htpasswd v0.0.0-20200116085101-e3a90e78da9c // indirect
github.com/frankban/quicktest v1.13.0 // indirect
github.com/garyburd/redigo v1.6.0 // indirect
github.com/ghodss/yaml v1.0.0
Expand All @@ -51,19 +46,16 @@ require (
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/huandu/xstrings v1.3.2 // indirect
github.com/itchyny/gojq v0.12.2 // indirect
github.com/k3s-io/kine v0.6.1
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/lib/pq v1.10.2
github.com/manifoldco/promptui v0.8.0
github.com/marccampbell/yaml-toolbox v0.0.0-20200805160637-950ceb36c770
github.com/mattn/go-isatty v0.0.12
github.com/mattn/go-sqlite3 v1.14.8 // indirect
github.com/mattn/go-sqlite3 v1.14.8
github.com/mholt/archiver v3.1.1+incompatible
github.com/nwaples/rardecode v1.0.0 // indirect
github.com/open-policy-agent/opa v0.24.0
github.com/replicatedhq/kurl v0.0.0-20210414162418-8d6211901244
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
github.com/openshift/api v0.0.0-20210513192832-efee9960e6fd // indirect
github.com/openshift/client-go v0.0.0-20210503124028-ac0910aac9fa
Expand All @@ -74,15 +66,15 @@ require (
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/rancher/wrangler v0.8.3
github.com/replicatedhq/kurl v0.0.0-20210414162418-8d6211901244
github.com/replicatedhq/troubleshoot v0.13.7
github.com/replicatedhq/yaml/v3 v3.0.0-beta5-replicatedhq
github.com/robfig/cron v1.2.0
github.com/robfig/cron/v3 v3.0.1
github.com/russellhaering/goxmldsig v1.1.0 // indirect
github.com/schemahero/schemahero v0.12.2 // indirect
github.com/schemahero/schemahero v0.12.2
github.com/segmentio/ksuid v1.0.3
github.com/sergi/go-diff v1.1.0
github.com/spf13/afero v1.5.1 // indirect
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
Expand All @@ -97,13 +89,12 @@ require (
go.uber.org/multierr v1.6.0
go.uber.org/zap v1.17.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
google.golang.org/api v0.22.0
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.38.0
gopkg.in/go-playground/assert.v1 v1.2.1
gopkg.in/ini.v1 v1.51.0
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gotest.tools v2.2.0+incompatible
Expand All @@ -115,6 +106,7 @@ require (
k8s.io/client-go v0.21.3
k8s.io/cluster-bootstrap v0.21.3
k8s.io/helm v2.14.3+incompatible
k8s.io/klog/v2 v2.8.0
k8s.io/kubelet v0.0.0
k8s.io/kubernetes v1.21.3
k8s.io/utils v0.0.0-20210305010621-2afb4311ab10
Expand Down

0 comments on commit 05ca1e3

Please sign in to comment.