kubek 0.4.2__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.
- kubek-0.4.2/LICENSE +21 -0
- kubek-0.4.2/PKG-INFO +117 -0
- kubek-0.4.2/README.md +86 -0
- kubek-0.4.2/kubectl-envx/src/envx/__init__.py +0 -0
- kubek-0.4.2/kubectl-envx/src/envx/__main__.py +18 -0
- kubek-0.4.2/kubectl-envx/src/envx/cli/__init__.py +0 -0
- kubek-0.4.2/kubectl-envx/src/envx/cli/main.py +159 -0
- kubek-0.4.2/kubectl-envx/src/envx/console.py +40 -0
- kubek-0.4.2/kubectl-envx/src/envx/kube.py +168 -0
- kubek-0.4.2/kubectl-envx/src/envx/style.py +27 -0
- kubek-0.4.2/kubectl-envx/src/envx/utils.py +51 -0
- kubek-0.4.2/kubectl-portfwd/src/portfwd/__init__.py +0 -0
- kubek-0.4.2/kubectl-portfwd/src/portfwd/__main__.py +8 -0
- kubek-0.4.2/kubectl-portfwd/src/portfwd/cli/__init__.py +0 -0
- kubek-0.4.2/kubectl-portfwd/src/portfwd/cli/main.py +1 -0
- kubek-0.4.2/kubectl-portfwd/src/portfwd/cli/port_forward.py +390 -0
- kubek-0.4.2/kubectl-portfwd/src/portfwd/config.py +65 -0
- kubek-0.4.2/kubectl-portfwd/src/portfwd/kube.py +176 -0
- kubek-0.4.2/kubectl-portfwd/src/portfwd/utils.py +31 -0
- kubek-0.4.2/kubek-shared/src/kubek/core/__init__.py +2 -0
- kubek-0.4.2/kubek-shared/src/kubek/ui/__init__.py +0 -0
- kubek-0.4.2/pyproject.toml +68 -0
kubek-0.4.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ohmycoffe
|
|
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.
|
kubek-0.4.2/PKG-INFO
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kubek
|
|
3
|
+
Version: 0.4.2
|
|
4
|
+
Summary: kubectl extensions
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: kubernetes,kubectl,kubectl plugins,cli,devtools,port forwarding,dotenv
|
|
8
|
+
Author: ohmycoffe
|
|
9
|
+
Author-email: ohmycoffe1@gmail.com
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
21
|
+
Classifier: Topic :: System :: Systems Administration
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Requires-Dist: psutil (>=7.2.2,<8.0.0)
|
|
24
|
+
Requires-Dist: pydantic (>=2.13.4,<3.0.0)
|
|
25
|
+
Requires-Dist: questionary (>=2.1.1,<3.0.0)
|
|
26
|
+
Requires-Dist: rich (>=15.0.0,<16.0.0)
|
|
27
|
+
Requires-Dist: typer (>=0.25.1,<0.26.0)
|
|
28
|
+
Project-URL: Repository, https://github.com/ohmycoffe/kubek
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
<div align="center">
|
|
32
|
+
|
|
33
|
+
# kubek
|
|
34
|
+
|
|
35
|
+
> `kubectl` plugins for friendlier Kubernetes interactions.
|
|
36
|
+
|
|
37
|
+
**kubek** (**kub**ernetes **e**xtension **k**it) is a collection of CLI tools that plug into `kubectl` and add interactive, developer-friendly shortcuts on top of it.
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+

|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Plugins
|
|
48
|
+
|
|
49
|
+
### 🔌 portfwd — Interactive port forwarding
|
|
50
|
+
|
|
51
|
+
Forwarding ports to Kubernetes services usually means running a separate `kubectl port-forward` command for each service, keeping track of which local port maps to what, and restarting them when they die. **portfwd** (**port** **f**or**w**ar**d**) replaces all of that with a single interactive command — pick your services, and it handles the rest.
|
|
52
|
+
|
|
53
|
+
- Fuzzy-search namespaces and services interactively
|
|
54
|
+
- Forward multiple services simultaneously in one command
|
|
55
|
+
- Live status table with real-time updates when a process dies
|
|
56
|
+
- Pin preferred local ports per service in a TOML config
|
|
57
|
+
- Fallback to a random free port if the preferred port is taken
|
|
58
|
+
- Inform user which services are currently forwarded and on which ports
|
|
59
|
+
|
|
60
|
+

