Skip to content

Commit

Permalink
Allow comma separated list of daemons for the gather-logs command.
Browse files Browse the repository at this point in the history
The name of the `telepresence gather-logs` flag `--daemons` suggests
that the argument can contain more than one daemon, but prior to this
fix, it couldn't. It is now possible to use a comma separated list, e.g.
`telepresence gather-logs --daemons root,user`.

Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Oct 5, 2024
1 parent 29af3b7 commit cfae40a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ items:
client originate from the specified container. Additionally, if the
`--replace` option is used, it ensures that this container is replaced.
docs: https://telepresence.io/docs/reference/intercepts/container
- type: bugfix
title: Allow comma separated list of daemons for the gather-logs command.
body: ->
The name of the `telepresence gather-logs` flag `--daemons` suggests that the argument can contain more
than one daemon, but prior to this fix, it couldn't. It is now possible to use a comma separated
list, e.g. `telepresence gather-logs --daemons root,user`.
- version: 2.20.0
date: 2024-10-03
notes:
Expand Down
34 changes: 20 additions & 14 deletions pkg/client/cli/cmd/gather_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ telepresence gather-logs --daemons=None
}
flags := cmd.Flags()
flags.StringVarP(&gl.outputFile, "output-file", "o", "", "The file you want to output the logs to.")
flags.StringVar(&gl.daemons, "daemons", "all", "The daemons you want logs from: all, root, user, kubeauth, None")
flags.StringVar(&gl.daemons, "daemons", "all", "Comma separated list of daemons you want logs from: all, root, user, kubeauth, None")
flags.BoolVar(&gl.trafficManager, "traffic-manager", true, "If you want to collect logs from the traffic-manager")
flags.StringVar(&gl.trafficAgents, "traffic-agents", "all", "Traffic-agents to collect logs from: all, name substring, None")
flags.BoolVarP(&gl.anon, "anonymize", "a", false, "To anonymize pod names + namespaces from the logs")
Expand Down Expand Up @@ -121,21 +121,27 @@ func (gl *gatherLogsCommand) gatherLogs(cmd *cobra.Command, _ []string) error {
}
}()

// First we add the daemonLogs to the export directory
// Add the daemonLogs to the export directory
var daemonLogs []string
switch gl.daemons {
case "all":
daemonLogs = append(daemonLogs, "cli", "connector", "daemon", "kubeauth")
case "root":
daemonLogs = append(daemonLogs, "daemon")
case "user":
daemonLogs = append(daemonLogs, "connector")
case "kubeauth":
daemonLogs = append(daemonLogs, "kubeauth")
case "None":
default:
return errcat.User.New("Options for --daemons are: all, root, user, or None")
for _, daemon := range strings.Split(gl.daemons, ",") {
daemon = strings.TrimSpace(daemon)
switch daemon {
case "all":
daemonLogs = append(daemonLogs, "cli", "connector", "daemon", "kubeauth")
case "cli":
daemonLogs = append(daemonLogs, "cli")
case "daemon", "root":
daemonLogs = append(daemonLogs, "daemon")
case "connector", "user":
daemonLogs = append(daemonLogs, "connector")
case "kubeauth":
daemonLogs = append(daemonLogs, "kubeauth")
case "", "None":
default:
return errcat.User.New("Options for --daemons are: all, root, user, or None")
}
}

// Add metadata about the request, so we can track usage + see which
// types of logs people are requesting more frequently.
// This also gives us an idea about how much usage this command is
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/cli/cmd/gather_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ func Test_gatherLogsNoK8s(t *testing.T) {
daemons: "user",
errMsg: "",
},
{
name: "successfulZipConnectorAndDaemonLogs",
outputFile: "",
daemons: "user,root",
errMsg: "",
},
{
name: "successfulZipNoDaemonLogs",
outputFile: "",
Expand Down Expand Up @@ -261,6 +267,8 @@ func Test_gatherLogsNoK8s(t *testing.T) {
regexStr = "daemon"
case "user":
regexStr = "connector"
case "user,root":
regexStr = "connector|daemon"
case "None":
regexStr = "a^" // impossible to match
default:
Expand Down

0 comments on commit cfae40a

Please sign in to comment.