-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.go
46 lines (43 loc) · 1.07 KB
/
logs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package deployments
import (
"fmt"
"github.com/angelokurtis/kts-cli/internal/log"
"github.com/angelokurtis/kts-cli/pkg/app/kubectl"
"github.com/gookit/color"
"github.com/spf13/cobra"
"strings"
)
// kube deployments logs -s 2h
func logs(cmd *cobra.Command, args []string) {
deploys, err := kubectl.ListDeployments(namespace, allNamespaces)
if err != nil {
log.Fatal(err)
}
deploy, err := deploys.SelectOne()
if err != nil {
log.Fatal(err)
}
if download {
containers, err := kubectl.ListContainersByDeployment(deploy)
if err != nil {
log.Fatal(err)
}
kubectl.SaveLogs(containers, since, previous)
} else {
follow(deploy, since)
}
}
func follow(deploy *kubectl.Deployment, since string) {
ns := fmt.Sprintf("-n %s", deploy.Metadata.Namespace)
labels := make([]string, 0, 0)
for key, value := range deploy.Spec.Selector.MatchLabels {
labels = append(labels, key+"="+value)
}
if since == "0s" {
since = ""
} else {
since = "--since " + since
}
cmd := fmt.Sprintf("stern %s -l %s %s", ns, strings.Join(labels, ","), since)
color.Secondary.Println(cmd)
}