kubexec 0.7.0__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.
Files changed (44) hide show
  1. kubexec-0.8.0/PKG-INFO +175 -0
  2. kubexec-0.8.0/README.md +136 -0
  3. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/__init__.py +2 -2
  4. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/cli.py +26 -14
  5. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/config.py +31 -11
  6. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/executor.py +94 -26
  7. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/kuberlist.py +53 -28
  8. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/templates.py +19 -9
  9. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/utils.py +22 -0
  10. kubexec-0.8.0/kubexec.egg-info/PKG-INFO +175 -0
  11. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec.egg-info/SOURCES.txt +1 -0
  12. {kubexec-0.7.0 → kubexec-0.8.0}/tests/climb/conftest.py +6 -0
  13. kubexec-0.8.0/tests/climb/test_e2e_jobs.py +167 -0
  14. kubexec-0.8.0/tests/unit/conftest.py +16 -0
  15. {kubexec-0.7.0 → kubexec-0.8.0}/tests/unit/test_cli.py +31 -1
  16. {kubexec-0.7.0 → kubexec-0.8.0}/tests/unit/test_config.py +50 -0
  17. {kubexec-0.7.0 → kubexec-0.8.0}/tests/unit/test_executor.py +165 -4
  18. kubexec-0.8.0/tests/unit/test_kuberlist.py +89 -0
  19. {kubexec-0.7.0 → kubexec-0.8.0}/tests/unit/test_templates.py +12 -0
  20. {kubexec-0.7.0 → kubexec-0.8.0}/tests/unit/test_utils.py +37 -0
  21. kubexec-0.7.0/PKG-INFO +0 -106
  22. kubexec-0.7.0/README.md +0 -67
  23. kubexec-0.7.0/kubexec.egg-info/PKG-INFO +0 -106
  24. kubexec-0.7.0/tests/climb/test_e2e_jobs.py +0 -65
  25. kubexec-0.7.0/tests/unit/conftest.py +0 -16
  26. {kubexec-0.7.0 → kubexec-0.8.0}/LICENSE +0 -0
  27. {kubexec-0.7.0 → kubexec-0.8.0}/MANIFEST.in +0 -0
  28. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/exceptions.py +0 -0
  29. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec/k8s_client.py +0 -0
  30. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec.egg-info/dependency_links.txt +0 -0
  31. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec.egg-info/entry_points.txt +0 -0
  32. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec.egg-info/requires.txt +0 -0
  33. {kubexec-0.7.0 → kubexec-0.8.0}/kubexec.egg-info/top_level.txt +0 -0
  34. {kubexec-0.7.0 → kubexec-0.8.0}/pytest.ini +0 -0
  35. {kubexec-0.7.0 → kubexec-0.8.0}/requirements.txt +0 -0
  36. {kubexec-0.7.0 → kubexec-0.8.0}/setup.cfg +0 -0
  37. {kubexec-0.7.0 → kubexec-0.8.0}/setup.py +0 -0
  38. {kubexec-0.7.0 → kubexec-0.8.0}/tests/__init__.py +0 -0
  39. {kubexec-0.7.0 → kubexec-0.8.0}/tests/climb/__init__.py +0 -0
  40. {kubexec-0.7.0 → kubexec-0.8.0}/tests/climb/test_cluster.py +0 -0
  41. {kubexec-0.7.0 → kubexec-0.8.0}/tests/conftest.py +0 -0
  42. {kubexec-0.7.0 → kubexec-0.8.0}/tests/unit/__init__.py +0 -0
  43. {kubexec-0.7.0 → kubexec-0.8.0}/tests/unit/test_k8s_client.py +0 -0
  44. {kubexec-0.7.0 → kubexec-0.8.0}/tests/unit/test_version.py +0 -0
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
+ [![PyPI Python Version](https://img.shields.io/pypi/pyversions/kubexec)](https://pypi.org/project/kubexec/)
43
+ [![PyPI Wheel](https://img.shields.io/pypi/wheel/kubexec)](https://pypi.org/project/kubexec/)
44
+ [![GitHub Release](https://img.shields.io/github/v/release/telatin/kubexec)](https://github.com/telatin/kubexec/releases)
45
+ [![Tests](https://github.com/telatin/kubexec/actions/workflows/tests.yml/badge.svg)](https://github.com/telatin/kubexec/actions/workflows/tests.yml)
46
+
47
+ ![Kubekec logo](https://raw.githubusercontent.com/telatin/kubexec/55eb22279b7c066987f992db94cb2c49840ba7f3/kubexec-logo.png)
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.
@@ -0,0 +1,136 @@
1
+ # kubexec
2
+
3
+ [![PyPI Python Version](https://img.shields.io/pypi/pyversions/kubexec)](https://pypi.org/project/kubexec/)
4
+ [![PyPI Wheel](https://img.shields.io/pypi/wheel/kubexec)](https://pypi.org/project/kubexec/)
5
+ [![GitHub Release](https://img.shields.io/github/v/release/telatin/kubexec)](https://github.com/telatin/kubexec/releases)
6
+ [![Tests](https://github.com/telatin/kubexec/actions/workflows/tests.yml/badge.svg)](https://github.com/telatin/kubexec/actions/workflows/tests.yml)
7
+
8
+ ![Kubekec logo](https://raw.githubusercontent.com/telatin/kubexec/55eb22279b7c066987f992db94cb2c49840ba7f3/kubexec-logo.png)
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.7.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"]
@@ -71,7 +71,11 @@ Examples:
71
71
 
72
72
  parser.add_argument(
73
73
  '-w', '--workdir',
74
- help='Working directory inside pod (default: /tmp)'
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')
75
79
  )
76
80
 
77
81
  parser.add_argument(
@@ -124,14 +128,20 @@ Examples:
124
128
  parser.add_argument(
125
129
  '--list-jobs',
126
130
  action='store_true',
127
- help='List recent kubexec jobs'
131
+ help='List your recent kubexec jobs'
128
132
  )
129
133
 
130
134
  parser.add_argument(
131
135
  '--cleanup-old',
132
136
  type=int,
133
137
  metavar='HOURS',
134
- 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'
135
145
  )
136
146
 
137
147
  parser.add_argument(
@@ -161,10 +171,10 @@ def main() -> int:
161
171
 
162
172
  # Handle special operations
163
173
  if args.list_jobs:
164
- return _handle_list_jobs(k8s_client, config, args.namespace or config.get('namespace'))
174
+ return _handle_list_jobs(k8s_client, config, args.namespace or config.get('namespace'), args.all_users)
165
175
 
166
176
  if args.cleanup_old:
167
- return _handle_cleanup_old(k8s_client, config, 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)
168
178
 
169
179
  # Validate target
170
180
  if not args.target:
@@ -214,22 +224,24 @@ def main() -> int:
214
224
  return 1
215
225
 
216
226
 
217
- def _handle_list_jobs(k8s_client: KubernetesClient, config: Config, namespace: str) -> int:
227
+ def _handle_list_jobs(k8s_client: KubernetesClient, config: Config, namespace: str, all_users: bool = False) -> int:
218
228
  """Handle --list-jobs operation"""
219
229
  try:
220
230
  from .executor import KubeExecutor
221
231
  executor = KubeExecutor(config, k8s_client)
222
- jobs = executor.list_jobs(namespace)
232
+ jobs = executor.list_jobs(namespace, all_users)
223
233
 
224
234
  if not jobs:
225
- 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)")
226
236
  return 0
227
237
 
228
- print(f"{'NAME':<30} {'STATUS':<12} {'IMAGE':<30} {'CREATED'}")
229
- print("-" * 90)
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)))
230
241
  for job in jobs:
231
242
  created = job['created'].strftime('%Y-%m-%d %H:%M:%S') if job['created'] else 'unknown'
232
- print(f"{job['name']:<30} {job['status']:<12} {job['image']:<30} {created}")
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}")
233
245
 
234
246
  return 0
235
247
 
@@ -238,14 +250,14 @@ def _handle_list_jobs(k8s_client: KubernetesClient, config: Config, namespace: s
238
250
  return 1
239
251
 
240
252
 
241
- def _handle_cleanup_old(k8s_client: KubernetesClient, config: Config, 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:
242
254
  """Handle --cleanup-old operation"""
243
255
  try:
244
256
  from .executor import KubeExecutor
245
257
  executor = KubeExecutor(config, k8s_client)
246
- cleaned_count = executor.cleanup_old_jobs(namespace, max_age_hours)
258
+ cleaned_count = executor.cleanup_old_jobs(namespace, max_age_hours, all_users)
247
259
 
248
- 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)"))
249
261
  return 0
250
262
 
251
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,7 +27,12 @@ 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,
29
38
  'verify_ssl': True, # Set to false to skip Kubernetes API TLS verification
@@ -63,8 +72,11 @@ class Config:
63
72
  self._create_default_config()
64
73
 
65
74
  try:
66
- with open(self.config_file, 'r') as f:
67
- config = yaml.safe_load(f) or {}
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 = {}
68
80
  except yaml.YAMLError as e:
69
81
  raise ConfigurationError(f"Invalid YAML in config file {self.config_file}: {e}")
70
82
  except IOError as e:
@@ -81,6 +93,12 @@ class Config:
81
93
  # Override with environment variables
82
94
  self._apply_env_overrides(merged_config)
83
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
+
84
102
  if os.getenv('KUBEXEC_TIMEOUT') is None:
85
103
  merged_config['timeout'] = self._parse_timeout(
86
104
  merged_config['timeout'], f"'timeout' in {self.config_file}"
@@ -89,16 +107,17 @@ class Config:
89
107
  return merged_config
90
108
 
91
109
  def _create_default_config(self) -> None:
92
- """Create default configuration file"""
93
- config_dir = os.path.dirname(self.config_file)
94
- os.makedirs(config_dir, exist_ok=True)
95
-
110
+ """Create default configuration file (best effort: defaults apply without it)"""
96
111
  # Use detected namespace in default config
97
112
  default_config = self.DEFAULT_CONFIG.copy()
98
113
  default_config['namespace'] = self._detected_namespace
99
114
 
100
- with open(self.config_file, 'w') as f:
101
- yaml.dump(default_config, f, default_flow_style=False, indent=2)
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")
102
121
 
103
122
  def _apply_env_overrides(self, config: Dict[str, Any]) -> None:
104
123
  """Apply environment variable overrides"""
@@ -108,6 +127,7 @@ class Config:
108
127
  'KUBEXEC_MEMORY': 'memory',
109
128
  'KUBEXEC_CPU': 'cpu',
110
129
  'KUBEXEC_WORKDIR': 'workdir',
130
+ 'KUBEXEC_DEFAULT_WORKDIR': 'default_workdir',
111
131
  'KUBEXEC_CLEANUP': 'cleanup',
112
132
  'KUBEXEC_VERBOSE': 'verbose',
113
133
  'KUBEXEC_VERIFY_SSL': 'verify_ssl',