Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve help and docs #11

Merged
merged 1 commit into from
Mar 12, 2024
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
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

kubectl-daemons is a kubectl plugin to help with daemonset work. When running a
kubernetes infrastructure, it is common to do lots of work with deamonsets, but
the tools are optimized for other types of k8s objects. With daemonsets, you
often know a node and a DS you care about, and this plugin lets you focus on
that.
the tools are optimized for other workflows where node names aren't
particularly important.. With daemonsets, you often know a node and a DS you
care about, and this plugin lets you focus on that.

Previously you'd do things like:

Expand All @@ -21,11 +21,24 @@ kubectl get pods -o wide | grep <daemonset> | grep <node>
...
```

Now you can do:
Or maybe:

```shell
kubectl get pods --field-selector spec.nodeName=<node>
kubectl describe pod <pod_from above>
kubectl delete pod <pod_from above>
kubectl get pods ---field-selector spec.nodeName=<node>
...
```

No more using a long `get` command to find the pod name,
and having to keep track of it! Just specify the DS and
the node:

```shell
kubectl d describe <daemonset> -N <node>
kubectl d delete <daemonset> -N <node>
kubectl d logs <daemonset> -N <node>
```

## General Usage
Expand Down Expand Up @@ -63,12 +76,30 @@ kubectl d logs <daemonset> -N <node>

NOTE: -N is required here.

And you can even describe:
You can describe pods:

```bash
kubectl d describe <daemonset> [-N <node>] # node optional
```

You can even exec:

```bash
kubectl d exec <daemonset> -N <node> -- echo "Hello world"
```

Or interactively:

```bash
kubectl d exec <daemonset> -N <node> -it -- /bin/bash
```

And you can list all daemonsets on a node:

```bash
kubectl d list <node>
```

## Installing

The easiest way to install, right now, is to grab the right build from our
Expand Down
5 changes: 5 additions & 0 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func newDshDeleteCommand(
cmd := &cobra.Command{
Use: "delete <daemonset> [<options>]",
Short: "delete pods for <daemonset>",
Long:
`Deletes matching pods from the daemonset and/or node. If only a daemonset is
specified, all pods for that daemonset will be deleted. If only a node is
specified, all pods belonging to daemonsets on that node will be deleted. If
both are specified, the pod in that daemonset on that node will be deleted.`,
Args: cobra.MatchAll(cobra.ExactArgs(1)),
RunE: func(cmd *cobra.Command, args []string) error {
return dshDelete.deletePods(*context, *namespace, args[0], *nodeName)
Expand Down
5 changes: 5 additions & 0 deletions cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func newDshDescribeCommand(
cmd := &cobra.Command{
Use: "describe <daemonset> [<options>]",
Short: "describe pods for <daemonset>",
Long:
`Describe pods matching a given daemonset and node. Any combination is allowed.
If only a node is specified all pods owned by a daemonset on that node will be
described. If only a daemonset is specified, a all pods in that daemonset will
be described.`,
Args: cobra.MatchAll(cobra.MaximumNArgs(1)),
RunE: func(cmd *cobra.Command, args []string) error {
ds := ""
Expand Down
12 changes: 9 additions & 3 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func newDshExecCommand(
cmd := &cobra.Command{
Use: "exec <daemonset> [<options>] -- <command> [args...]",
Short: "execute arbitrary commands in pod for <daemonset>",
Long:
`Executes an arbitrary command inside the pod of the specified daemonset on the
specified node. To pass arguments to the command, use '--' followed by the
command and its arguments. For example:
kubectl d exec my-daemonset -c my-container -- echo "Hello, world!"`,
Args: cobra.MatchAll(cobra.MinimumNArgs(1)),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 1 && cmd.ArgsLenAtDash() != -1 {
Expand Down Expand Up @@ -171,9 +177,9 @@ func (sv *dshCmd) execPod(
}
}

if !stdin {
streamOptions.Stdin = nil
}
if !stdin {
streamOptions.Stdin = nil
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
5 changes: 5 additions & 0 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func newDshGetCommand(
cmd := &cobra.Command{
Use: "get <daemonset> [<options>]",
Short: "get pods for <daemonset>",
Long:
`Get poddescribed matching a given daemonset and node. Any combination is allowed.
If only a node is specified all pods owned by a daemonset on that node will be
shown. If only a daemonset is specified, a all pods in that daemonset will
be shown.`,
Args: cobra.MatchAll(cobra.MaximumNArgs(1)),
RunE: func(cmd *cobra.Command, args []string) error {
ds := ""
Expand Down
5 changes: 4 additions & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func newDshListCommand(

cmd := &cobra.Command{
Use: "list [<node>] [<options>]",
Short: "list daemonsets on a node. You can pass in the node as the arg, or use -N",
Short: "list daemonsets on a node.",
Long:
`Will list alll daemonsets on a node. You can pass in the node as the arg, or
use -N.`,
Args: cobra.MatchAll(cobra.MaximumNArgs(1)),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func newDshLogCommand(
cmd := &cobra.Command{
Use: "log <daemonset> [<options>]",
Short: "get logs for <daemonset>",
Long:
`Get logs for pods matching a given daemonset and node. Any combination is
allowed. If only a node is specified logs from all pods owned by a daemonset
on that node will be shown. If only a daemonset is specified, all pods in that
daemonset will have their logs shown.`,
Args: cobra.MatchAll(cobra.ExactArgs(1)),
RunE: func(cmd *cobra.Command, args []string) error {
return dshLog.getLogs(
Expand Down
40 changes: 20 additions & 20 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ type versionCmd struct {
}

func newVersionCommand(out io.Writer) *cobra.Command {
version := &versionCmd{
out: out,
}

cmd := &cobra.Command{
Use: "version",
Short: "print the version number and exit",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return errors.New("this command does not accept arguments")
}
return version.run()
},
}
return cmd
version := &versionCmd{
out: out,
}

cmd := &cobra.Command{
Use: "version",
Short: "print the version number and exit",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return errors.New("this command does not accept arguments")
}
return version.run()
},
}
return cmd
}

func (v *versionCmd) run() error {
_, err := fmt.Fprintf(v.out, "%s %s\n", appLabel, version)
if err != nil {
return err
}
return nil
_, err := fmt.Fprintf(v.out, "%s %s\n", appLabel, version)
if err != nil {
return err
}
return nil
}
Loading