kubex 0.1.0a1__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.
- kubex-0.1.0a1/.gitignore +171 -0
- kubex-0.1.0a1/PKG-INFO +53 -0
- kubex-0.1.0a1/README.md +25 -0
- kubex-0.1.0a1/kubex/__init__.py +4 -0
- kubex-0.1.0a1/kubex/__version__.py +1 -0
- kubex-0.1.0a1/kubex/client/__init__.py +5 -0
- kubex-0.1.0a1/kubex/client/api/__init__.py +3 -0
- kubex-0.1.0a1/kubex/client/api/_logs.py +64 -0
- kubex-0.1.0a1/kubex/client/api/_metadata.py +65 -0
- kubex-0.1.0a1/kubex/client/api/_protocol.py +14 -0
- kubex-0.1.0a1/kubex/client/api/_subressource.py +105 -0
- kubex-0.1.0a1/kubex/client/api/api.py +187 -0
- kubex-0.1.0a1/kubex/client/client.py +157 -0
- kubex-0.1.0a1/kubex/client/configuration.py +252 -0
- kubex-0.1.0a1/kubex/client/file_config.py +95 -0
- kubex-0.1.0a1/kubex/client/incluster_config.py +39 -0
- kubex-0.1.0a1/kubex/core/__init__.py +3 -0
- kubex-0.1.0a1/kubex/core/exceptions.py +73 -0
- kubex-0.1.0a1/kubex/core/params.py +273 -0
- kubex-0.1.0a1/kubex/core/patch.py +93 -0
- kubex-0.1.0a1/kubex/core/request.py +20 -0
- kubex-0.1.0a1/kubex/core/request_builder/__init__.py +0 -0
- kubex-0.1.0a1/kubex/core/request_builder/builder.py +120 -0
- kubex-0.1.0a1/kubex/core/request_builder/constants.py +7 -0
- kubex-0.1.0a1/kubex/core/request_builder/logs.py +27 -0
- kubex-0.1.0a1/kubex/core/request_builder/metadata.py +68 -0
- kubex-0.1.0a1/kubex/core/request_builder/subresource.py +53 -0
- kubex-0.1.0a1/kubex/core/response.py +18 -0
- kubex-0.1.0a1/kubex/core/subresource.py +15 -0
- kubex-0.1.0a1/kubex/models/__init__.py +0 -0
- kubex-0.1.0a1/kubex/models/base.py +8 -0
- kubex-0.1.0a1/kubex/models/base_entity.py +15 -0
- kubex-0.1.0a1/kubex/models/interfaces.py +19 -0
- kubex-0.1.0a1/kubex/models/list_entity.py +14 -0
- kubex-0.1.0a1/kubex/models/metadata.py +45 -0
- kubex-0.1.0a1/kubex/models/namespace.py +26 -0
- kubex-0.1.0a1/kubex/models/partial_object_meta.py +14 -0
- kubex-0.1.0a1/kubex/models/pod.py +31 -0
- kubex-0.1.0a1/kubex/models/resource_config.py +156 -0
- kubex-0.1.0a1/kubex/models/scale.py +22 -0
- kubex-0.1.0a1/kubex/models/status.py +60 -0
- kubex-0.1.0a1/kubex/models/typing.py +9 -0
- kubex-0.1.0a1/kubex/models/watch_event.py +36 -0
- kubex-0.1.0a1/kubex/py.typed +0 -0
- kubex-0.1.0a1/pyproject.toml +69 -0
kubex-0.1.0a1/.gitignore
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
110
|
+
.pdm.toml
|
|
111
|
+
.pdm-python
|
|
112
|
+
.pdm-build/
|
|
113
|
+
|
|
114
|
+
uv.lock
|
|
115
|
+
.python-version
|
|
116
|
+
|
|
117
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
118
|
+
__pypackages__/
|
|
119
|
+
|
|
120
|
+
# Celery stuff
|
|
121
|
+
celerybeat-schedule
|
|
122
|
+
celerybeat.pid
|
|
123
|
+
|
|
124
|
+
# SageMath parsed files
|
|
125
|
+
*.sage.py
|
|
126
|
+
|
|
127
|
+
# Environments
|
|
128
|
+
.env
|
|
129
|
+
.venv
|
|
130
|
+
env/
|
|
131
|
+
venv/
|
|
132
|
+
ENV/
|
|
133
|
+
env.bak/
|
|
134
|
+
venv.bak/
|
|
135
|
+
|
|
136
|
+
# Spyder project settings
|
|
137
|
+
.spyderproject
|
|
138
|
+
.spyproject
|
|
139
|
+
|
|
140
|
+
# Rope project settings
|
|
141
|
+
.ropeproject
|
|
142
|
+
|
|
143
|
+
# mkdocs documentation
|
|
144
|
+
/site
|
|
145
|
+
|
|
146
|
+
# mypy
|
|
147
|
+
.mypy_cache/
|
|
148
|
+
.dmypy.json
|
|
149
|
+
dmypy.json
|
|
150
|
+
|
|
151
|
+
# Pyre type checker
|
|
152
|
+
.pyre/
|
|
153
|
+
|
|
154
|
+
# pytype static type analyzer
|
|
155
|
+
.pytype/
|
|
156
|
+
|
|
157
|
+
# Cython debug symbols
|
|
158
|
+
cython_debug/
|
|
159
|
+
|
|
160
|
+
# PyCharm
|
|
161
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
162
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
163
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
164
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
165
|
+
#.idea/
|
|
166
|
+
*.code-workspace
|
|
167
|
+
.vscode/
|
|
168
|
+
|
|
169
|
+
# Ruff
|
|
170
|
+
.ruff_cache/
|
|
171
|
+
scratches/
|
kubex-0.1.0a1/PKG-INFO
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: kubex
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Asynchronous Kubernetes client inspired by kube.rs
|
|
5
|
+
Project-URL: Homepage, https://github.com/codemageddon/kubex
|
|
6
|
+
Project-URL: Repository, https://github.com/codemageddon/kubex.git
|
|
7
|
+
Project-URL: Issues, https://github.com/codemageddon/kubex/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/codemageddon/kubex/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Codemageddon <dev@codemageddon.me>
|
|
10
|
+
Maintainer-email: Codemageddon <dev@codemageddon.me>
|
|
11
|
+
License: MIT License
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
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
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: httpx>=0.27.2
|
|
23
|
+
Requires-Dist: pydantic<3,>=2.0
|
|
24
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
25
|
+
Provides-Extra: aiohttp
|
|
26
|
+
Requires-Dist: aiohttp>=3.11.2; extra == 'aiohttp'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Kubex
|
|
30
|
+
|
|
31
|
+
Kubex is a Kubernetes client library for Python inspired by kube.rs. It is built on top of [Pydantic](https://github.com/pydantic/pydantic) and is async-runtime agnostic.
|
|
32
|
+
|
|
33
|
+
> *ATTENTION:* Kubex is currently under active development, and backward compatibility may be broken in future releases.
|
|
34
|
+
|
|
35
|
+
# Completed Features:
|
|
36
|
+
|
|
37
|
+
* Basic API interface that allows interaction with almost any Kubernetes resources and their methods.
|
|
38
|
+
* In-cluster client authorization with token refreshing.
|
|
39
|
+
* Basic support for kubeconfig files.
|
|
40
|
+
|
|
41
|
+
# Planned Features:
|
|
42
|
+
|
|
43
|
+
* [ ] Support for OIDC and other authentication extensions.
|
|
44
|
+
* [ ] Integration with aiohttp as an internal HTTP client.
|
|
45
|
+
* [ ] Fine-tuning of timeouts.
|
|
46
|
+
* [ ] Comprehensive library of Kubernetes models.
|
|
47
|
+
* [ ] Dynamic API object creation to exclude unsupported methods for resources (requires research for mypy compatibility).
|
|
48
|
+
* [ ] Potential synchronous version of the client.
|
|
49
|
+
* [ ] Additional tests and examples.
|
|
50
|
+
* [ ] JsonPatch models.
|
|
51
|
+
* [ ] Allow `namespace` to be a method parameter instead of an API instance-scoped parameter.
|
|
52
|
+
* [ ] Enhanced support for subresources (status, ephemeral containers).
|
|
53
|
+
* [ ] Support for Pod.attach.
|
kubex-0.1.0a1/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Kubex
|
|
2
|
+
|
|
3
|
+
Kubex is a Kubernetes client library for Python inspired by kube.rs. It is built on top of [Pydantic](https://github.com/pydantic/pydantic) and is async-runtime agnostic.
|
|
4
|
+
|
|
5
|
+
> *ATTENTION:* Kubex is currently under active development, and backward compatibility may be broken in future releases.
|
|
6
|
+
|
|
7
|
+
# Completed Features:
|
|
8
|
+
|
|
9
|
+
* Basic API interface that allows interaction with almost any Kubernetes resources and their methods.
|
|
10
|
+
* In-cluster client authorization with token refreshing.
|
|
11
|
+
* Basic support for kubeconfig files.
|
|
12
|
+
|
|
13
|
+
# Planned Features:
|
|
14
|
+
|
|
15
|
+
* [ ] Support for OIDC and other authentication extensions.
|
|
16
|
+
* [ ] Integration with aiohttp as an internal HTTP client.
|
|
17
|
+
* [ ] Fine-tuning of timeouts.
|
|
18
|
+
* [ ] Comprehensive library of Kubernetes models.
|
|
19
|
+
* [ ] Dynamic API object creation to exclude unsupported methods for resources (requires research for mypy compatibility).
|
|
20
|
+
* [ ] Potential synchronous version of the client.
|
|
21
|
+
* [ ] Additional tests and examples.
|
|
22
|
+
* [ ] JsonPatch models.
|
|
23
|
+
* [ ] Allow `namespace` to be a method parameter instead of an API instance-scoped parameter.
|
|
24
|
+
* [ ] Enhanced support for subresources (status, ephemeral containers).
|
|
25
|
+
* [ ] Support for Pod.attach.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "0.1.0-alpha.1"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from typing import AsyncGenerator
|
|
2
|
+
|
|
3
|
+
from kubex.core.params import LogOptions
|
|
4
|
+
from kubex.models.interfaces import HasLogs
|
|
5
|
+
from kubex.models.typing import ResourceType
|
|
6
|
+
|
|
7
|
+
from ._protocol import ApiProtocol
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LogsMixin(ApiProtocol[ResourceType]):
|
|
11
|
+
def _check_implemented(self) -> None:
|
|
12
|
+
if not issubclass(self._resource, HasLogs):
|
|
13
|
+
raise NotImplementedError("Logs are only supported for Pods")
|
|
14
|
+
|
|
15
|
+
# TODO: Investigate how to force mypy to complain on logs calling with non-Pod resources
|
|
16
|
+
# @overload
|
|
17
|
+
# def logs(
|
|
18
|
+
# self: Type[ApiProtocol[Any]],
|
|
19
|
+
# name: str,
|
|
20
|
+
# options: LogOptions | None = None,
|
|
21
|
+
# ) -> NoReturn: ...
|
|
22
|
+
|
|
23
|
+
# @overload
|
|
24
|
+
# def logs(
|
|
25
|
+
# self: Type[ApiProtocol[PodProtocol]],
|
|
26
|
+
# name: str,
|
|
27
|
+
# options: LogOptions | None = None,
|
|
28
|
+
# ) -> Awaitable[str]: ...
|
|
29
|
+
|
|
30
|
+
async def logs(self, name: str, options: LogOptions | None = None) -> str:
|
|
31
|
+
self._check_implemented()
|
|
32
|
+
self._check_namespace()
|
|
33
|
+
request = self._request_builder.logs(
|
|
34
|
+
name, options=options or LogOptions.default()
|
|
35
|
+
)
|
|
36
|
+
response = await self._client.request(request)
|
|
37
|
+
return response.text
|
|
38
|
+
|
|
39
|
+
# TODO: Investigate how to force mypy to complain on stream_logs calling with non-Pod resources
|
|
40
|
+
# @overload
|
|
41
|
+
# def stream_logs(
|
|
42
|
+
# self: Type[ApiProtocol[ResourceType]],
|
|
43
|
+
# name: str,
|
|
44
|
+
# options: LogOptions | None = None,
|
|
45
|
+
# ) -> NoReturn: ...
|
|
46
|
+
|
|
47
|
+
# @overload
|
|
48
|
+
# def stream_logs(
|
|
49
|
+
# self: Type[ApiProtocol[PodProtocol]],
|
|
50
|
+
# name: str,
|
|
51
|
+
# options: LogOptions | None = None,
|
|
52
|
+
# ) -> AsyncGenerator[str, None]: ...
|
|
53
|
+
|
|
54
|
+
async def stream_logs(
|
|
55
|
+
self, name: str, options: LogOptions | None = None
|
|
56
|
+
) -> AsyncGenerator[str, None]:
|
|
57
|
+
self._check_implemented()
|
|
58
|
+
self._check_namespace()
|
|
59
|
+
request = self._request_builder.stream_logs(
|
|
60
|
+
name, options=options or LogOptions.default()
|
|
61
|
+
)
|
|
62
|
+
# TODO: ReadTimeout
|
|
63
|
+
async for line in self._client.stream_lines(request):
|
|
64
|
+
yield line
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import AsyncGenerator
|
|
5
|
+
|
|
6
|
+
from kubex.client.api._protocol import ApiProtocol
|
|
7
|
+
from kubex.core.params import GetOptions, ListOptions, PatchOptions, WatchOptions
|
|
8
|
+
from kubex.core.patch import (
|
|
9
|
+
ApplyPatch,
|
|
10
|
+
JsonPatch,
|
|
11
|
+
MergePatch,
|
|
12
|
+
StrategicMergePatch,
|
|
13
|
+
)
|
|
14
|
+
from kubex.models.list_entity import ListEntity
|
|
15
|
+
from kubex.models.partial_object_meta import PartialObjectMetadata
|
|
16
|
+
from kubex.models.typing import (
|
|
17
|
+
ResourceType,
|
|
18
|
+
)
|
|
19
|
+
from kubex.models.watch_event import WatchEvent
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MetadataMixin(ApiProtocol[ResourceType]):
|
|
23
|
+
async def get_metadata(
|
|
24
|
+
self, name: str, options: GetOptions | None = None
|
|
25
|
+
) -> PartialObjectMetadata:
|
|
26
|
+
self._check_namespace()
|
|
27
|
+
request = self._request_builder.get_metadata(
|
|
28
|
+
name, options=options or GetOptions.default()
|
|
29
|
+
)
|
|
30
|
+
response = await self._client.request(request)
|
|
31
|
+
return PartialObjectMetadata.model_validate_json(response.content)
|
|
32
|
+
|
|
33
|
+
async def list_metadata(
|
|
34
|
+
self, options: ListOptions | None = None
|
|
35
|
+
) -> ListEntity[PartialObjectMetadata]:
|
|
36
|
+
request = self._request_builder.list_metadata(options or ListOptions.default())
|
|
37
|
+
response = await self._client.request(request)
|
|
38
|
+
model = PartialObjectMetadata.__RESOURCE_CONFIG__.list_model
|
|
39
|
+
return model.model_validate_json(response.content)
|
|
40
|
+
|
|
41
|
+
async def patch_metadata(
|
|
42
|
+
self,
|
|
43
|
+
name: str,
|
|
44
|
+
patch: ApplyPatch[ResourceType]
|
|
45
|
+
| MergePatch[ResourceType]
|
|
46
|
+
| StrategicMergePatch[ResourceType]
|
|
47
|
+
| JsonPatch,
|
|
48
|
+
options: PatchOptions,
|
|
49
|
+
) -> PartialObjectMetadata:
|
|
50
|
+
self._check_namespace()
|
|
51
|
+
request = self._request_builder.patch_metadata(name, options, patch)
|
|
52
|
+
response = await self._client.request(request)
|
|
53
|
+
return PartialObjectMetadata.model_validate_json(response.content)
|
|
54
|
+
|
|
55
|
+
async def watch_metadata(
|
|
56
|
+
self, options: WatchOptions | None = None, resource_version: str | None = None
|
|
57
|
+
) -> AsyncGenerator[
|
|
58
|
+
WatchEvent[PartialObjectMetadata],
|
|
59
|
+
None,
|
|
60
|
+
]:
|
|
61
|
+
request = self._request_builder.watch_metadata(
|
|
62
|
+
options or WatchOptions.default(), resource_version=resource_version
|
|
63
|
+
)
|
|
64
|
+
async for line in self._client.stream_lines(request):
|
|
65
|
+
yield WatchEvent(PartialObjectMetadata, json.loads(line))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Protocol, Type
|
|
2
|
+
|
|
3
|
+
from kubex.client.client import Client
|
|
4
|
+
from kubex.core.request_builder.builder import RequestBuilder
|
|
5
|
+
from kubex.models.typing import ResourceType
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ApiProtocol(Protocol[ResourceType]):
|
|
9
|
+
_resource: Type[ResourceType]
|
|
10
|
+
_client: Client
|
|
11
|
+
_request_builder: RequestBuilder
|
|
12
|
+
_namespace: str | None
|
|
13
|
+
|
|
14
|
+
def _check_namespace(self) -> None: ...
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from kubex.core.params import PatchOptions, PostOptions
|
|
2
|
+
from kubex.core.patch import (
|
|
3
|
+
Patch,
|
|
4
|
+
)
|
|
5
|
+
from kubex.models.interfaces import HasScaleSubresource
|
|
6
|
+
from kubex.models.scale import Scale
|
|
7
|
+
from kubex.models.typing import ResourceType
|
|
8
|
+
|
|
9
|
+
from ._protocol import ApiProtocol
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ScaleMixin(ApiProtocol[ResourceType]):
|
|
13
|
+
def _check_implemented(self) -> None:
|
|
14
|
+
if not issubclass(self._resource, HasScaleSubresource):
|
|
15
|
+
raise NotImplementedError(
|
|
16
|
+
"Scale is only supported for resources with replicas"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
async def get_scale(self, name: str) -> Scale:
|
|
20
|
+
self._check_implemented()
|
|
21
|
+
self._check_namespace()
|
|
22
|
+
request = self._request_builder.get_subresource("scale", name)
|
|
23
|
+
response = await self._client.request(request)
|
|
24
|
+
return Scale.model_validate_json(response.content)
|
|
25
|
+
|
|
26
|
+
async def replace_scale(
|
|
27
|
+
self, name: str, scale: Scale, options: PostOptions | None = None
|
|
28
|
+
) -> Scale:
|
|
29
|
+
self._check_implemented()
|
|
30
|
+
self._check_namespace()
|
|
31
|
+
request = self._request_builder.replace_subresource(
|
|
32
|
+
"scale",
|
|
33
|
+
name,
|
|
34
|
+
data=scale.model_dump_json(
|
|
35
|
+
by_alias=True, exclude_unset=True, exclude_none=True
|
|
36
|
+
),
|
|
37
|
+
options=options or PostOptions.default(),
|
|
38
|
+
)
|
|
39
|
+
response = await self._client.request(request)
|
|
40
|
+
return Scale.model_validate_json(response.content)
|
|
41
|
+
|
|
42
|
+
async def patch_scale(
|
|
43
|
+
self,
|
|
44
|
+
name: str,
|
|
45
|
+
patch: Patch,
|
|
46
|
+
options: PatchOptions | None = None,
|
|
47
|
+
) -> Scale:
|
|
48
|
+
self._check_implemented()
|
|
49
|
+
self._check_namespace()
|
|
50
|
+
request = self._request_builder.patch_subresource(
|
|
51
|
+
"scale",
|
|
52
|
+
name,
|
|
53
|
+
options=options or PatchOptions.default(),
|
|
54
|
+
patch=patch,
|
|
55
|
+
)
|
|
56
|
+
response = await self._client.request(request)
|
|
57
|
+
return Scale.model_validate_json(response.content)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# class _SubresourceMixin(ApiProtocol[ResourceType]):
|
|
61
|
+
# def _check_subresource(self, surecesource: Subresource) -> None:
|
|
62
|
+
# parent_required = surecesource.value
|
|
63
|
+
# if not issubclass(self._resource, parent_required):
|
|
64
|
+
# raise NotImplementedError(
|
|
65
|
+
# f"{self._resource.__RESOURCE_CONFIG__.kind} from {self._resource.__RESOURCE_CONFIG__.api_version} has no {surecesource.name.lower()} subresource"
|
|
66
|
+
# )
|
|
67
|
+
|
|
68
|
+
# async def get_subresource(
|
|
69
|
+
# self, name: str, subresource: Subresource
|
|
70
|
+
# ) -> ResourceType:
|
|
71
|
+
# self._check_subresource(subresource)
|
|
72
|
+
# self._check_namespace()
|
|
73
|
+
# request = self._request_builder.get_subresource(name, subresource)
|
|
74
|
+
# async with self._client.get_client() as client:
|
|
75
|
+
# response = await client.get(request.url, params=request.query_params)
|
|
76
|
+
# response.raise_for_status()
|
|
77
|
+
# return self._resource.model_validate_json(response.content)
|
|
78
|
+
|
|
79
|
+
# async def patch_subresource(
|
|
80
|
+
# self, name: str, subresource: str, patch: dict[str, str]
|
|
81
|
+
# ) -> ResourceType:
|
|
82
|
+
# self._check_namespace()
|
|
83
|
+
# request = self._request_builder.patch_subresource(name, subresource, patch)
|
|
84
|
+
# async with self._client.get_client() as client:
|
|
85
|
+
# response = await client.patch(
|
|
86
|
+
# request.url,
|
|
87
|
+
# data=patch,
|
|
88
|
+
# headers={"Content-Type": "application/merge-patch+json"},
|
|
89
|
+
# )
|
|
90
|
+
# response.raise_for_status()
|
|
91
|
+
# return self._resource.model_validate_json(response.content)
|
|
92
|
+
|
|
93
|
+
# async def replace_subresource(
|
|
94
|
+
# self, name: str, subresource: str, body: ResourceType
|
|
95
|
+
# ) -> ResourceType:
|
|
96
|
+
# self._check_namespace()
|
|
97
|
+
# request = self._request_builder.replace_subresource(name, subresource, body)
|
|
98
|
+
# async with self._client.get_client() as client:
|
|
99
|
+
# response = await client.put(
|
|
100
|
+
# request.url,
|
|
101
|
+
# data=body.json(),
|
|
102
|
+
# headers={"Content-Type": "application/json"},
|
|
103
|
+
# )
|
|
104
|
+
# response.raise_for_status()
|
|
105
|
+
# return self._resource.model_validate_json(response.content)
|