kubexec 0.6.2__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kubexec-0.8.0/LICENSE +21 -0
- kubexec-0.8.0/MANIFEST.in +2 -0
- kubexec-0.8.0/PKG-INFO +175 -0
- kubexec-0.8.0/README.md +136 -0
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/__init__.py +2 -2
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/cli.py +30 -17
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/config.py +53 -13
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/executor.py +120 -40
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/k8s_client.py +41 -11
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/kuberlist.py +54 -29
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/templates.py +19 -9
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/utils.py +39 -13
- kubexec-0.8.0/kubexec.egg-info/PKG-INFO +175 -0
- kubexec-0.8.0/kubexec.egg-info/SOURCES.txt +37 -0
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec.egg-info/requires.txt +3 -0
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec.egg-info/top_level.txt +0 -1
- kubexec-0.8.0/pytest.ini +6 -0
- kubexec-0.8.0/requirements.txt +3 -0
- {kubexec-0.6.2 → kubexec-0.8.0}/setup.py +21 -3
- kubexec-0.8.0/tests/climb/__init__.py +0 -0
- kubexec-0.8.0/tests/climb/conftest.py +32 -0
- kubexec-0.8.0/tests/climb/test_cluster.py +80 -0
- kubexec-0.8.0/tests/climb/test_e2e_jobs.py +167 -0
- kubexec-0.8.0/tests/conftest.py +70 -0
- kubexec-0.8.0/tests/unit/__init__.py +0 -0
- kubexec-0.8.0/tests/unit/conftest.py +16 -0
- kubexec-0.8.0/tests/unit/test_cli.py +115 -0
- kubexec-0.8.0/tests/unit/test_config.py +123 -0
- kubexec-0.8.0/tests/unit/test_executor.py +388 -0
- kubexec-0.8.0/tests/unit/test_k8s_client.py +119 -0
- kubexec-0.8.0/tests/unit/test_kuberlist.py +89 -0
- kubexec-0.8.0/tests/unit/test_templates.py +64 -0
- kubexec-0.8.0/tests/unit/test_utils.py +103 -0
- kubexec-0.8.0/tests/unit/test_version.py +27 -0
- kubexec-0.6.2/PKG-INFO +0 -80
- kubexec-0.6.2/README.md +0 -53
- kubexec-0.6.2/kubexec.egg-info/PKG-INFO +0 -80
- kubexec-0.6.2/kubexec.egg-info/SOURCES.txt +0 -18
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec/exceptions.py +0 -0
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec.egg-info/dependency_links.txt +0 -0
- {kubexec-0.6.2 → kubexec-0.8.0}/kubexec.egg-info/entry_points.txt +0 -0
- {kubexec-0.6.2 → kubexec-0.8.0}/setup.cfg +0 -0
- {kubexec-0.6.2 → kubexec-0.8.0}/tests/__init__.py +0 -0
kubexec-0.8.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Andrea Telatin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
kubexec-0.8.0/PKG-INFO
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kubexec
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: Execute commands and scripts on Kubernetes pods with Docker access
|
|
5
|
+
Home-page: https://github.com/telatin/kubexec
|
|
6
|
+
Author: kubexec team
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Source, https://github.com/telatin/kubexec
|
|
9
|
+
Project-URL: Issues, https://github.com/telatin/kubexec/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/telatin/kubexec#readme
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: kubernetes>=28.1.0
|
|
23
|
+
Requires-Dist: PyYAML>=6.0
|
|
24
|
+
Requires-Dist: rich>=13.0.0
|
|
25
|
+
Provides-Extra: test
|
|
26
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: description
|
|
30
|
+
Dynamic: description-content-type
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: license
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
Dynamic: project-url
|
|
35
|
+
Dynamic: provides-extra
|
|
36
|
+
Dynamic: requires-dist
|
|
37
|
+
Dynamic: requires-python
|
|
38
|
+
Dynamic: summary
|
|
39
|
+
|
|
40
|
+
# kubexec
|
|
41
|
+
|
|
42
|
+
[](https://pypi.org/project/kubexec/)
|
|
43
|
+
[](https://pypi.org/project/kubexec/)
|
|
44
|
+
[](https://github.com/telatin/kubexec/releases)
|
|
45
|
+
[](https://github.com/telatin/kubexec/actions/workflows/tests.yml)
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
49
|
+
Execute commands and scripts on Kubernetes pods with Docker access.
|
|
50
|
+
|
|
51
|
+
Designed for use in [CLIMB Notebooks](https://docs.climb.ac.uk/).
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install -e .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
kubexec [-h] [-d DOCKER_IMAGE] [-n NAMESPACE] [-p POD_NAME]
|
|
63
|
+
[-m MEMORY] [-c CPU] [-w WORKDIR] [-v VOLUME_MOUNT]
|
|
64
|
+
[--config CONFIG] [--context CONTEXT] [--create-pod]
|
|
65
|
+
[--cleanup | --no-cleanup] [--verbose] [--dry-run] TARGET
|
|
66
|
+
|
|
67
|
+
kubexec --list-jobs [--all-users]
|
|
68
|
+
kubexec --cleanup-old HOURS [--all-users]
|
|
69
|
+
|
|
70
|
+
kuberlist [--all] [--running] [--kubexec [--all-users]] [--watch]
|
|
71
|
+
[-n NAMESPACE] [--config CONFIG] [--context CONTEXT]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Examples
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Run a simple command
|
|
78
|
+
kubexec 'echo "Hello, Kubernetes!"'
|
|
79
|
+
|
|
80
|
+
# Use specific Docker image
|
|
81
|
+
kubexec -d python:3.9 'python -c "import sys; print(sys.version)"'
|
|
82
|
+
|
|
83
|
+
# Run with resource limits
|
|
84
|
+
kubexec -m 4Gi -c 2 'stress --cpu 2 --timeout 60s'
|
|
85
|
+
|
|
86
|
+
# Execute script file
|
|
87
|
+
kubexec ./my_script.sh
|
|
88
|
+
|
|
89
|
+
# Use existing pod
|
|
90
|
+
kubexec -p my-existing-pod 'ls -la'
|
|
91
|
+
|
|
92
|
+
# Volume mounting
|
|
93
|
+
kubexec -v /host/data:/pod/data 'ls /pod/data'
|
|
94
|
+
|
|
95
|
+
# Save output to local files (works like local commands; from a non-shared
|
|
96
|
+
# directory the file ends up in the per-run folder printed at start)
|
|
97
|
+
kubexec "ls -la > output.txt"
|
|
98
|
+
|
|
99
|
+
# Bioinformatics example with SPAdes genome assembler
|
|
100
|
+
# This will create spades-out/ in your current working directory (if it is under
|
|
101
|
+
# /shared/team or /shared/public; otherwise in the per-run folder printed at start)
|
|
102
|
+
kubexec -d community.wave.seqera.io/library/spades:4.1.0--77799c52e1d1054a \
|
|
103
|
+
"spades.py -1 tests/reads/s_6_1.fastq.gz -2 tests/reads/s_6_2.fastq.gz -o spades-out"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Where jobs run
|
|
107
|
+
|
|
108
|
+
Jobs always have `/shared/team` and `/shared/public` mounted. The directory a job runs in is
|
|
109
|
+
chosen as follows:
|
|
110
|
+
|
|
111
|
+
1. `-w/--workdir`, if given. It supports `{user}` (your login name) and `{run}` (a unique id
|
|
112
|
+
per run), and relative paths are resolved against the directory in point 2 or 3.
|
|
113
|
+
2. The current directory, if it is under `/shared/team` or `/shared/public`.
|
|
114
|
+
3. Otherwise (e.g. your Jupyter home, which jobs cannot see) a new folder per run:
|
|
115
|
+
`/shared/team/kubexec/work/<you>/<run-id>`. The folder is printed at start and removed
|
|
116
|
+
when the job finishes if it was left empty, so outputs never overwrite each other.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
kubexec -w /shared/team/myproject/out 'make results' # run in an explicit directory
|
|
120
|
+
kubexec -w 'results/{run}' 'make results' # a unique subfolder per run
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Jobs and users
|
|
124
|
+
|
|
125
|
+
Every job is labelled with your `$JUPYTERHUB_USER` (falling back to `$USER`). On a shared
|
|
126
|
+
namespace this keeps your jobs separate from other people's:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
kubexec --list-jobs # your jobs
|
|
130
|
+
kubexec --cleanup-old 24 # delete your jobs older than 24 hours
|
|
131
|
+
kubexec --list-jobs --all-users # everyone's jobs
|
|
132
|
+
kubexec --cleanup-old 24 --all-users
|
|
133
|
+
|
|
134
|
+
kuberlist --kubexec # your kubexec pods
|
|
135
|
+
kuberlist --kubexec --all-users # everyone's kubexec pods, with a USER column
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Jobs created before 0.8.0 carry no user label: they are only listed or cleaned with
|
|
139
|
+
`--all-users` (shown as user `unknown`).
|
|
140
|
+
|
|
141
|
+
## Configuration
|
|
142
|
+
|
|
143
|
+
Configuration is personal and lives in `~/.config/kubexec/config.yaml`, created with the
|
|
144
|
+
defaults on first run (nothing is written to `/shared/team`, and older shared configs are no
|
|
145
|
+
longer read). Use `--config FILE` to read another file; this applies to `--list-jobs`,
|
|
146
|
+
`--cleanup-old` and `kuberlist` too.
|
|
147
|
+
|
|
148
|
+
| Key | Environment variable | Default |
|
|
149
|
+
|---|---|---|
|
|
150
|
+
| `docker_image` | `KUBEXEC_DOCKER_IMAGE` | `ubuntu:latest` |
|
|
151
|
+
| `namespace` | `KUBEXEC_NAMESPACE` | auto-detected |
|
|
152
|
+
| `memory` / `cpu` | `KUBEXEC_MEMORY` / `KUBEXEC_CPU` | `1Gi` / `1` |
|
|
153
|
+
| `default_workdir` | `KUBEXEC_DEFAULT_WORKDIR` | `/shared/team/kubexec/work/{user}/{run}` |
|
|
154
|
+
| `workdir` | `KUBEXEC_WORKDIR` | `/tmp` (container start directory only) |
|
|
155
|
+
| `cleanup` | `KUBEXEC_CLEANUP` | `true` |
|
|
156
|
+
| `verify_ssl` | `KUBEXEC_VERIFY_SSL` | `true` |
|
|
157
|
+
| `timeout` | `KUBEXEC_TIMEOUT` | `3600` (seconds) |
|
|
158
|
+
| `verbose` | `KUBEXEC_VERBOSE` | `false` |
|
|
159
|
+
|
|
160
|
+
`default_workdir` must be an absolute path. Drop `{run}` from it to share one persistent
|
|
161
|
+
folder between runs (it is then never removed automatically).
|
|
162
|
+
|
|
163
|
+
## Testing
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
pip install -e '.[test]'
|
|
167
|
+
|
|
168
|
+
pytest # unit tests; CLIMB tests run too when CLIMB is detected
|
|
169
|
+
pytest tests/unit # unit tests only (no cluster needed, runs anywhere)
|
|
170
|
+
pytest -m "not e2e" # on CLIMB, skip tests that create real jobs
|
|
171
|
+
KUBEXEC_TEST_CLIMB=0 pytest # force-skip the CLIMB suite (=1 forces it on)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
CLIMB is detected by the in-cluster service account plus `/shared/team` and `/shared/public`
|
|
175
|
+
being mounted. Tests marked `xfail` document known bugs and will fail loudly (strict) once fixed.
|
kubexec-0.8.0/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# kubexec
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/kubexec/)
|
|
4
|
+
[](https://pypi.org/project/kubexec/)
|
|
5
|
+
[](https://github.com/telatin/kubexec/releases)
|
|
6
|
+
[](https://github.com/telatin/kubexec/actions/workflows/tests.yml)
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
Execute commands and scripts on Kubernetes pods with Docker access.
|
|
11
|
+
|
|
12
|
+
Designed for use in [CLIMB Notebooks](https://docs.climb.ac.uk/).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install -e .
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
kubexec [-h] [-d DOCKER_IMAGE] [-n NAMESPACE] [-p POD_NAME]
|
|
24
|
+
[-m MEMORY] [-c CPU] [-w WORKDIR] [-v VOLUME_MOUNT]
|
|
25
|
+
[--config CONFIG] [--context CONTEXT] [--create-pod]
|
|
26
|
+
[--cleanup | --no-cleanup] [--verbose] [--dry-run] TARGET
|
|
27
|
+
|
|
28
|
+
kubexec --list-jobs [--all-users]
|
|
29
|
+
kubexec --cleanup-old HOURS [--all-users]
|
|
30
|
+
|
|
31
|
+
kuberlist [--all] [--running] [--kubexec [--all-users]] [--watch]
|
|
32
|
+
[-n NAMESPACE] [--config CONFIG] [--context CONTEXT]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Examples
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Run a simple command
|
|
39
|
+
kubexec 'echo "Hello, Kubernetes!"'
|
|
40
|
+
|
|
41
|
+
# Use specific Docker image
|
|
42
|
+
kubexec -d python:3.9 'python -c "import sys; print(sys.version)"'
|
|
43
|
+
|
|
44
|
+
# Run with resource limits
|
|
45
|
+
kubexec -m 4Gi -c 2 'stress --cpu 2 --timeout 60s'
|
|
46
|
+
|
|
47
|
+
# Execute script file
|
|
48
|
+
kubexec ./my_script.sh
|
|
49
|
+
|
|
50
|
+
# Use existing pod
|
|
51
|
+
kubexec -p my-existing-pod 'ls -la'
|
|
52
|
+
|
|
53
|
+
# Volume mounting
|
|
54
|
+
kubexec -v /host/data:/pod/data 'ls /pod/data'
|
|
55
|
+
|
|
56
|
+
# Save output to local files (works like local commands; from a non-shared
|
|
57
|
+
# directory the file ends up in the per-run folder printed at start)
|
|
58
|
+
kubexec "ls -la > output.txt"
|
|
59
|
+
|
|
60
|
+
# Bioinformatics example with SPAdes genome assembler
|
|
61
|
+
# This will create spades-out/ in your current working directory (if it is under
|
|
62
|
+
# /shared/team or /shared/public; otherwise in the per-run folder printed at start)
|
|
63
|
+
kubexec -d community.wave.seqera.io/library/spades:4.1.0--77799c52e1d1054a \
|
|
64
|
+
"spades.py -1 tests/reads/s_6_1.fastq.gz -2 tests/reads/s_6_2.fastq.gz -o spades-out"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Where jobs run
|
|
68
|
+
|
|
69
|
+
Jobs always have `/shared/team` and `/shared/public` mounted. The directory a job runs in is
|
|
70
|
+
chosen as follows:
|
|
71
|
+
|
|
72
|
+
1. `-w/--workdir`, if given. It supports `{user}` (your login name) and `{run}` (a unique id
|
|
73
|
+
per run), and relative paths are resolved against the directory in point 2 or 3.
|
|
74
|
+
2. The current directory, if it is under `/shared/team` or `/shared/public`.
|
|
75
|
+
3. Otherwise (e.g. your Jupyter home, which jobs cannot see) a new folder per run:
|
|
76
|
+
`/shared/team/kubexec/work/<you>/<run-id>`. The folder is printed at start and removed
|
|
77
|
+
when the job finishes if it was left empty, so outputs never overwrite each other.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
kubexec -w /shared/team/myproject/out 'make results' # run in an explicit directory
|
|
81
|
+
kubexec -w 'results/{run}' 'make results' # a unique subfolder per run
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Jobs and users
|
|
85
|
+
|
|
86
|
+
Every job is labelled with your `$JUPYTERHUB_USER` (falling back to `$USER`). On a shared
|
|
87
|
+
namespace this keeps your jobs separate from other people's:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
kubexec --list-jobs # your jobs
|
|
91
|
+
kubexec --cleanup-old 24 # delete your jobs older than 24 hours
|
|
92
|
+
kubexec --list-jobs --all-users # everyone's jobs
|
|
93
|
+
kubexec --cleanup-old 24 --all-users
|
|
94
|
+
|
|
95
|
+
kuberlist --kubexec # your kubexec pods
|
|
96
|
+
kuberlist --kubexec --all-users # everyone's kubexec pods, with a USER column
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Jobs created before 0.8.0 carry no user label: they are only listed or cleaned with
|
|
100
|
+
`--all-users` (shown as user `unknown`).
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
Configuration is personal and lives in `~/.config/kubexec/config.yaml`, created with the
|
|
105
|
+
defaults on first run (nothing is written to `/shared/team`, and older shared configs are no
|
|
106
|
+
longer read). Use `--config FILE` to read another file; this applies to `--list-jobs`,
|
|
107
|
+
`--cleanup-old` and `kuberlist` too.
|
|
108
|
+
|
|
109
|
+
| Key | Environment variable | Default |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| `docker_image` | `KUBEXEC_DOCKER_IMAGE` | `ubuntu:latest` |
|
|
112
|
+
| `namespace` | `KUBEXEC_NAMESPACE` | auto-detected |
|
|
113
|
+
| `memory` / `cpu` | `KUBEXEC_MEMORY` / `KUBEXEC_CPU` | `1Gi` / `1` |
|
|
114
|
+
| `default_workdir` | `KUBEXEC_DEFAULT_WORKDIR` | `/shared/team/kubexec/work/{user}/{run}` |
|
|
115
|
+
| `workdir` | `KUBEXEC_WORKDIR` | `/tmp` (container start directory only) |
|
|
116
|
+
| `cleanup` | `KUBEXEC_CLEANUP` | `true` |
|
|
117
|
+
| `verify_ssl` | `KUBEXEC_VERIFY_SSL` | `true` |
|
|
118
|
+
| `timeout` | `KUBEXEC_TIMEOUT` | `3600` (seconds) |
|
|
119
|
+
| `verbose` | `KUBEXEC_VERBOSE` | `false` |
|
|
120
|
+
|
|
121
|
+
`default_workdir` must be an absolute path. Drop `{run}` from it to share one persistent
|
|
122
|
+
folder between runs (it is then never removed automatically).
|
|
123
|
+
|
|
124
|
+
## Testing
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pip install -e '.[test]'
|
|
128
|
+
|
|
129
|
+
pytest # unit tests; CLIMB tests run too when CLIMB is detected
|
|
130
|
+
pytest tests/unit # unit tests only (no cluster needed, runs anywhere)
|
|
131
|
+
pytest -m "not e2e" # on CLIMB, skip tests that create real jobs
|
|
132
|
+
KUBEXEC_TEST_CLIMB=0 pytest # force-skip the CLIMB suite (=1 forces it on)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
CLIMB is detected by the in-cluster service account plus `/shared/team` and `/shared/public`
|
|
136
|
+
being mounted. Tests marked `xfail` document known bugs and will fail loudly (strict) once fixed.
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
kubexec - Execute commands and scripts on Kubernetes pods with Docker access
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
__version__ = "0.
|
|
5
|
+
__version__ = "0.8.0"
|
|
6
6
|
__author__ = "kubexec team"
|
|
7
7
|
|
|
8
8
|
from .cli import main
|
|
9
9
|
from .executor import KubeExecutor
|
|
10
10
|
from .config import Config
|
|
11
11
|
|
|
12
|
-
__all__ = ["main", "KubeExecutor", "Config"]
|
|
12
|
+
__all__ = ["main", "KubeExecutor", "Config"]
|
|
@@ -39,6 +39,7 @@ Examples:
|
|
|
39
39
|
|
|
40
40
|
parser.add_argument(
|
|
41
41
|
'target',
|
|
42
|
+
nargs='?',
|
|
42
43
|
metavar='TARGET',
|
|
43
44
|
help='Command string or path to script file to execute'
|
|
44
45
|
)
|
|
@@ -70,7 +71,11 @@ Examples:
|
|
|
70
71
|
|
|
71
72
|
parser.add_argument(
|
|
72
73
|
'-w', '--workdir',
|
|
73
|
-
help='
|
|
74
|
+
help=('Directory to run in inside the job. Default: the current directory if it is under '
|
|
75
|
+
'/shared/team or /shared/public, otherwise a new folder per run '
|
|
76
|
+
'(config key default_workdir, /shared/team/kubexec/work/{user}/{run}). '
|
|
77
|
+
'Relative paths are resolved against that default. {user} is your login name '
|
|
78
|
+
'and {run} a unique id per run, usable in paths')
|
|
74
79
|
)
|
|
75
80
|
|
|
76
81
|
parser.add_argument(
|
|
@@ -123,14 +128,20 @@ Examples:
|
|
|
123
128
|
parser.add_argument(
|
|
124
129
|
'--list-jobs',
|
|
125
130
|
action='store_true',
|
|
126
|
-
help='List recent kubexec jobs'
|
|
131
|
+
help='List your recent kubexec jobs'
|
|
127
132
|
)
|
|
128
133
|
|
|
129
134
|
parser.add_argument(
|
|
130
135
|
'--cleanup-old',
|
|
131
136
|
type=int,
|
|
132
137
|
metavar='HOURS',
|
|
133
|
-
help='Cleanup jobs older than specified hours'
|
|
138
|
+
help='Cleanup your jobs older than specified hours'
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
parser.add_argument(
|
|
142
|
+
'--all-users',
|
|
143
|
+
action='store_true',
|
|
144
|
+
help='With --list-jobs / --cleanup-old, act on every user\'s jobs in the namespace, not only yours'
|
|
134
145
|
)
|
|
135
146
|
|
|
136
147
|
parser.add_argument(
|
|
@@ -156,14 +167,14 @@ def main() -> int:
|
|
|
156
167
|
config = Config(args.config)
|
|
157
168
|
|
|
158
169
|
# Initialize Kubernetes client
|
|
159
|
-
k8s_client = KubernetesClient(args.context)
|
|
170
|
+
k8s_client = KubernetesClient(args.context, verify_ssl=config.get('verify_ssl', True))
|
|
160
171
|
|
|
161
172
|
# Handle special operations
|
|
162
173
|
if args.list_jobs:
|
|
163
|
-
return _handle_list_jobs(k8s_client, args.namespace or config.get('namespace'))
|
|
174
|
+
return _handle_list_jobs(k8s_client, config, args.namespace or config.get('namespace'), args.all_users)
|
|
164
175
|
|
|
165
176
|
if args.cleanup_old:
|
|
166
|
-
return _handle_cleanup_old(k8s_client, args.namespace or config.get('namespace'), args.cleanup_old)
|
|
177
|
+
return _handle_cleanup_old(k8s_client, config, args.namespace or config.get('namespace'), args.cleanup_old, args.all_users)
|
|
167
178
|
|
|
168
179
|
# Validate target
|
|
169
180
|
if not args.target:
|
|
@@ -213,22 +224,24 @@ def main() -> int:
|
|
|
213
224
|
return 1
|
|
214
225
|
|
|
215
226
|
|
|
216
|
-
def _handle_list_jobs(k8s_client: KubernetesClient, namespace: str) -> int:
|
|
227
|
+
def _handle_list_jobs(k8s_client: KubernetesClient, config: Config, namespace: str, all_users: bool = False) -> int:
|
|
217
228
|
"""Handle --list-jobs operation"""
|
|
218
229
|
try:
|
|
219
230
|
from .executor import KubeExecutor
|
|
220
|
-
executor = KubeExecutor(
|
|
221
|
-
jobs = executor.list_jobs(namespace)
|
|
231
|
+
executor = KubeExecutor(config, k8s_client)
|
|
232
|
+
jobs = executor.list_jobs(namespace, all_users)
|
|
222
233
|
|
|
223
234
|
if not jobs:
|
|
224
|
-
print("No kubexec jobs found")
|
|
235
|
+
print("No kubexec jobs found" if all_users else "No kubexec jobs of yours found (use --all-users to see everyone's)")
|
|
225
236
|
return 0
|
|
226
237
|
|
|
227
|
-
|
|
228
|
-
print("
|
|
238
|
+
user_header = f"{'USER':<20} " if all_users else ""
|
|
239
|
+
print(f"{'NAME':<30} {user_header}{'STATUS':<12} {'IMAGE':<30} {'CREATED'}")
|
|
240
|
+
print("-" * (90 + len(user_header)))
|
|
229
241
|
for job in jobs:
|
|
230
242
|
created = job['created'].strftime('%Y-%m-%d %H:%M:%S') if job['created'] else 'unknown'
|
|
231
|
-
|
|
243
|
+
user_col = f"{job['user']:<20} " if all_users else ""
|
|
244
|
+
print(f"{job['name']:<30} {user_col}{job['status']:<12} {job['image']:<30} {created}")
|
|
232
245
|
|
|
233
246
|
return 0
|
|
234
247
|
|
|
@@ -237,14 +250,14 @@ def _handle_list_jobs(k8s_client: KubernetesClient, namespace: str) -> int:
|
|
|
237
250
|
return 1
|
|
238
251
|
|
|
239
252
|
|
|
240
|
-
def _handle_cleanup_old(k8s_client: KubernetesClient, namespace: str, max_age_hours: int) -> int:
|
|
253
|
+
def _handle_cleanup_old(k8s_client: KubernetesClient, config: Config, namespace: str, max_age_hours: int, all_users: bool = False) -> int:
|
|
241
254
|
"""Handle --cleanup-old operation"""
|
|
242
255
|
try:
|
|
243
256
|
from .executor import KubeExecutor
|
|
244
|
-
executor = KubeExecutor(
|
|
245
|
-
cleaned_count = executor.cleanup_old_jobs(namespace, max_age_hours)
|
|
257
|
+
executor = KubeExecutor(config, k8s_client)
|
|
258
|
+
cleaned_count = executor.cleanup_old_jobs(namespace, max_age_hours, all_users)
|
|
246
259
|
|
|
247
|
-
print(f"Cleaned up {cleaned_count} jobs older than {max_age_hours} hours")
|
|
260
|
+
print(f"Cleaned up {cleaned_count} jobs older than {max_age_hours} hours" + ("" if all_users else " (yours only; use --all-users for everyone's)"))
|
|
248
261
|
return 0
|
|
249
262
|
|
|
250
263
|
except Exception as e:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Configuration management for kubexec"""
|
|
2
2
|
|
|
3
|
+
import logging
|
|
3
4
|
import os
|
|
4
5
|
import yaml
|
|
5
6
|
from pathlib import Path
|
|
@@ -7,13 +8,16 @@ from typing import Dict, Any, Optional
|
|
|
7
8
|
from .exceptions import ConfigurationError
|
|
8
9
|
|
|
9
10
|
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
10
14
|
class Config:
|
|
11
15
|
"""Configuration manager for kubexec"""
|
|
12
16
|
|
|
17
|
+
# Personal configuration lives in the user's home. Nothing is ever created in
|
|
18
|
+
# shared locations such as /shared/team, where all users would share one file.
|
|
13
19
|
DEFAULT_CONFIG_DIRS = [
|
|
14
|
-
f"/shared/team/kubexec/{os.getenv('USER', 'default')}/",
|
|
15
20
|
os.path.join(os.path.expanduser("~"), ".config", "kubexec"),
|
|
16
|
-
f"/tmp/kubexec"
|
|
17
21
|
]
|
|
18
22
|
|
|
19
23
|
DEFAULT_CONFIG_FILE = "config.yaml"
|
|
@@ -23,9 +27,15 @@ class Config:
|
|
|
23
27
|
'namespace': None, # Will be auto-detected from service account
|
|
24
28
|
'memory': '1Gi',
|
|
25
29
|
'cpu': '1',
|
|
26
|
-
'workdir': '/tmp',
|
|
30
|
+
'workdir': '/tmp', # container start directory (commands run in the directory chosen by kubexec)
|
|
31
|
+
# Where jobs run when the current directory is not on a shared volume. Created on
|
|
32
|
+
# demand inside the job. {user} is your login name; {run} is a unique id per run
|
|
33
|
+
# (timestamp + random), so parallel or repeated runs never overwrite each other.
|
|
34
|
+
# Drop {run} to share one persistent folder between runs.
|
|
35
|
+
'default_workdir': '/shared/team/kubexec/work/{user}/{run}',
|
|
27
36
|
'cleanup': True,
|
|
28
37
|
'verbose': False,
|
|
38
|
+
'verify_ssl': True, # Set to false to skip Kubernetes API TLS verification
|
|
29
39
|
'timeout': 3600, # 1 hour default timeout
|
|
30
40
|
'ttl_seconds_after_finished': 60, # Based on Nextflow config
|
|
31
41
|
'security_context': {
|
|
@@ -62,8 +72,11 @@ class Config:
|
|
|
62
72
|
self._create_default_config()
|
|
63
73
|
|
|
64
74
|
try:
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
if os.path.exists(self.config_file):
|
|
76
|
+
with open(self.config_file, 'r') as f:
|
|
77
|
+
config = yaml.safe_load(f) or {}
|
|
78
|
+
else:
|
|
79
|
+
config = {}
|
|
67
80
|
except yaml.YAMLError as e:
|
|
68
81
|
raise ConfigurationError(f"Invalid YAML in config file {self.config_file}: {e}")
|
|
69
82
|
except IOError as e:
|
|
@@ -80,19 +93,31 @@ class Config:
|
|
|
80
93
|
# Override with environment variables
|
|
81
94
|
self._apply_env_overrides(merged_config)
|
|
82
95
|
|
|
96
|
+
default_workdir = merged_config.get('default_workdir')
|
|
97
|
+
if not isinstance(default_workdir, str) or not default_workdir.startswith('/'):
|
|
98
|
+
raise ConfigurationError(
|
|
99
|
+
f"Invalid 'default_workdir' {default_workdir!r}: expected an absolute path (may contain {{user}})"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
if os.getenv('KUBEXEC_TIMEOUT') is None:
|
|
103
|
+
merged_config['timeout'] = self._parse_timeout(
|
|
104
|
+
merged_config['timeout'], f"'timeout' in {self.config_file}"
|
|
105
|
+
)
|
|
106
|
+
|
|
83
107
|
return merged_config
|
|
84
108
|
|
|
85
109
|
def _create_default_config(self) -> None:
|
|
86
|
-
"""Create default configuration file"""
|
|
87
|
-
config_dir = os.path.dirname(self.config_file)
|
|
88
|
-
os.makedirs(config_dir, exist_ok=True)
|
|
89
|
-
|
|
110
|
+
"""Create default configuration file (best effort: defaults apply without it)"""
|
|
90
111
|
# Use detected namespace in default config
|
|
91
112
|
default_config = self.DEFAULT_CONFIG.copy()
|
|
92
113
|
default_config['namespace'] = self._detected_namespace
|
|
93
114
|
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
try:
|
|
116
|
+
os.makedirs(os.path.dirname(self.config_file), exist_ok=True)
|
|
117
|
+
with open(self.config_file, 'w') as f:
|
|
118
|
+
yaml.dump(default_config, f, default_flow_style=False, indent=2)
|
|
119
|
+
except OSError as e:
|
|
120
|
+
logger.debug(f"Could not create default config {self.config_file}: {e}; using built-in defaults")
|
|
96
121
|
|
|
97
122
|
def _apply_env_overrides(self, config: Dict[str, Any]) -> None:
|
|
98
123
|
"""Apply environment variable overrides"""
|
|
@@ -102,21 +127,36 @@ class Config:
|
|
|
102
127
|
'KUBEXEC_MEMORY': 'memory',
|
|
103
128
|
'KUBEXEC_CPU': 'cpu',
|
|
104
129
|
'KUBEXEC_WORKDIR': 'workdir',
|
|
130
|
+
'KUBEXEC_DEFAULT_WORKDIR': 'default_workdir',
|
|
105
131
|
'KUBEXEC_CLEANUP': 'cleanup',
|
|
106
132
|
'KUBEXEC_VERBOSE': 'verbose',
|
|
133
|
+
'KUBEXEC_VERIFY_SSL': 'verify_ssl',
|
|
107
134
|
'KUBEXEC_TIMEOUT': 'timeout',
|
|
108
135
|
}
|
|
109
136
|
|
|
110
137
|
for env_var, config_key in env_mappings.items():
|
|
111
138
|
env_value = os.getenv(env_var)
|
|
112
139
|
if env_value is not None:
|
|
113
|
-
if config_key in ['cleanup', 'verbose']:
|
|
140
|
+
if config_key in ['cleanup', 'verbose', 'verify_ssl']:
|
|
114
141
|
config[config_key] = env_value.lower() in ('true', '1', 'yes', 'on')
|
|
115
142
|
elif config_key == 'timeout':
|
|
116
|
-
config[config_key] =
|
|
143
|
+
config[config_key] = self._parse_timeout(env_value, env_var)
|
|
117
144
|
else:
|
|
118
145
|
config[config_key] = env_value
|
|
119
146
|
|
|
147
|
+
@staticmethod
|
|
148
|
+
def _parse_timeout(value: Any, source: str) -> int:
|
|
149
|
+
"""Validate a timeout value (seconds): must be a positive integer"""
|
|
150
|
+
try:
|
|
151
|
+
if isinstance(value, bool):
|
|
152
|
+
raise ValueError
|
|
153
|
+
timeout = int(str(value).strip())
|
|
154
|
+
except ValueError:
|
|
155
|
+
raise ConfigurationError(f"Invalid {source} {value!r}: expected a positive integer (seconds)")
|
|
156
|
+
if timeout <= 0:
|
|
157
|
+
raise ConfigurationError(f"Invalid {source} {value!r}: expected a positive integer (seconds)")
|
|
158
|
+
return timeout
|
|
159
|
+
|
|
120
160
|
def get(self, key: str, default: Any = None) -> Any:
|
|
121
161
|
"""Get configuration value"""
|
|
122
162
|
return self.config.get(key, default)
|