Skip to content

Commit

Permalink
Simplified interface, focused on easy mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
cpg314 committed Jul 1, 2024
1 parent 3b43ed3 commit 092fef7
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 172 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pv_inspect"
version = "0.1.1"
version = "0.1.2"
edition = "2021"

[dependencies]
Expand All @@ -12,8 +12,11 @@ futures = "0.3.30"
k8s-openapi = { version = "0.22.0", features = ["v1_25"] }
kube = { version = "0.91.0", features = ["runtime", "derive", "ws"] }
log = "0.4.21"
rand_core = "0.6.4"
serde_yaml = "0.9.34"
ssh-key = { version = "0.6.6", features = ["ed25519"] }
tabled = "0.15.0"
tempfile = "3.10.1"
tokio = { version = "1.37.0", features = ["full"] }
tokio-util = "0.7.11"

Expand Down
81 changes: 8 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# pv_inspect

Mount a Kubernetes PersistentVolumeClaim volume on a new pod, shell into it, and port-forward if desired. Delete the pod when done.

Three pod templates are provided (see the `templates` directory):

- `sleep`: Debian container, with a sleep command.
- `miniserve`: Container with a [miniserve](https://github.com/svenstaro/miniserve) HTTP server of the volume contents, port-forwarded on port 8080.
- `samba`: Container with a [Samba server](https://hub.docker.com/r/dperson/samba) sharing the volume contents, automatically bound on port 8080.

Custom templates can be passed with the `--template-yaml` option. A `data` volume/volume mount is automatically added and mounted on `/data`.
Mount a Kubernetes PersistentVolumeClaim volume on a new pod, shell into it, mount it (via SSHFS) if desired. Delete the pod when done.

## Installation

Expand All @@ -23,37 +15,19 @@ $ cargo install --git https://github.com/cpg314/pv_inspect
## Usage

```
Mount a PVC on a new pod, shell into it, and port-forward if desired
Mount a PVC on a new pod, shell into it, and mount if (via SSHFS) if desired
Usage: pv_inspect [OPTIONS] [NAME]
Arguments:
[NAME]
Name of the PVC to inspect
[NAME] Name of the PVC to inspect
Options:
-n, --namespace <NAMESPACE>
[default: default]
--template <TEMPLATE>
[default: miniserve]
Possible values:
- miniserve: Shell and miniserve port-forwarded on 8080:8080
- sleep: A pod that sleeps
- samba: Shell and Samba mount port-forwarded on 8080:445
--template-yaml <TEMPLATE_YAML>
Alternatively, path to a custom pod template
--port <PORT>
Bind a port on the pod. Format: host:pod
--rw
Mount the volume in read/write mode rather than read only
-h, --help
Print help (see a summary with '-h')
-n, --namespace <NAMESPACE> [default: default]
-m, --mountpoint <MOUNTPOINT>
--rw Mount the volume in read/write mode rather than read only
-h, --help Print help
-V, --version Print version
```

### As a `k9s` plugin
Expand All @@ -77,42 +51,3 @@ plugins:
When viewing `PersistentVolumeClaims`, the `p` key (or any other you might choose) will launch `pv_inspect`:

![k9s creenshot](k9s.png)

### Examples

With the default template (`miniserve`):

```console
$ pv_inspect -n my-namespace my-pvc
[INFO pv_inspect] Creating pod
[INFO pv_inspect] Waiting for pod "pvc-inspect-my-pvc-gqnp9"
[INFO pv_inspect] Pod created
[INFO pv_inspect] Starting port forwarding on port 8080:8080
[INFO pv_inspect] Miniserve on http://localhost:8080
[INFO pv_inspect] Connecting to pod. Type Control+D to exit the shell
root@pvc-inspect-my-pvc-gqnp9:/data# ls
folder1 folder2 README
root@pvc-inspect-my-pvc-gqnp9:/data#
[INFO pv_inspect] Stopping port forwarding
[INFO pv_inspect] Deleting pod
[INFO pv_inspect] Waiting for deletion
[INFO pv_inspect] Pod deleted
```

With the `samba` template:

```console
$ pv_inspect -n my-namespace my-pvc --template samba
[INFO pv_inspect] Creating pod
[INFO pv_inspect] Waiting for pod "pvc-inspect-my-pvc-gqnp9"
[INFO pv_inspect] Pod created
[INFO pv_inspect] Starting port forwarding on port 8080:8080
[INFO pv_inspect] Miniserve on http://localhost:8080
[INFO pv_inspect] Connecting to pod. Type Control+D to exit the shell
```

```console
$ sudo mount -t cifs //127.0.0.1/public samba -o port=8080 -o password=""
$ ls samba
folder1 folder2 README
```
33 changes: 33 additions & 0 deletions checkalot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
checks:
- type: version
version: ">=0.1.6"

- type: command
name: group-imports
command: cargo group-imports
version_command: cargo group-imports --version
fix_command: cargo group-imports --fix

- type: command
name: machete
command: cargo-machete .
fix_command:
command: cargo-machete . --fix
success_statuses:
- 0
- 1

- type: command
name: fmt
command: cargo fmt --all -- --check
fix_command: cargo fmt --all

- type: command
name: clippy
command: cargo clippy --color always --release --workspace --no-deps --benches --tests --all-features -- -D warnings
fix_command: cargo clippy --color always --release --workspace --no-deps --benches --tests --all-features --fix --allow-dirty --allow-staged -- -D warnings

- type: command
name: typos
command: typos src README.md
fix_command: typos -w src README.md
Loading

0 comments on commit 092fef7

Please sign in to comment.