Skip to content

Commit e71cb61

Browse files
mitchdraftsoloio-bulldozer[bot]
authored andcommitted
support process specification (#193)
* introduce multi-process example app * use v0.0.2 images * changelog * wip: introduce failing test * add optional timeout for cli wrapper * refactor test setup * implement feature, test passing * collided with a stale ns, reduce likelihood * gen docs * make docs in build
1 parent a6f675f commit e71cb61

32 files changed

+466
-30
lines changed

Gopkg.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ clean:
100100
generatecode: must
101101
mkdir -p $(OUTPUT_DIR)
102102
go run cmd/generate-code/main.go
103+
rm docs/cli/squashctl*
104+
go run cmd/generate-docs/main.go
103105
gofmt -w ci cmd pkg test
104106
goimports -w ci cmd pkg test
105107

changelog/v0.5.13/multi-process.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
description:
2+
- type: NEW_FEATURE
3+
description: Option to pass a process selector, rather than default to PID 1
4+
issueLink: https://github.com/solo-io/squash/issues/173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_out/
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
IMAGE_TAG ?= dev
2+
CONTAINER_REPO_ORG ?= docker.io/soloio
3+
4+
## These are the images created by this makefile
5+
MULTI_SPEC := $(CONTAINER_REPO_ORG)/multi_process:$(IMAGE_TAG)
6+
SINGLE_SPEC := $(CONTAINER_REPO_ORG)/multi_process_base:$(IMAGE_TAG)
7+
8+
ROOTDIR := $(shell pwd)
9+
OUTPUT_DIR := $(ROOTDIR)/_output
10+
11+
.PHONY: all
12+
all: push-single push-multi
13+
14+
.PHONY: compile
15+
compile:
16+
GOOS=linux go build -gcflags "-N -l" -o $(OUTPUT_DIR)/sample_app main.go
17+
18+
.PHONY: build-multi
19+
build-multi: compile
20+
docker build -t $(MULTI_SPEC) -f multi.dockerfile .
21+
22+
.PHONY: push-multi
23+
push-multi: build-multi
24+
docker push $(MULTI_SPEC)
25+
26+
.PHONY: build-single
27+
build-single: compile
28+
docker build -t $(SINGLE_SPEC) -f single.dockerfile .
29+
30+
.PHONY: push-single
31+
push-single: build-single
32+
docker push $(SINGLE_SPEC)
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Debug arbitrary container PIDs with Squash
2+
3+
At one point, Squash assumed that a user's debug target was completely described by the selection of: namespace, pod name, container. Squash assumed that the user wanted to debug the first process in the container. This is a reasonable assumption, since a popular container usage pattern is to specify one process per container. However it may be useful to run multiple processes in a single container. In order for squash to debug an arbitrary process, it needs to be told how to choose among the available processes.
4+
5+
# Demonstration of the properties of multi-process containers
6+
7+
This directory includes files needed to build and deploy a sample app as the first process in one container and the second process in a separate container.
8+
9+
## Build and push the containers
10+
11+
*This step is not needed, as the container images are already available with the values shown below. If you change these values you will need to update the manifests similarly.*
12+
13+
```bash
14+
export CONTAINER_REPO_ORG = docker.io/soloio
15+
IMAGE_TAG=v0.0.2 make all
16+
```
17+
18+
## Deploy the containers
19+
20+
We will deploy our sample containers in their own pods:
21+
22+
```bash
23+
kubectl apply -f single.yaml
24+
kubectl apply -f multi.yaml
25+
```
26+
27+
## Inspect the images
28+
29+
Note that the container with a single process features our app in PID 1
30+
31+
```bash
32+
k exec -it squash-demo-multiprocess-base-6c746c8595-kpsvt -- /bin/s
33+
h
34+
/app # ls
35+
sample_app
36+
/app # ps
37+
PID USER TIME COMMAND
38+
1 root 0:00 ./sample_app
39+
19 root 0:00 /bin/sh
40+
26 root 0:00 ps
41+
```
42+
43+
However, for our multi-process container, our app is not PID 1
44+
45+
```bash
46+
k exec -it squash-demo-multiprocess-5fbdcd96cf-k9bzw -- /bin/sh
47+
/app # ls
48+
call_app.sh sample_app
49+
/app # ps
50+
PID USER TIME COMMAND
51+
1 root 0:00 {call_app.sh} /bin/sh ./call_app.sh
52+
7 root 0:00 ./sample_app
53+
20 root 0:00 /bin/sh
54+
27 root 0:00 ps
55+
```
56+
57+
## Debug the processes with squash
58+
59+
You can debug the single process container without passing any flags. Squash will use the first PID by default. This works fine with our single process example.
60+
61+
```bash
62+
squashctl # follow interactive prompt to choose target debug container
63+
```
64+
65+
To debug a multi-process container, you need to specify a process-identifier string. Squash will look for processes whos invocation comand matches the string provided.
66+
67+
```bash
68+
squashctl --process sample_app # matches with case-insensitive regex
69+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
echo running the app from a bash script
4+
5+
./sample_app
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net/http"
7+
"os"
8+
)
9+
10+
var ServiceToCall = "example-service2"
11+
12+
func main() {
13+
14+
fmt.Println("starting app")
15+
potentialservice2 := os.Getenv("SERVICE2_URL")
16+
if potentialservice2 != "" {
17+
ServiceToCall = potentialservice2
18+
}
19+
20+
http.HandleFunc("/calc", handler)
21+
http.HandleFunc("/", view)
22+
23+
log.Fatal(http.ListenAndServe(":8080", nil))
24+
}
25+
26+
func view(w http.ResponseWriter, r *http.Request) {
27+
fmt.Fprintf(w, "hello")
28+
}
29+
30+
func handler(w http.ResponseWriter, r *http.Request) {
31+
fmt.Fprintf(w, "hello again")
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# calls a go process from a shell script, making it the second PID
2+
FROM alpine
3+
WORKDIR /app
4+
ADD _output/sample_app /app
5+
ADD call_app.sh /app
6+
ENTRYPOINT ./call_app.sh
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apps/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: squash-demo-multiprocess
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: squash-demo-multiprocess
10+
template:
11+
metadata:
12+
labels:
13+
app: squash-demo-multiprocess
14+
spec:
15+
containers:
16+
- name: squash-demo-multiprocess
17+
image: soloio/multi_process:v0.0.2
18+
ports:
19+
- containerPort: 8080
20+
protocol: TCP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# calls the go process only, making it the first PID
2+
FROM alpine
3+
WORKDIR /app
4+
ADD _output/sample_app /app
5+
ENTRYPOINT ./sample_app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apps/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: squash-demo-multiprocess-base
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: squash-demo-multiprocess-base
10+
template:
11+
metadata:
12+
labels:
13+
app: squash-demo-multiprocess-base
14+
spec:
15+
containers:
16+
- name: squash-demo-multiprocess-base
17+
image: soloio/multi_process_base:v0.0.2
18+
ports:
19+
- containerPort: 8080
20+
protocol: TCP

docs/cli/squashctl.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ squashctl [flags]
2222
### Options
2323

2424
```
25+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
2526
--container string Container to debug
2627
--container-repo string debug container repo to use (default "soloio")
2728
--container-version string debug container version to use (default "mkdev")
@@ -36,6 +37,7 @@ squashctl [flags]
3637
--no-guess-debugger don't auto detect debugger to use
3738
--no-guess-pod don't auto detect pod to use
3839
--pod string Pod to debug
40+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
3941
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
4042
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
4143
```

docs/cli/squashctl_completion.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ squashctl completion SHELL [flags]
5555
### Options inherited from parent commands
5656

5757
```
58+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
5859
--container string Container to debug
5960
--container-repo string debug container repo to use (default "soloio")
6061
--container-version string debug container version to use (default "mkdev")
@@ -68,6 +69,7 @@ squashctl completion SHELL [flags]
6869
--no-guess-debugger don't auto detect debugger to use
6970
--no-guess-pod don't auto detect pod to use
7071
--pod string Pod to debug
72+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
7173
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
7274
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
7375
```

docs/cli/squashctl_deploy.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ deploy squash or a demo microservice
1919
### Options inherited from parent commands
2020

2121
```
22+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
2223
--container string Container to debug
2324
--container-repo string debug container repo to use (default "soloio")
2425
--container-version string debug container version to use (default "mkdev")
@@ -32,6 +33,7 @@ deploy squash or a demo microservice
3233
--no-guess-debugger don't auto detect debugger to use
3334
--no-guess-pod don't auto detect pod to use
3435
--pod string Pod to debug
36+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
3537
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
3638
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
3739
```

docs/cli/squashctl_deploy_demo.md

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ squashctl deploy demo [flags]
2626
### Options inherited from parent commands
2727

2828
```
29+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
2930
--container string Container to debug
3031
--container-repo string debug container repo to use (default "soloio")
3132
--container-version string debug container version to use (default "mkdev")
@@ -39,6 +40,7 @@ squashctl deploy demo [flags]
3940
--no-guess-debugger don't auto detect debugger to use
4041
--no-guess-pod don't auto detect pod to use
4142
--pod string Pod to debug
43+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
4244
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
4345
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
4446
```

docs/cli/squashctl_deploy_squash.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ squashctl deploy squash [flags]
2424
### Options inherited from parent commands
2525

2626
```
27+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
2728
--container string Container to debug
2829
--container-repo string debug container repo to use (default "soloio")
2930
--container-version string debug container version to use (default "mkdev")
@@ -37,6 +38,7 @@ squashctl deploy squash [flags]
3738
--no-guess-debugger don't auto detect debugger to use
3839
--no-guess-pod don't auto detect pod to use
3940
--pod string Pod to debug
41+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
4042
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
4143
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
4244
```

docs/cli/squashctl_squash.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ squashctl squash [flags]
3131
### Options inherited from parent commands
3232

3333
```
34+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
3435
--container string Container to debug
3536
--container-repo string debug container repo to use (default "soloio")
3637
--container-version string debug container version to use (default "mkdev")
@@ -44,6 +45,7 @@ squashctl squash [flags]
4445
--no-guess-debugger don't auto detect debugger to use
4546
--no-guess-pod don't auto detect pod to use
4647
--pod string Pod to debug
48+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
4749
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
4850
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
4951
```

docs/cli/squashctl_squash_delete.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ squashctl squash delete [flags]
2323
### Options inherited from parent commands
2424

2525
```
26+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
2627
--container string Container to debug
2728
--container-repo string debug container repo to use (default "soloio")
2829
--container-version string debug container version to use (default "mkdev")
@@ -36,6 +37,7 @@ squashctl squash delete [flags]
3637
--no-guess-debugger don't auto detect debugger to use
3738
--no-guess-pod don't auto detect pod to use
3839
--pod string Pod to debug
40+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
3941
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
4042
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
4143
```

docs/cli/squashctl_squash_status.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ squashctl squash status [flags]
2323
### Options inherited from parent commands
2424

2525
```
26+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
2627
--container string Container to debug
2728
--container-repo string debug container repo to use (default "soloio")
2829
--container-version string debug container version to use (default "mkdev")
@@ -36,6 +37,7 @@ squashctl squash status [flags]
3637
--no-guess-debugger don't auto detect debugger to use
3738
--no-guess-pod don't auto detect pod to use
3839
--pod string Pod to debug
40+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
3941
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
4042
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
4143
```

docs/cli/squashctl_utils.md

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ squash utils list-attachments
2929
### Options inherited from parent commands
3030

3131
```
32+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
3233
--container string Container to debug
3334
--container-repo string debug container repo to use (default "soloio")
3435
--container-version string debug container version to use (default "mkdev")
@@ -42,6 +43,7 @@ squash utils list-attachments
4243
--no-guess-debugger don't auto detect debugger to use
4344
--no-guess-pod don't auto detect pod to use
4445
--pod string Pod to debug
46+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
4547
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
4648
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
4749
```
@@ -53,4 +55,5 @@ squash utils list-attachments
5355
* [squashctl utils delete-permissions](../squashctl_utils_delete-permissions) - remove all service accounts, roles, and role bindings created by Squash.
5456
* [squashctl utils delete-planks](../squashctl_utils_delete-planks) - remove all plank debugger pods created by Squash.
5557
* [squashctl utils list-attachments](../squashctl_utils_list-attachments) - list all existing debug attachments
58+
* [squashctl utils register-resources](../squashctl_utils_register-resources) - register the custom resource definitions (CRDs) needed by squash
5659

docs/cli/squashctl_utils_delete-attachments.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ squashctl utils delete-attachments [flags]
2323
### Options inherited from parent commands
2424

2525
```
26+
--config string optional, path to squash config (defaults to ~/.squash/config.yaml)
2627
--container string Container to debug
2728
--container-repo string debug container repo to use (default "soloio")
2829
--container-version string debug container version to use (default "mkdev")
@@ -36,6 +37,7 @@ squashctl utils delete-attachments [flags]
3637
--no-guess-debugger don't auto detect debugger to use
3738
--no-guess-pod don't auto detect pod to use
3839
--pod string Pod to debug
40+
--process-match string optional, if passed, Squash will try to find a process in the target container that matches (regex, case-insensitive) this string. Otherwise Squash chooses the first process.
3941
--squash-namespace string the namespace where squash resources will be deployed (default: squash-debugger) (default "squash-debugger")
4042
--timeout int timeout in seconds to wait for debug pod to be ready (default 300)
4143
```

0 commit comments

Comments
 (0)