-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(kumactl) add install loki for log aggregation #820
Merged
nickolaev
merged 7 commits into
kumahq:master
from
xbauquet:feat/kumactl-install-logging
Jul 6, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ae5673
feat(kumactl) add install loki for log aggregation
xbauquet 4422335
tests(kumactl) tests for kumactl install logging
xbauquet 62ecdb4
fix(data-planes) access log missing new line
xbauquet 56f522a
refactor(kumactl) order imports
xbauquet 19cb442
tests(data-planes) fix access logs tests
xbauquet abd5171
feat(kumactl): bump grafana version to 7.0.5
xbauquet 001c29b
Merge remote-tracking branch 'kuma/master' into feat/kumactl-install-…
xbauquet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package install | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/Kong/kuma/app/kumactl/pkg/install/data" | ||
"github.com/Kong/kuma/app/kumactl/pkg/install/k8s" | ||
|
||
"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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package install_test | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
kuma_version "github.com/Kong/kuma/pkg/version" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/Kong/kuma/app/kumactl/cmd" | ||
"github.com/Kong/kuma/app/kumactl/pkg/install/data" | ||
) | ||
|
||
var _ = Describe("kumactl install logging", func() { | ||
|
||
var stdout *bytes.Buffer | ||
var stderr *bytes.Buffer | ||
|
||
BeforeEach(func() { | ||
stdout = &bytes.Buffer{} | ||
stderr = &bytes.Buffer{} | ||
}) | ||
|
||
type testCase struct { | ||
extraArgs []string | ||
goldenFile string | ||
} | ||
|
||
BeforeEach(func() { | ||
kuma_version.Build = kuma_version.BuildInfo{ | ||
Version: "0.0.1", | ||
GitTag: "v0.0.1", | ||
GitCommit: "91ce236824a9d875601679aa80c63783fb0e8725", | ||
BuildDate: "2019-08-07T11:26:06Z", | ||
} | ||
}) | ||
|
||
DescribeTable("should generate Kubernetes resources", | ||
func(given testCase) { | ||
// given | ||
rootCmd := cmd.DefaultRootCmd() | ||
rootCmd.SetArgs(append([]string{"install", "logging"}, given.extraArgs...)) | ||
rootCmd.SetOut(stdout) | ||
rootCmd.SetErr(stderr) | ||
|
||
// when | ||
err := rootCmd.Execute() | ||
// then | ||
Expect(err).ToNot(HaveOccurred()) | ||
// and | ||
Expect(stderr.Bytes()).To(BeNil()) | ||
|
||
// when | ||
expected, err := ioutil.ReadFile(filepath.Join("testdata", given.goldenFile)) | ||
// then | ||
Expect(err).ToNot(HaveOccurred()) | ||
// and | ||
expectedManifests := data.SplitYAML(data.File{Data: expected}) | ||
|
||
// when | ||
actual := stdout.Bytes() | ||
// then | ||
Expect(actual).To(MatchYAML(expected)) | ||
// and | ||
actualManifests := data.SplitYAML(data.File{Data: actual}) | ||
|
||
// and | ||
Expect(len(actualManifests)).To(Equal(len(expectedManifests))) | ||
// and | ||
for i := range expectedManifests { | ||
Expect(actualManifests[i]).To(MatchYAML(expectedManifests[i])) | ||
} | ||
}, | ||
Entry("should generate Kubernetes resources with default settings", testCase{ | ||
extraArgs: nil, | ||
goldenFile: "install-logging.defaults.golden.yaml", | ||
}), | ||
Entry("should generate Kubernetes resources with custom settings", testCase{ | ||
extraArgs: []string{ | ||
"--namespace", "kuma", | ||
}, | ||
goldenFile: "install-logging.overrides.golden.yaml", | ||
}), | ||
) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakubdyszkiewicz what do you think?