|
|
61
|
+
|
|
62
|
+
→ [Full documentation](kubectl-portfwd/README.md)
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### 📦 envx — Export env vars from Kubernetes manifests
|
|
67
|
+
|
|
68
|
+
Getting credentials out of a running deployment usually means digging through `kubectl get deployment -o yaml`, copying values by hand, and reformatting them into a `.env` file. **envx** (**env**ironment e**x**porter) does it in one command — pick any Deployment or Argo WorkflowTemplate you have access to and get its env vars exported instantly.
|
|
69
|
+
|
|
70
|
+
- Fully interactive (fuzzy-search, arrow key navigation)
|
|
71
|
+
- Output as `.env` or JSON
|
|
72
|
+
- Pipe directly: `kubectl envx ... > .env` to produce a dotenv file
|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+
→ [Full documentation](kubectl-envx/README.md)
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
### Prerequisites
|
|
83
|
+
|
|
84
|
+
- Python 3.11+
|
|
85
|
+
- `kubectl` installed and configured with cluster access
|
|
86
|
+
|
|
87
|
+
### Install
|
|
88
|
+
|
|
89
|
+
The recommended way to install kubek is with [pipx](https://pipx.pypa.io/), which installs it in an isolated environment and automatically makes the plugin executables available on your PATH:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Latest stable release (recommended)
|
|
93
|
+
pipx install kubek
|
|
94
|
+
|
|
95
|
+
# Newest development version
|
|
96
|
+
pipx install git+https://github.com/ohmycoffe/kubek.git
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
If you use pip or another package manager, make sure the installation's `bin/` directory is on your PATH — `kubectl` discovers plugins by scanning PATH for executables prefixed with `kubectl-`.
|
|
100
|
+
|
|
101
|
+
### Verify
|
|
102
|
+
|
|
103
|
+
After installing, confirm both plugins are available:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
kubectl portfwd --help
|
|
107
|
+
kubectl envx --help
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
See each plugin's README for full usage details.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT — see [LICENSE](LICENSE).
|
|
117
|
+
|
kubek-0.4.2/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# kubek
|
|
4
|
+
|
|
5
|
+
> `kubectl` plugins for friendlier Kubernetes interactions.
|
|
6
|
+
|
|
7
|
+
**kubek** (**kub**ernetes **e**xtension **k**it) is a collection of CLI tools that plug into `kubectl` and add interactive, developer-friendly shortcuts on top of it.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Plugins
|
|
18
|
+
|
|
19
|
+
### 🔌 portfwd — Interactive port forwarding
|
|
20
|
+
|
|
21
|
+
Forwarding ports to Kubernetes services usually means running a separate `kubectl port-forward` command for each service, keeping track of which local port maps to what, and restarting them when they die. **portfwd** (**port** **f**or**w**ar**d**) replaces all of that with a single interactive command — pick your services, and it handles the rest.
|
|
22
|
+
|
|
23
|
+
- Fuzzy-search namespaces and services interactively
|
|
24
|
+
- Forward multiple services simultaneously in one command
|
|
25
|
+
- Live status table with real-time updates when a process dies
|
|
26
|
+
- Pin preferred local ports per service in a TOML config
|
|
27
|
+
- Fallback to a random free port if the preferred port is taken
|
|
28
|
+
- Inform user which services are currently forwarded and on which ports
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
→ [Full documentation](kubectl-portfwd/README.md)
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
### 📦 envx — Export env vars from Kubernetes manifests
|
|
37
|
+
|
|
38
|
+
Getting credentials out of a running deployment usually means digging through `kubectl get deployment -o yaml`, copying values by hand, and reformatting them into a `.env` file. **envx** (**env**ironment e**x**porter) does it in one command — pick any Deployment or Argo WorkflowTemplate you have access to and get its env vars exported instantly.
|
|
39
|
+
|
|
40
|
+
- Fully interactive (fuzzy-search, arrow key navigation)
|
|
41
|
+
- Output as `.env` or JSON
|
|
42
|
+
- Pipe directly: `kubectl envx ... > .env` to produce a dotenv file
|
|
43
|
+
|
|
44
|
+

|
|
45
|
+
|
|
46
|
+
→ [Full documentation](kubectl-envx/README.md)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
### Prerequisites
|
|
53
|
+
|
|
54
|
+
- Python 3.11+
|
|
55
|
+
- `kubectl` installed and configured with cluster access
|
|
56
|
+
|
|
57
|
+
### Install
|
|
58
|
+
|
|
59
|
+
The recommended way to install kubek is with [pipx](https://pipx.pypa.io/), which installs it in an isolated environment and automatically makes the plugin executables available on your PATH:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Latest stable release (recommended)
|
|
63
|
+
pipx install kubek
|
|
64
|
+
|
|
65
|
+
# Newest development version
|
|
66
|
+
pipx install git+https://github.com/ohmycoffe/kubek.git
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
If you use pip or another package manager, make sure the installation's `bin/` directory is on your PATH — `kubectl` discovers plugins by scanning PATH for executables prefixed with `kubectl-`.
|
|
70
|
+
|
|
71
|
+
### Verify
|
|
72
|
+
|
|
73
|
+
After installing, confirm both plugins are available:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
kubectl portfwd --help
|
|
77
|
+
kubectl envx --help
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
See each plugin's README for full usage details.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT — see [LICENSE](LICENSE).
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from envx.cli.main import app
|
|
4
|
+
from envx.console import console
|
|
5
|
+
from envx.style import COLOR_WARNING
|
|
6
|
+
|
|
7
|
+
logging.basicConfig()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def deprecated_entry() -> None:
|
|
11
|
+
console.print(
|
|
12
|
+
f"[bold {COLOR_WARNING}]Warning:[/] 'envx' has been deprecated, use 'kenvx' instead."
|
|
13
|
+
)
|
|
14
|
+
app()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if __name__ == "__main__":
|
|
18
|
+
app()
|
|
File without changes
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import enum
|
|
4
|
+
import json
|
|
5
|
+
import subprocess
|
|
6
|
+
from typing import Annotated
|
|
7
|
+
|
|
8
|
+
import questionary
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
from envx.console import console, print_error
|
|
12
|
+
from envx.kube import (
|
|
13
|
+
get_available_deployments,
|
|
14
|
+
get_available_namespaces,
|
|
15
|
+
get_available_workflowtemplates,
|
|
16
|
+
get_deployment_envs,
|
|
17
|
+
get_workflowtemplate_envs,
|
|
18
|
+
)
|
|
19
|
+
from envx.style import COLOR_MUTED, STYLE
|
|
20
|
+
from envx.utils import export_as_dotenv, resolve_namespace, setup_logging
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ResourceKind(str, enum.Enum):
|
|
24
|
+
DEPLOYMENT = "deployment"
|
|
25
|
+
WORKFLOWTEMPLATE = "workflowtemplate"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ExportFormat(str, enum.Enum):
|
|
29
|
+
ENV = "env"
|
|
30
|
+
JSON = "json"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
app = typer.Typer()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def select_resource_kind() -> ResourceKind:
|
|
37
|
+
selected = questionary.select(
|
|
38
|
+
"Select a kind:",
|
|
39
|
+
choices=[
|
|
40
|
+
questionary.Choice(
|
|
41
|
+
title="Deployment",
|
|
42
|
+
value=ResourceKind.DEPLOYMENT,
|
|
43
|
+
description="(Kubernetes Deployment)",
|
|
44
|
+
),
|
|
45
|
+
questionary.Choice(
|
|
46
|
+
title="WorkflowTemplate",
|
|
47
|
+
value=ResourceKind.WORKFLOWTEMPLATE,
|
|
48
|
+
description="(Argo WorkflowTemplate)",
|
|
49
|
+
),
|
|
50
|
+
],
|
|
51
|
+
use_jk_keys=False,
|
|
52
|
+
style=STYLE,
|
|
53
|
+
).ask()
|
|
54
|
+
if not selected:
|
|
55
|
+
raise typer.Exit(code=0)
|
|
56
|
+
return ResourceKind(selected)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@app.callback(invoke_without_command=True)
|
|
60
|
+
def get(
|
|
61
|
+
kind: Annotated[
|
|
62
|
+
ResourceKind | None,
|
|
63
|
+
typer.Option(
|
|
64
|
+
help="Kind of resource to get parameters for. If not provided, you will be prompted to select one.",
|
|
65
|
+
),
|
|
66
|
+
] = None,
|
|
67
|
+
namespace: Annotated[
|
|
68
|
+
str | None,
|
|
69
|
+
typer.Option(
|
|
70
|
+
envvar="KENVX_NAMESPACE",
|
|
71
|
+
help="Kubernetes namespace. If not provided, you will be prompted to select one.",
|
|
72
|
+
),
|
|
73
|
+
] = None,
|
|
74
|
+
name: Annotated[
|
|
75
|
+
str | None,
|
|
76
|
+
typer.Option(
|
|
77
|
+
help="Name of the resource. If not provided, you will be prompted to select one.",
|
|
78
|
+
),
|
|
79
|
+
] = None,
|
|
80
|
+
output: ExportFormat = ExportFormat.ENV,
|
|
81
|
+
verbose: Annotated[
|
|
82
|
+
int,
|
|
83
|
+
typer.Option(
|
|
84
|
+
"--verbose", "-v", count=True, help="Verbose output. Use -vv for debug."
|
|
85
|
+
),
|
|
86
|
+
] = 0,
|
|
87
|
+
):
|
|
88
|
+
"""
|
|
89
|
+
Get environment variables for a Kubernetes deployment or Argo WorkflowTemplate.
|
|
90
|
+
"""
|
|
91
|
+
setup_logging(verbose)
|
|
92
|
+
if kind is None:
|
|
93
|
+
kind = select_resource_kind()
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
with console.status(f"[italic {COLOR_MUTED}]Fetching available namespaces…[/]"):
|
|
97
|
+
namespaces = get_available_namespaces()
|
|
98
|
+
except subprocess.CalledProcessError as e:
|
|
99
|
+
print_error(e, "Failed to fetch available namespaces")
|
|
100
|
+
raise typer.Exit(code=1) from None
|
|
101
|
+
|
|
102
|
+
namespace = resolve_namespace(namespace, available_namespaces=namespaces)
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
with console.status(
|
|
106
|
+
f"[italic {COLOR_MUTED}]Fetching available {kind.value}s in {namespace}…[/]"
|
|
107
|
+
):
|
|
108
|
+
if kind == ResourceKind.DEPLOYMENT:
|
|
109
|
+
resources = get_available_deployments(namespace=namespace)
|
|
110
|
+
else:
|
|
111
|
+
resources = get_available_workflowtemplates(namespace=namespace)
|
|
112
|
+
except subprocess.CalledProcessError as e:
|
|
113
|
+
print_error(
|
|
114
|
+
e, f"Failed to fetch available {kind.value}s in namespace '{namespace}'"
|
|
115
|
+
)
|
|
116
|
+
raise typer.Exit(code=1) from None
|
|
117
|
+
if not resources:
|
|
118
|
+
console.print(f"[red]Error: no {kind.value}s found in namespace '{namespace}'")
|
|
119
|
+
raise typer.Exit(code=1)
|
|
120
|
+
|
|
121
|
+
if not name:
|
|
122
|
+
name = questionary.select(
|
|
123
|
+
f"Select a {kind.value}:",
|
|
124
|
+
choices=resources,
|
|
125
|
+
use_search_filter=True,
|
|
126
|
+
use_jk_keys=False,
|
|
127
|
+
style=STYLE,
|
|
128
|
+
).ask()
|
|
129
|
+
if not name:
|
|
130
|
+
raise typer.Exit(code=0)
|
|
131
|
+
|
|
132
|
+
if name not in resources:
|
|
133
|
+
console.print(
|
|
134
|
+
f"[red]Error:[/red] {kind.value} '{name}' not found in namespace '{namespace}'."
|
|
135
|
+
)
|
|
136
|
+
raise typer.Exit(code=1)
|
|
137
|
+
|
|
138
|
+
try:
|
|
139
|
+
with console.status(
|
|
140
|
+
f"[italic {COLOR_MUTED}]Fetching environment variables…[/]"
|
|
141
|
+
):
|
|
142
|
+
if kind == ResourceKind.DEPLOYMENT:
|
|
143
|
+
vals = get_deployment_envs(namespace=namespace, name=name)
|
|
144
|
+
else:
|
|
145
|
+
vals = get_workflowtemplate_envs(namespace=namespace, name=name)
|
|
146
|
+
except subprocess.CalledProcessError as e:
|
|
147
|
+
print_error(e, f"Failed to fetch environment variables for '{name}'")
|
|
148
|
+
raise typer.Exit(code=1) from None
|
|
149
|
+
|
|
150
|
+
if output == ExportFormat.JSON:
|
|
151
|
+
formatted = json.dumps(vals, sort_keys=True)
|
|
152
|
+
elif output == ExportFormat.ENV:
|
|
153
|
+
formatted = export_as_dotenv(vals=vals, name=name)
|
|
154
|
+
print(formatted)
|
|
155
|
+
raise typer.Exit(code=0)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
if __name__ == "__main__":
|
|
159
|
+
app()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import subprocess
|
|
5
|
+
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.panel import Panel
|
|
8
|
+
|
|
9
|
+
from envx.style import COLOR_ERROR
|
|
10
|
+
|
|
11
|
+
console = Console(stderr=True)
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def print_error(e: subprocess.CalledProcessError, msg: str) -> None:
|
|
17
|
+
logger.debug("kubectl error", exc_info=e, stack_info=True)
|
|
18
|
+
stderr = (e.stderr or "no output").strip()
|
|
19
|
+
stdout = (e.stdout or "no output").strip()
|
|
20
|
+
cmd = " ".join(e.cmd)
|
|
21
|
+
content = "\n".join(
|
|
22
|
+
[
|
|
23
|
+
"[dim]stderr:[/dim]",
|
|
24
|
+
f"[{COLOR_ERROR}]{stderr}[/]",
|
|
25
|
+
"",
|
|
26
|
+
"[dim]stdout:[/dim]",
|
|
27
|
+
stdout,
|
|
28
|
+
"",
|
|
29
|
+
f"[dim]command:[/dim] {cmd}",
|
|
30
|
+
f"[dim]exit code:[/dim] {e.returncode}",
|
|
31
|
+
]
|
|
32
|
+
)
|
|
33
|
+
console.print(
|
|
34
|
+
Panel(
|
|
35
|
+
content,
|
|
36
|
+
title=f"[bold {COLOR_ERROR}]{msg}[/]",
|
|
37
|
+
border_style=COLOR_ERROR,
|
|
38
|
+
expand=False,
|
|
39
|
+
)
|
|
40
|
+
)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import logging
|
|
5
|
+
import re
|
|
6
|
+
import subprocess
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
from functools import lru_cache
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from envx.utils import decode
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def call_subprocess(cmd: list[str]) -> str:
|
|
17
|
+
logger.debug("%s", " ".join(cmd))
|
|
18
|
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
|
19
|
+
return result.stdout
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_available_namespaces() -> list[str]:
|
|
23
|
+
cmd = ["kubectl", "get", "namespaces", "-o", "json"]
|
|
24
|
+
result = call_subprocess(cmd)
|
|
25
|
+
data = json.loads(result)
|
|
26
|
+
return [el["metadata"]["name"] for el in data["items"]]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@lru_cache
|
|
30
|
+
def get_secret(namespace: str, name: str) -> dict[str, Any]:
|
|
31
|
+
cmd = ["kubectl", "get", "secret", name, "-n", namespace, "-o", "json"]
|
|
32
|
+
result = call_subprocess(cmd)
|
|
33
|
+
secret = json.loads(result)
|
|
34
|
+
return secret
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@lru_cache
|
|
38
|
+
def get_configmap(namespace: str, name: str) -> dict[str, Any]:
|
|
39
|
+
cmd = ["kubectl", "get", "configmap", name, "-n", namespace, "-o", "json"]
|
|
40
|
+
result = call_subprocess(cmd)
|
|
41
|
+
configmap = json.loads(result)
|
|
42
|
+
return configmap
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _clean_key(key: str) -> str:
|
|
46
|
+
def strip_argo_inputs_param(key: str) -> str:
|
|
47
|
+
match = re.match(r"^\{\{inputs\.parameters\.(?P<param_name>\w+)\}\}$", key)
|
|
48
|
+
return match.group("param_name") if match else key
|
|
49
|
+
|
|
50
|
+
cleanups: list[Callable[[str], str]] = [
|
|
51
|
+
strip_argo_inputs_param,
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
for cleanup in cleanups:
|
|
55
|
+
key = cleanup(key)
|
|
56
|
+
return key
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_available_deployments(namespace: str) -> list[str]:
|
|
60
|
+
cmd = ["kubectl", "get", "deployment", "-n", namespace, "-o", "json"]
|
|
61
|
+
result = call_subprocess(cmd)
|
|
62
|
+
data = json.loads(result)
|
|
63
|
+
return [el["metadata"]["name"] for el in data["items"]]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def get_deployment_envs(namespace: str, name: str) -> dict[str, str]:
|
|
67
|
+
cmd = ["kubectl", "get", "deployment", name, "-n", namespace, "-o", "json"]
|
|
68
|
+
result = call_subprocess(cmd)
|
|
69
|
+
deployment = json.loads(result)
|
|
70
|
+
containers = deployment["spec"]["template"]["spec"]["containers"]
|
|
71
|
+
if len(containers) != 1:
|
|
72
|
+
raise ValueError(f"Expected 1 container, got {len(containers)}")
|
|
73
|
+
return extract_envs_from_container(namespace=namespace, container=containers[0])
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_available_workflowtemplates(namespace: str) -> list[str]:
|
|
77
|
+
cmd = ["kubectl", "get", "workflowtemplate", "-n", namespace, "-o", "json"]
|
|
78
|
+
result = call_subprocess(cmd)
|
|
79
|
+
data = json.loads(result)
|
|
80
|
+
return [el["metadata"]["name"] for el in data["items"]]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def get_workflowtemplate_envs(namespace: str, name: str) -> dict[str, str]:
|
|
84
|
+
cmd = ["kubectl", "get", "workflowtemplate", name, "-n", namespace, "-o", "json"]
|
|
85
|
+
result = call_subprocess(cmd)
|
|
86
|
+
workflow = json.loads(result)
|
|
87
|
+
envs = {}
|
|
88
|
+
for template in workflow["spec"]["templates"]:
|
|
89
|
+
if "container" not in template:
|
|
90
|
+
continue
|
|
91
|
+
fallback_keys = {
|
|
92
|
+
p["name"]: p["default"]
|
|
93
|
+
for p in template.get("inputs", {}).get("parameters", [])
|
|
94
|
+
if "default" in p
|
|
95
|
+
}
|
|
96
|
+
envs.update(
|
|
97
|
+
extract_envs_from_container(
|
|
98
|
+
namespace, template["container"], fallback_keys=fallback_keys
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
return envs
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def extract_envs_from_container(
|
|
105
|
+
namespace: str,
|
|
106
|
+
container: dict[str, Any],
|
|
107
|
+
fallback_keys: dict[str, str] | None = None,
|
|
108
|
+
) -> dict[str, str]:
|
|
109
|
+
if fallback_keys is None:
|
|
110
|
+
fallback_keys = {}
|
|
111
|
+
result = {}
|
|
112
|
+
if "envFrom" in container:
|
|
113
|
+
for env_from in container["envFrom"]:
|
|
114
|
+
if "configMapRef" in env_from:
|
|
115
|
+
configmap = get_configmap(namespace, env_from["configMapRef"]["name"])
|
|
116
|
+
result.update(configmap["data"])
|
|
117
|
+
elif "secretRef" in env_from:
|
|
118
|
+
secret_name = env_from["secretRef"]["name"]
|
|
119
|
+
secret = get_secret(namespace, secret_name)
|
|
120
|
+
encoded = {k: decode(v) for k, v in secret["data"].items()}
|
|
121
|
+
result.update(encoded)
|
|
122
|
+
else:
|
|
123
|
+
raise ValueError(f"Unknown envFrom format: {env_from}")
|
|
124
|
+
|
|
125
|
+
if "env" in container:
|
|
126
|
+
for env in container["env"]:
|
|
127
|
+
name = env["name"]
|
|
128
|
+
if "value" in env:
|
|
129
|
+
value = env["value"]
|
|
130
|
+
result[name] = value
|
|
131
|
+
elif "valueFrom" in env:
|
|
132
|
+
value_from = env["valueFrom"]
|
|
133
|
+
if "configMapKeyRef" in value_from:
|
|
134
|
+
configmap = get_configmap(
|
|
135
|
+
namespace, value_from["configMapKeyRef"]["name"]
|
|
136
|
+
)
|
|
137
|
+
key = value_from["configMapKeyRef"]["key"]
|
|
138
|
+
if key not in configmap["data"]:
|
|
139
|
+
key = fallback_keys.get(_clean_key(key), key)
|
|
140
|
+
if key not in configmap["data"]:
|
|
141
|
+
logger.warning(
|
|
142
|
+
f"{name} won't be set: key {key} not found in ConfigMap {value_from['configMapKeyRef']['name']}"
|
|
143
|
+
)
|
|
144
|
+
value = ""
|
|
145
|
+
else:
|
|
146
|
+
value = configmap["data"][key]
|
|
147
|
+
result[name] = value
|
|
148
|
+
elif "secretKeyRef" in value_from:
|
|
149
|
+
secret_name = value_from["secretKeyRef"]["name"]
|
|
150
|
+
encoded = get_secret(namespace, secret_name)
|
|
151
|
+
key = value_from["secretKeyRef"]["key"]
|
|
152
|
+
if key not in encoded["data"]:
|
|
153
|
+
key = fallback_keys.get(_clean_key(key), key)
|
|
154
|
+
if key not in encoded["data"]:
|
|
155
|
+
logger.warning(
|
|
156
|
+
f"{name} won't be set: key {key} not found in Secret {secret_name}"
|
|
157
|
+
)
|
|
158
|
+
value = ""
|
|
159
|
+
else:
|
|
160
|
+
value = decode(encoded["data"][key])
|
|
161
|
+
result[name] = value
|
|
162
|
+
else:
|
|
163
|
+
logger.warning(
|
|
164
|
+
f"Unknown valueFrom format: {value_from} for {name} ({env})"
|
|
165
|
+
)
|
|
166
|
+
else:
|
|
167
|
+
logger.warning(f"Unknown env format: {env}")
|
|
168
|
+
return result
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from questionary import Style
|
|
2
|
+
|
|
3
|
+
# fmt: off
|
|
4
|
+
COLOR_ACCENT = "#e5c07b" # yellow — draws attention (qmark)
|
|
5
|
+
COLOR_SUCCESS = "#98c379" # green — confirmed / selected
|
|
6
|
+
COLOR_ACTIVE = "#61afef" # blue — navigation / pointer
|
|
7
|
+
COLOR_WARNING = "#d19a66" # orange — warnings / cautions
|
|
8
|
+
COLOR_ERROR = "#e06c75" # red — errors / failures
|
|
9
|
+
COLOR_MUTED = "#5c6370" # gray — secondary elements
|
|
10
|
+
COLOR_SUBTLE = "#4b5263" # dark gray — near-invisible hints
|
|
11
|
+
|
|
12
|
+
# fmt: off
|
|
13
|
+
STYLE = Style(
|
|
14
|
+
[
|
|
15
|
+
("qmark", f"fg:{COLOR_ACCENT} bold"),
|
|
16
|
+
("question", "bold"),
|
|
17
|
+
("answer", f"fg:{COLOR_SUCCESS} bold"),
|
|
18
|
+
("pointer", f"fg:{COLOR_ACTIVE} bold"),
|
|
19
|
+
("highlighted", f"fg:{COLOR_ACTIVE} bold"),
|
|
20
|
+
("selected", f"fg:{COLOR_SUCCESS}"),
|
|
21
|
+
("separator", f"fg:{COLOR_MUTED}"),
|
|
22
|
+
("instruction", f"fg:{COLOR_SUBTLE} italic"),
|
|
23
|
+
("text", ""),
|
|
24
|
+
("disabled", f"fg:{COLOR_SUBTLE} italic"),
|
|
25
|
+
]
|
|
26
|
+
)
|
|
27
|
+
# fmt: on
|