Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

gardenctl logs tf fix #185

Merged
merged 2 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ Targets represent a hierarchical structure of resources. On top, there is/are th
`gardenctl logs etcd-main --elasticsearch`
- Show last 100 logs from elasticsearch from the last 2 hours
`gardenctl logs etcd-main --elasticsearch --since=2h --tail=100`
- Show logs from seed nodes
`gardenctl target -g garden-name -s seed-name`
`gardenctl logs tf infra shoot-name`
- Show logs from shoot nodes
`gardenctl target -g garden-name -t shoot-name`
`gardenctl logs api | scheduler | controller-manager | etcd-main -c etcd |etcd-main -c backup-restore | vpn-seed | vpn-shoot | machine-controller-manager | prometheus |grafana | alertmanager | cluster-autoscaler`
- Show logs from garden nodes
`gardenctl target -g garden-name`
`gardenctl logs gardener-apiserver | gardener-controller-manager`

## Advanced usage based on JsonQuery

Expand Down
33 changes: 19 additions & 14 deletions pkg/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewLogsCmd() *cobra.Command {
}

func validateArgs(args []string) {
if len(args) < 1 || len(args) > 2 {
if len(args) < 1 || len(args) > 3 {
fmt.Println("Command must be in the format: logs (gardener-apiserver|gardener-controller-manager|gardener-dashboard|api|scheduler|controller-manager|etcd-operator|etcd-main[etcd backup-restore]|etcd-events[etcd backup-restore]|addon-manager|vpn-seed|vpn-shoot|machine-controller-manager|kubernetes-dashboard|prometheus|grafana|alertmanager|tf (infra|dns|ingress)|cluster-autoscaler flags(--elasticsearch|--tail|--since|--since-time|--timestamps)")
os.Exit(2)
}
Expand Down Expand Up @@ -156,17 +156,22 @@ func runCommand(args []string) {
case "cluster-autoscaler":
logsClusterAutoscaler()
case "tf":
if len(args) == 1 {
logsTf()
if len(args) == 1 || len(args) < 3 {
logsTfHelp()
break
}

var prefixName string = (args[02])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also check if shoot name exists and please use args[2]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my understanding, so far the logic for logs tf will fetch all podName and podNamespace from a seed node, then match infra.tf from List output to found the pod name.
It takes about at least 11M List output data when I testing, depends on the total of shoots host in the seed node.
To check shoot name whether exists, it maybe double the times for the result output. search shoot name from List output ->exist -> search infra.tf from List output to found the pod name. Let me know any concerns. thanks

https://github.com/gardener/gardenctl/blob/f68840200614710714ba6df3cdc7626ea4be7ecc/pkg/cmd/logs.go#L506-L522

switch args[1] {
case "infra":
logsInfra()
str := prefixName + ".infra.tf"
logsInfra(str)
case "dns":
logsDNS()
str := prefixName + ".dns.tf"
logsDNS(str)
case "ingress":
logsIngress()
str := prefixName + ".ingress.tf"
logsIngress(str)
default:
fmt.Println("Command must be in the format: logs (gardener-apiserver|gardener-controller-manager|gardener-dashboard|api|scheduler|controller-manager|etcd-operator|etcd-main[etcd backup-restore]|etcd-events[etcd backup-restore]|addon-manager|vpn-seed|vpn-shoot|auto-node-repair|kubernetes-dashboard|prometheus|grafana|alertmanager|tf (infra|dns|ingress)|cluster-autoscaler)")
}
Expand Down Expand Up @@ -535,23 +540,23 @@ func logsTerraform(toMatch string) {
}

// logsTf prints the logfiles of tf job
func logsTf() {
logsTerraform("tf-job")
func logsTfHelp() {
fmt.Println("Command must be in the format: logs tf (infra|dns|ingress) shoot name")
}

// logsInfra prints the logfiles of tf infra job
func logsInfra() {
logsTerraform("infra.tf-job")
func logsInfra(str string) {
logsTerraform(str)
}

// logsDNS prints the logfiles of tf dns job
func logsDNS() {
logsTerraform("dns.tf-job")
func logsDNS(str string) {
logsTerraform(str)
}

// logsIngress prints the logfiles of tf ingress job
func logsIngress() {
logsTerraform("ingress.tf-job")
func logsIngress(str string) {
logsTerraform(str)
}

type logFlags struct {
Expand Down