Skip to content

Commit 8d3ede2

Browse files
committed
feat: only log default container
1 parent a94bd62 commit 8d3ede2

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

internal/run.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"time"
2727
)
2828

29-
func Run(ctx context.Context, group, namespace, labels string, hostPortOffset int) error {
29+
func Run(ctx context.Context, group, namespace, labels, container string, allContainers bool, hostPortOffset int) error {
3030
// connect to the k8s cluster
3131
kubeConfig := os.Getenv("KUBECONFIG")
3232
if kubeConfig == "" {
@@ -161,11 +161,21 @@ func Run(ctx context.Context, group, namespace, labels string, hostPortOffset in
161161
running[s.Name] = s.State.Running != nil
162162
}
163163

164+
if container == "" {
165+
container = pod.Annotations["kubectl.kubernetes.io/default-container"]
166+
}
167+
164168
for _, ctr := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
165169
// skip containers that are not running
166170
if !running[ctr.Name] {
167171
continue
168172
}
173+
174+
// skip containers that are not the one we want to watch
175+
if !allContainers && ctr.Name != container {
176+
continue
177+
}
178+
169179
out := colorWriter("pods", fmt.Sprintf("[pods/%s] %s: ", pod.Name, ctr.Name))
170180
go func() {
171181
// start a log tail

main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import (
1111
)
1212

1313
func main() {
14-
var namespace, labels, group string
14+
var namespace, labels, group, container string
15+
var allContainers bool
1516
var hostPortOffset int
1617
var help bool
1718
var version bool
1819
flag.StringVar(&namespace, "n", "", "namespace to filter resources, defaults to the current namespace ")
1920
flag.StringVar(&labels, "l", "", "comma separated list of labels to filter resources, e.g. app=nginx, defaults to all resources")
2021
flag.StringVar(&group, "g", "", "the group to watch, defaults to core resources")
21-
flag.IntVar(&hostPortOffset, "p", 0, "the offset to add to the host port, e.g. if the container listens on 8080 and the host port is 30000, the offset is 38080, defaults to 0")
22+
flag.StringVar(&container, "c", "", "the container to show logs for, defaults to the annotation")
23+
flag.BoolVar(&allContainers, "a", false, "show logs for all containers")
24+
flag.IntVar(&hostPortOffset, "p", 0, "the offset to add to the host port, e.g. if the container listens on 8080 and the host port is 30000, the offset is 38080")
2225
flag.BoolVar(&help, "h", false, "print help")
2326
flag.BoolVar(&version, "v", false, "print version")
2427
flag.Parse()
@@ -37,7 +40,7 @@ func main() {
3740
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
3841
defer cancel()
3942

40-
if err := internal.Run(ctx, group, namespace, labels, hostPortOffset); err != nil {
43+
if err := internal.Run(ctx, group, namespace, labels, container, allContainers, hostPortOffset); err != nil {
4144
panic(err)
4245
}
4346
}

release

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
#!/bin/sh
2-
set -eux -o pipefail
2+
set -eu -o pipefail
33

44
go install github.com/ffurrer2/semver/v2/cmd/semver@latest
5-
git tag v$(semver next patch $(git tag|sort -V|tail -n1|cut -c 2-))
5+
6+
previous_version=$(git tag|sort -V|tail -n1|cut -c 2-)
7+
new_version=v$(semver next patch $previous_version)
8+
9+
echo "$previous_version -> $new_version"
10+
11+
# replace the previous version with the new version in README.md
12+
sed -i '' "s|$previous_version|$new_version|" README.md
13+
14+
git reset
15+
git add README.md
16+
git commit -m 'docs: update version in README'
17+
18+
git tag $new_version
19+
620
git push --tags

0 commit comments

Comments
 (0)