Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Mar 20, 2022
0 parents commit a930611
Show file tree
Hide file tree
Showing 10 changed files with 1,246 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#

name: release

on:
push:
tags:
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17.8
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 34 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
# they are unable to install libraries.
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- freebsd
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
binary: '{{ .ProjectName }}'
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
release:
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Christoph Mewes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# loks - Collect Kubernetes Pod Logs with Ease

`loks` is a command line tool to watch for pods and storing their logs as text files
on your local machine. It's primarily intended to be used in test scenarios where you
need to gather logs of many different, possibly restarting or reconciled pods at the
same time.

## Installation

You can download a binary for the [latest release on GitHub](https://github.com/xrstf/loks/releases)
or install loks via Go:

```bash
go install go.xrstf.de/loks
```

## Usage

```
Usage of ./loks:
-c, --container stringArray Container names to store logs for (supports glob expression) (can be given multiple times)
-f, --flat Do not create directory per namespace, but put all logs in the same directory
--kubeconfig string kubeconfig file to use (uses $KUBECONFIG by default)
-l, --labels string Label-selector as an alternative to specifying resource names
-n, --namespace stringArray Kubernetes namespace to watch resources in (supports glob expression) (can be given multiple times)
-o, --output string Directory where logs should be stored
-v, --verbose Enable more verbose output
```

## Examples

```bash
loks '*'
```

This is the BFG: it will watch all Pods in all namespaces and stream the logs for each running container to
a text file in your disk. Don't do this, you do not want to kill the apiserver with a gazillion streams.

```bash
loks -n kube-system -n 'cluster-*'
```

You can restrict the Pods to a set of namespaces. Wildcards are allowed.

```bash
loks -l 'foo=bar'
```

Label selectors work just as you would expect.

```bash
loks 'kube-*' 'coredns-*' 'etcd-*'
```

You can give multiple name patterns, placeholders are allowed.

```bash
loks -c 'test*' 'kube-*' 'coredns-*' 'etcd-*'
```

You can restrict the container names using `-c`. This flag can be given multiple times and also supports wildcards.

```bash
loks -o test 'kube-*' 'coredns-*' 'etcd-*'
```

By default loks will create a `loks-%Y%m%dT%m.%h%s` directory whenever you invoke it, but you can also specify
a directory yourself.

```bash
loks -o test -f 'kube-*' 'coredns-*' 'etcd-*'
```

By default loks will create one directory per namespace. With `-f` (`--flat`) you can disable this behaviour.

## License

MIT
42 changes: 42 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module go.xrstf.de/loks

go 1.17

require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/pflag v1.0.5
k8s.io/api v0.23.4
k8s.io/apimachinery v0.23.4
k8s.io/client-go v0.23.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit a930611

Please sign in to comment.