Skip to content

Commit 095ccb1

Browse files
committed
Update the README and other cleanups
Signed-off-by: Mario Loriedo <[email protected]>
1 parent 842a089 commit 095ccb1

File tree

7 files changed

+75
-48
lines changed

7 files changed

+75
-48
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
kubectl-debug_ide
22
.idea/*
3+
.DS_Store

README.md

+68-38
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,93 @@
22

33
A `kubectl` plugin to debug Pods with an IDE rather than the CLI.
44

5-
![kubectl debug-ide in action](img/demo.gif)
5+
:warning: This plugin is in its alpha stage and is missing some important feature compared to `kubectl debug`. Running
6+
the IDE in an ephemeral debugging container (rather than copying the target Pod) is not supported. Workloads other than
7+
`Pods` aren't supported either.
8+
9+
## How does `kubectl debug-ide` work?
610

7-
## Prerequirements
11+
Running `kubectl debug-ide` is similar to running `kubectl debug` (same flags) but an IDE is started and a git
12+
repository is cloned within the debugging container.
813

9-
The [DevWorkspace Operator](https://github.com/devfile/devworkspace-operator/tree/main) needs to be installed in the
10-
Kubernetes cluster.
14+
![kubectl debug-ide in action](img/demo.gif)
1115

12-
## Details
16+
The command returns the URL of the remote IDE (local IDE support is not implemented yet). Opening the IDE URL in a
17+
browser allow debugging a process in the target container. Note that the IDE runs in the debugging container, but
18+
"local" debugging is possible as the debugging container and the target container share the same process namespace.
1319

14-
The plugin uses the [client-go library](https://github.com/kubernetes/client-go/tree/master/tools/clientcmd) to create a DevWorkspace in the current namespace.
20+
![debugging using an IDE](img/outyet-debug.gif)
1521

16-
It accepts the same flags as the command `kubectl debug` which it tries to mimic as much as possible, but including an
17-
IDE for source code debugging.
22+
## Examples
1823

19-
## Running
24+
The following command creates a copy of the Pod `$TARGET_POD` with an extra container using image
25+
`$DEBUGGING_CONTAINER_IMG` where `$GIT_REPO` is cloned and an IDE is started.
2026

2127
```sh
22-
$ go install cmd/kubectl-debug_ide.go
28+
TARGET_POD="outyet"
29+
DEBUGGING_CONTAINER_IMG="ghcr.io/l0rd/outyet-dev:latest"
30+
TARGET_POD_COPY="outyet-debug"
31+
GIT_REPO="https://github.com/l0rd/outyet.git"
32+
33+
kubectl debug-ide $TARGET_POD \
34+
--image $DEBUGGING_CONTAINER_IMG \
35+
--copy-to $TARGET_POD_COPY \
36+
--share-processes \
37+
--git-repository $GIT_REPO
38+
```
2339

24-
# assumes you have a working KUBECONFIG
25-
# you can now begin using this plugin as a regular kubectl command:
26-
# start debugging the pod `outyet`
27-
$ kubectl debug-ide outyet \
28-
--image ghcr.io/l0rd/outyet-dev:latest \
29-
--copy-to outyet-debug \
40+
:mega: The containers in the copy of target Pod share the PID namespace. This is helpful to attach the IDE debugger to
41+
the target process as they run in separate containers.
42+
43+
Delete the `DevWorkspace` Custom resource to stop the debugging session and cleanup the Kubernetes resources created by
44+
`kubectl debug-id`:
45+
46+
```sh
47+
TARGET_POD="outyet"
48+
DEBUGGING_CONTAINER_IMG="ghcr.io/l0rd/outyet-dev:latest"
49+
TARGET_POD_COPY="outyet-debug"
50+
GIT_REPO="https://github.com/l0rd/outyet.git"
51+
52+
kubectl debug-ide $TARGET_POD \
53+
--image $DEBUGGING_CONTAINER_IMG \
54+
--copy-to $TARGET_POD_COPY \
3055
--share-processes \
31-
--git-repository https://github.com/l0rd/outyet.git
56+
--git-repository $GIT_REPO
3257
```
3358

34-
## Shell completion
59+
:mega: `kubectl delete pod` won't work in this case as the DevWorkspace Operator will restart the Pod.
3560

36-
This plugin supports shell completion when used through kubectl. To enable shell completion for the plugin
37-
you must copy the file `./kubectl_complete-cde` somewhere on `$PATH` and give it executable permissions.
61+
## Requirements
3862

39-
The `./kubectl_complete-cde` script shows a hybrid approach to providing completions:
40-
1. it uses the builtin `__complete` command provided by [Cobra](https://github.com/spf13/cobra) for flags
41-
1. it calls `kubectl` to obtain the list of pods to complete arguments (note that a more elegant approach would be to
42-
have the `kubectl-cde` program itself provide completion of arguments by implementing Cobra's `ValidArgsFunction` to
43-
fetch the list of pods, but it would then be a less varied example)
63+
Running `kubectl debug-ide` requires the [DevWorkspace Operator](https://github.com/devfile/devworkspace-operator/tree/main).
64+
`kubectl debug-ide` creates Custom Resources of type `DevWorkspace`.
4465

45-
One can then do things like:
46-
```
47-
$ kubectl debug-ide <TAB>
48-
outyet
49-
50-
$ kubectl debug-ide --<TAB>
51-
--copy-to
52-
--image
53-
--git-repository
54-
--share-processes
55-
[...]
66+
Building (and currently installing too) requires [Go](https://go.dev/dl/).
67+
68+
## Installation
69+
70+
To install `kubectl debug-ide` clone this git repository and run `go install`:
71+
72+
```sh
73+
$ go install cmd/kubectl-debug_ide.go
5674
```
5775

58-
Note: kubectl v1.26 or higher is required for shell completion to work for plugins.
76+
## Shell completion
77+
78+
Copy the file `./kubectl_complete-ide` somewhere on `$PATH` and give it executable permissions to enable shell
79+
completion for the plugin.
80+
81+
:mega: kubectl v1.26 or higher is required for shell completion to work for plugins.
5982

6083
## Cleanup
6184

6285
You can "uninstall" this plugin from kubectl by simply removing it from your PATH:
6386

64-
$ rm /usr/local/bin/kubectl-debug_ide
87+
$ rm $GOBIN/kubectl-debug_ide
88+
89+
## Acknowledgments
90+
91+
The awesome [sample-cli-plugin](https://github.com/kubernetes/sample-cli-plugin) was used to kick off this plugin.
92+
93+
`kubectl debug-ide` is just a generator of DevWorkspace Custom Resources. The heavy lifting, the Cloud Development
94+
Environment provisioning, is done by the [DevWorkspace Operator](https://github.com/devfile/devworkspace-operator).

cmd/kubectl-debug_ide.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func main() {
29-
flags := pflag.NewFlagSet("kubectl-debug_cde", pflag.ExitOnError)
29+
flags := pflag.NewFlagSet("kubectl-debug_ide", pflag.ExitOnError)
3030
pflag.CommandLine = flags
3131

3232
root := pkg.NewCmdDebugIDE(genericiooptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr})

img/outyet-debug.gif

485 KB
Loading

kubectl_complete-cde renamed to kubectl_complete-ide

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ args=("$@")
66
lastArg=${args[((${#args[@]}-1))]}
77
if [[ "$lastArg" == -* ]]; then
88
if [[ "$lastArg" != *=* ]]; then
9-
kubectl debug-cde __complete "$@"
9+
kubectl debug-ide __complete "$@"
1010
fi
1111
else
1212
# TODO Make sure we are not completing the value of a flag.
@@ -21,4 +21,4 @@ else
2121
# Turn off file completion. See the ShellCompDirective documentation within
2222
# https://github.com/spf13/cobra/blob/main/shell_completions.md#completion-of-nouns
2323
echo :4
24-
fi
24+
fi

pkg/debug-cde.go renamed to pkg/debug-ide.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func NewCmdDebugIDE(streams genericiooptions.IOStreams) *cobra.Command {
9494
o := NewDebugIDEOptions(streams)
9595

9696
cmd := &cobra.Command{
97-
Use: "debug-cde [pod] [flags]",
97+
Use: "debug-ide [pod] [flags]",
9898
Short: "Create a copy of a Pod and add a Cloud Development Environment to debug it.",
9999
Example: fmt.Sprintf(debugIDEExample, "kubectl"),
100100
SilenceUsage: true,

tests/test.sh

+2-6
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,15 @@ EOF
6464

6565
kubectl wait --for=condition=Ready pod/outyet
6666

67-
echo
68-
echo "Building..."
69-
echo
70-
go build cmd/kubectl-debug_cde.go
7167
echo
7268
echo "Installing..."
7369
echo
74-
cp ./kubectl-debug_cde ~/.bin/
70+
go install cmd/kubectl-debug_ide.go
7571

7672
echo
7773
echo "Running..."
7874
echo
79-
kubectl debug-cde outyet \
75+
kubectl debug-ide outyet \
8076
--image ghcr.io/l0rd/outyet-dev:latest \
8177
--copy-to outyet-debug \
8278
--share-processes \

0 commit comments

Comments
 (0)