helm-sdkpy 0.0.2__py3-none-any.whl
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.
- helm_sdkpy/__init__.py +86 -0
- helm_sdkpy/_ffi.py +232 -0
- helm_sdkpy/actions.py +555 -0
- helm_sdkpy/chart.py +298 -0
- helm_sdkpy/exceptions.py +83 -0
- helm_sdkpy/repo.py +248 -0
- helm_sdkpy-0.0.2.dist-info/METADATA +273 -0
- helm_sdkpy-0.0.2.dist-info/RECORD +10 -0
- helm_sdkpy-0.0.2.dist-info/WHEEL +4 -0
- helm_sdkpy-0.0.2.dist-info/licenses/LICENSE +69 -0
helm_sdkpy/__init__.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Copyright 2025 Vantage Compute
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Python bindings for Helm - The Kubernetes Package Manager."""
|
|
16
|
+
|
|
17
|
+
from ._ffi import get_version
|
|
18
|
+
from .actions import (
|
|
19
|
+
Configuration,
|
|
20
|
+
GetValues,
|
|
21
|
+
History,
|
|
22
|
+
Install,
|
|
23
|
+
List,
|
|
24
|
+
Rollback,
|
|
25
|
+
Status,
|
|
26
|
+
Uninstall,
|
|
27
|
+
Upgrade,
|
|
28
|
+
)
|
|
29
|
+
from .chart import Lint, Package, Pull, Show, Test
|
|
30
|
+
from .exceptions import (
|
|
31
|
+
ChartError,
|
|
32
|
+
ConfigurationError,
|
|
33
|
+
HelmError,
|
|
34
|
+
HelmLibraryNotFound,
|
|
35
|
+
InstallError,
|
|
36
|
+
RegistryError,
|
|
37
|
+
ReleaseError,
|
|
38
|
+
RollbackError,
|
|
39
|
+
UninstallError,
|
|
40
|
+
UpgradeError,
|
|
41
|
+
ValidationError,
|
|
42
|
+
)
|
|
43
|
+
from .repo import RepoAdd, RepoList, RepoRemove, RepoUpdate
|
|
44
|
+
|
|
45
|
+
__version__ = "0.0.1"
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
# Core classes
|
|
49
|
+
"Configuration",
|
|
50
|
+
# Action classes
|
|
51
|
+
"Install",
|
|
52
|
+
"Upgrade",
|
|
53
|
+
"Uninstall",
|
|
54
|
+
"List",
|
|
55
|
+
"Status",
|
|
56
|
+
"Rollback",
|
|
57
|
+
"GetValues",
|
|
58
|
+
"History",
|
|
59
|
+
# Chart classes
|
|
60
|
+
"Pull",
|
|
61
|
+
"Show",
|
|
62
|
+
"Test",
|
|
63
|
+
"Lint",
|
|
64
|
+
"Package",
|
|
65
|
+
# Repository classes
|
|
66
|
+
"RepoAdd",
|
|
67
|
+
"RepoRemove",
|
|
68
|
+
"RepoList",
|
|
69
|
+
"RepoUpdate",
|
|
70
|
+
# Exceptions - Base
|
|
71
|
+
"HelmError",
|
|
72
|
+
"HelmLibraryNotFound",
|
|
73
|
+
# Exceptions - Specific
|
|
74
|
+
"ConfigurationError",
|
|
75
|
+
"InstallError",
|
|
76
|
+
"UpgradeError",
|
|
77
|
+
"UninstallError",
|
|
78
|
+
"RollbackError",
|
|
79
|
+
"ChartError",
|
|
80
|
+
"ReleaseError",
|
|
81
|
+
"RegistryError",
|
|
82
|
+
"ValidationError",
|
|
83
|
+
# Utilities
|
|
84
|
+
"get_version",
|
|
85
|
+
"__version__",
|
|
86
|
+
]
|
helm_sdkpy/_ffi.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Copyright 2025 Vantage Compute
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
import platform
|
|
19
|
+
import threading
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
from cffi import FFI # type: ignore[import]
|
|
24
|
+
|
|
25
|
+
from .exceptions import HelmError, HelmLibraryNotFound
|
|
26
|
+
|
|
27
|
+
ffi: Any = FFI()
|
|
28
|
+
ffi.cdef(
|
|
29
|
+
"""
|
|
30
|
+
typedef unsigned long long helm_sdkpy_handle;
|
|
31
|
+
|
|
32
|
+
// Configuration management
|
|
33
|
+
int helm_sdkpy_config_create(const char *namespace, const char *kubeconfig, const char *kubecontext, helm_sdkpy_handle *handle_out);
|
|
34
|
+
void helm_sdkpy_config_destroy(helm_sdkpy_handle handle);
|
|
35
|
+
|
|
36
|
+
// Install action
|
|
37
|
+
int helm_sdkpy_install(helm_sdkpy_handle handle, const char *release_name, const char *chart_path, const char *values_json, const char *version, int create_namespace, int wait, int timeout_seconds, char **result_json);
|
|
38
|
+
|
|
39
|
+
// Upgrade action
|
|
40
|
+
int helm_sdkpy_upgrade(helm_sdkpy_handle handle, const char *release_name, const char *chart_path, const char *values_json, const char *version, char **result_json);
|
|
41
|
+
|
|
42
|
+
// Uninstall action
|
|
43
|
+
int helm_sdkpy_uninstall(helm_sdkpy_handle handle, const char *release_name, int wait, int timeout_seconds, char **result_json);
|
|
44
|
+
|
|
45
|
+
// List action
|
|
46
|
+
int helm_sdkpy_list(helm_sdkpy_handle handle, int all, char **result_json);
|
|
47
|
+
|
|
48
|
+
// Status action
|
|
49
|
+
int helm_sdkpy_status(helm_sdkpy_handle handle, const char *release_name, char **result_json);
|
|
50
|
+
|
|
51
|
+
// Rollback action
|
|
52
|
+
int helm_sdkpy_rollback(helm_sdkpy_handle handle, const char *release_name, int revision, char **result_json);
|
|
53
|
+
|
|
54
|
+
// Get values action
|
|
55
|
+
int helm_sdkpy_get_values(helm_sdkpy_handle handle, const char *release_name, int all_values, char **result_json);
|
|
56
|
+
|
|
57
|
+
// History action
|
|
58
|
+
int helm_sdkpy_history(helm_sdkpy_handle handle, const char *release_name, char **result_json);
|
|
59
|
+
|
|
60
|
+
// Pull action
|
|
61
|
+
int helm_sdkpy_pull(helm_sdkpy_handle handle, const char *chart_ref, const char *dest_dir);
|
|
62
|
+
|
|
63
|
+
// Show chart action
|
|
64
|
+
int helm_sdkpy_show_chart(helm_sdkpy_handle handle, const char *chart_path, char **result_json);
|
|
65
|
+
|
|
66
|
+
// Show values action
|
|
67
|
+
int helm_sdkpy_show_values(helm_sdkpy_handle handle, const char *chart_path, char **result_json);
|
|
68
|
+
|
|
69
|
+
// Test action
|
|
70
|
+
int helm_sdkpy_test(helm_sdkpy_handle handle, const char *release_name, char **result_json);
|
|
71
|
+
|
|
72
|
+
// Lint action
|
|
73
|
+
int helm_sdkpy_lint(helm_sdkpy_handle handle, const char *chart_path, char **result_json);
|
|
74
|
+
|
|
75
|
+
// Package action
|
|
76
|
+
int helm_sdkpy_package(helm_sdkpy_handle handle, const char *chart_path, const char *dest_dir, char **result_path);
|
|
77
|
+
|
|
78
|
+
// Repository management actions
|
|
79
|
+
int helm_sdkpy_repo_add(helm_sdkpy_handle handle, const char *name, const char *url, const char *username, const char *password, const char *options_json);
|
|
80
|
+
int helm_sdkpy_repo_remove(helm_sdkpy_handle handle, const char *name);
|
|
81
|
+
int helm_sdkpy_repo_list(helm_sdkpy_handle handle, char **result_json);
|
|
82
|
+
int helm_sdkpy_repo_update(helm_sdkpy_handle handle, const char *name);
|
|
83
|
+
|
|
84
|
+
// Utility functions
|
|
85
|
+
const char *helm_sdkpy_last_error(void);
|
|
86
|
+
void helm_sdkpy_free(void *ptr);
|
|
87
|
+
int helm_sdkpy_version_number(void);
|
|
88
|
+
const char *helm_sdkpy_version_string(void);
|
|
89
|
+
"""
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
__all__ = [
|
|
94
|
+
"HelmError",
|
|
95
|
+
"HelmLibraryNotFound",
|
|
96
|
+
"configure",
|
|
97
|
+
"ffi",
|
|
98
|
+
"get_library",
|
|
99
|
+
"get_version",
|
|
100
|
+
"string_from_c",
|
|
101
|
+
"_reset_for_tests",
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
_library_lock = threading.Lock()
|
|
106
|
+
_library = None
|
|
107
|
+
_library_path: str | None = None
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def configure(path: str | None) -> None:
|
|
111
|
+
"""Force the bindings to load libhelm_sdkpy from ``path``.
|
|
112
|
+
|
|
113
|
+
Passing ``None`` clears the override and re-enables auto-discovery.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
global _library_path, _library
|
|
117
|
+
with _library_lock:
|
|
118
|
+
_library_path = path
|
|
119
|
+
_library = None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _find_library() -> str | None:
|
|
123
|
+
"""Find the helm_sdkpy shared library."""
|
|
124
|
+
|
|
125
|
+
# Check for configured path first
|
|
126
|
+
if _library_path is not None:
|
|
127
|
+
return _library_path
|
|
128
|
+
|
|
129
|
+
# Determine platform-specific library name and search paths
|
|
130
|
+
system = platform.system()
|
|
131
|
+
machine = platform.machine()
|
|
132
|
+
|
|
133
|
+
# Normalize architecture names to match Go's convention
|
|
134
|
+
if machine == "x86_64":
|
|
135
|
+
machine = "amd64"
|
|
136
|
+
elif machine == "aarch64":
|
|
137
|
+
machine = "arm64"
|
|
138
|
+
|
|
139
|
+
if system == "Linux":
|
|
140
|
+
lib_name = "libhelm_sdkpy.so"
|
|
141
|
+
platform_dir = f"linux-{machine}"
|
|
142
|
+
elif system == "Darwin":
|
|
143
|
+
lib_name = "libhelm_sdkpy.dylib"
|
|
144
|
+
platform_dir = f"darwin-{machine}"
|
|
145
|
+
elif system == "Windows":
|
|
146
|
+
lib_name = "helm_sdkpy.dll"
|
|
147
|
+
platform_dir = f"windows-{machine}"
|
|
148
|
+
else:
|
|
149
|
+
return None
|
|
150
|
+
|
|
151
|
+
# Search in package directory first
|
|
152
|
+
package_dir = Path(__file__).parent
|
|
153
|
+
lib_dir = package_dir / "_lib" / platform_dir
|
|
154
|
+
lib_path = lib_dir / lib_name
|
|
155
|
+
|
|
156
|
+
if lib_path.exists():
|
|
157
|
+
return str(lib_path)
|
|
158
|
+
|
|
159
|
+
# Try just the platform directory
|
|
160
|
+
lib_path = lib_dir / lib_name
|
|
161
|
+
if lib_path.exists():
|
|
162
|
+
return str(lib_path)
|
|
163
|
+
|
|
164
|
+
# Try environment variable
|
|
165
|
+
env_path = os.environ.get("HELMPY_LIBRARY_PATH")
|
|
166
|
+
if env_path and Path(env_path).exists():
|
|
167
|
+
return env_path
|
|
168
|
+
|
|
169
|
+
return None
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def get_library():
|
|
173
|
+
"""Get the loaded Helm library, loading it if necessary."""
|
|
174
|
+
global _library
|
|
175
|
+
|
|
176
|
+
with _library_lock:
|
|
177
|
+
if _library is not None:
|
|
178
|
+
return _library
|
|
179
|
+
|
|
180
|
+
lib_path = _find_library()
|
|
181
|
+
if lib_path is None:
|
|
182
|
+
raise HelmLibraryNotFound(
|
|
183
|
+
"Could not find helm_sdkpy shared library. Please ensure helm_sdkpy is properly installed."
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
_library = ffi.dlopen(lib_path)
|
|
188
|
+
except OSError as e:
|
|
189
|
+
raise HelmLibraryNotFound(f"Failed to load helm_sdkpy library from {lib_path}: {e}") from e
|
|
190
|
+
|
|
191
|
+
return _library
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def get_version() -> str:
|
|
195
|
+
"""Get the version string from the native library."""
|
|
196
|
+
lib = get_library()
|
|
197
|
+
version_ptr = lib.helm_sdkpy_version_string()
|
|
198
|
+
if version_ptr == ffi.NULL:
|
|
199
|
+
return "unknown"
|
|
200
|
+
return ffi.string(version_ptr).decode("utf-8")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def string_from_c(c_str) -> str:
|
|
204
|
+
"""Convert a C string to Python string and free it."""
|
|
205
|
+
if c_str == ffi.NULL:
|
|
206
|
+
return ""
|
|
207
|
+
try:
|
|
208
|
+
s = ffi.string(c_str).decode("utf-8")
|
|
209
|
+
return s
|
|
210
|
+
finally:
|
|
211
|
+
lib = get_library()
|
|
212
|
+
lib.helm_sdkpy_free(c_str)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def check_error(result: int) -> None:
|
|
216
|
+
"""Check if a C function returned an error and raise an exception if so."""
|
|
217
|
+
if result != 0:
|
|
218
|
+
lib = get_library()
|
|
219
|
+
err_ptr = lib.helm_sdkpy_last_error()
|
|
220
|
+
if err_ptr != ffi.NULL:
|
|
221
|
+
err_msg = ffi.string(err_ptr).decode("utf-8")
|
|
222
|
+
raise HelmError(err_msg)
|
|
223
|
+
else:
|
|
224
|
+
raise HelmError("Unknown error occurred")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _reset_for_tests() -> None:
|
|
228
|
+
"""Reset library state for testing. Internal use only."""
|
|
229
|
+
global _library, _library_path
|
|
230
|
+
with _library_lock:
|
|
231
|
+
_library = None
|
|
232
|
+
_library_path = None
|