kubernator 1.0.23.dev20251011181340__py3-none-any.whl → 1.0.24.dev20251028221359__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.
Potentially problematic release.
This version of kubernator might be problematic. Click here for more details.
- kubernator/__init__.py +1 -1
- kubernator/api.py +64 -9
- kubernator/plugins/istio.py +23 -9
- kubernator/plugins/k8s.py +105 -53
- kubernator/plugins/k8s_api.py +14 -5
- kubernator/plugins/kubectl.py +1 -2
- {kubernator-1.0.23.dev20251011181340.dist-info → kubernator-1.0.24.dev20251028221359.dist-info}/METADATA +1 -1
- {kubernator-1.0.23.dev20251011181340.dist-info → kubernator-1.0.24.dev20251028221359.dist-info}/RECORD +13 -13
- {kubernator-1.0.23.dev20251011181340.dist-info → kubernator-1.0.24.dev20251028221359.dist-info}/WHEEL +0 -0
- {kubernator-1.0.23.dev20251011181340.dist-info → kubernator-1.0.24.dev20251028221359.dist-info}/entry_points.txt +0 -0
- {kubernator-1.0.23.dev20251011181340.dist-info → kubernator-1.0.24.dev20251028221359.dist-info}/namespace_packages.txt +0 -0
- {kubernator-1.0.23.dev20251011181340.dist-info → kubernator-1.0.24.dev20251028221359.dist-info}/top_level.txt +0 -0
- {kubernator-1.0.23.dev20251011181340.dist-info → kubernator-1.0.24.dev20251028221359.dist-info}/zip-safe +0 -0
kubernator/__init__.py
CHANGED
kubernator/api.py
CHANGED
|
@@ -20,10 +20,10 @@ import fnmatch
|
|
|
20
20
|
import json
|
|
21
21
|
import logging
|
|
22
22
|
import os
|
|
23
|
-
import io
|
|
24
23
|
import platform
|
|
25
24
|
import re
|
|
26
25
|
import sys
|
|
26
|
+
import textwrap
|
|
27
27
|
import traceback
|
|
28
28
|
import urllib.parse
|
|
29
29
|
from collections.abc import Callable
|
|
@@ -48,6 +48,7 @@ from jinja2 import (Environment,
|
|
|
48
48
|
pass_context)
|
|
49
49
|
from jsonschema import validators
|
|
50
50
|
from platformdirs import user_cache_dir
|
|
51
|
+
from yaml import MarkedYAMLError
|
|
51
52
|
|
|
52
53
|
from kubernator._json_path import jp # noqa: F401
|
|
53
54
|
from kubernator._k8s_client_patches import (URLLIB_HEADERS_PATCH,
|
|
@@ -59,6 +60,43 @@ _CACHE_HEADER_TRANSLATION = {"etag": "if-none-match",
|
|
|
59
60
|
_CACHE_HEADERS = ("etag", "last-modified")
|
|
60
61
|
|
|
61
62
|
|
|
63
|
+
def to_json(obj: Union[dict, list]):
|
|
64
|
+
return json.dumps(obj)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def to_yaml_str(s: str):
|
|
68
|
+
return repr(s)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def to_json_yaml_str(obj: Union[dict, list]):
|
|
72
|
+
"""
|
|
73
|
+
Takes `obj`, dumps as json representation, converts json representation to YAML string literal.
|
|
74
|
+
"""
|
|
75
|
+
return to_yaml_str(to_json(obj))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def to_yaml_str_block(s: str, indent: int = 4, pretty_indent: int = 2):
|
|
79
|
+
"""
|
|
80
|
+
Takes a multiline string, dedents it then indents it `indent` spaces for in-yaml alignment and
|
|
81
|
+
`pretty-indent` spaces for in-block alignment.
|
|
82
|
+
"""
|
|
83
|
+
return (f"|+{pretty_indent}\n" +
|
|
84
|
+
textwrap.indent(textwrap.dedent(s), " " * (indent + pretty_indent)))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def to_json_yaml_str_block(obj: Union[str, dict, list], indent: int = 4, pretty_indent=2):
|
|
88
|
+
"""
|
|
89
|
+
Takes an `obj`, serializes it as pretty JSON with `pretty_indent` in-json indentation and then
|
|
90
|
+
passes it to `to_yaml_str_block`.
|
|
91
|
+
"""
|
|
92
|
+
return to_yaml_str_block(json.dumps(obj, indent=pretty_indent), indent=indent, pretty_indent=pretty_indent)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def to_yaml(obj: Union[dict, list], level_indent: int, indent: int):
|
|
96
|
+
s = yaml.safe_dump(obj, indent=indent)
|
|
97
|
+
return "\n" + textwrap.indent(s, " " * level_indent)
|
|
98
|
+
|
|
99
|
+
|
|
62
100
|
class TemplateEngine:
|
|
63
101
|
VARIABLE_START_STRING = "{${"
|
|
64
102
|
VARIABLE_END_STRING = "}$}"
|
|
@@ -97,7 +135,15 @@ class TemplateEngine:
|
|
|
97
135
|
variable_end_string=self.VARIABLE_END_STRING,
|
|
98
136
|
autoescape=False,
|
|
99
137
|
finalize=variable_finalizer,
|
|
100
|
-
undefined=logging_undefined
|
|
138
|
+
undefined=logging_undefined,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
self.env.filters["to_json"] = to_json
|
|
142
|
+
self.env.filters["to_yaml_str"] = to_yaml_str
|
|
143
|
+
self.env.filters["to_yaml"] = to_yaml
|
|
144
|
+
self.env.filters["to_yaml_str_block"] = to_yaml_str_block
|
|
145
|
+
self.env.filters["to_json_yaml_str_block"] = to_json_yaml_str_block
|
|
146
|
+
self.env.filters["to_json_yaml_str"] = to_json_yaml_str
|
|
101
147
|
|
|
102
148
|
def from_string(self, template):
|
|
103
149
|
return self.env.from_string(template)
|
|
@@ -136,9 +182,18 @@ def scan_dir(logger, path: Path, path_filter: Callable[[os.DirEntry], bool], exc
|
|
|
136
182
|
yield path / f
|
|
137
183
|
|
|
138
184
|
|
|
185
|
+
def parse_yaml_docs(document: str, source=None):
|
|
186
|
+
try:
|
|
187
|
+
return list(d for d in yaml.safe_load_all(document) if d)
|
|
188
|
+
except MarkedYAMLError:
|
|
189
|
+
raise
|
|
190
|
+
|
|
191
|
+
|
|
139
192
|
class FileType(Enum):
|
|
140
|
-
|
|
141
|
-
|
|
193
|
+
TEXT = (lambda x: x,)
|
|
194
|
+
BINARY = (lambda x: x,)
|
|
195
|
+
JSON = (json.loads,)
|
|
196
|
+
YAML = (parse_yaml_docs,)
|
|
142
197
|
|
|
143
198
|
def __init__(self, func):
|
|
144
199
|
self.func = func
|
|
@@ -147,13 +202,13 @@ class FileType(Enum):
|
|
|
147
202
|
def _load_file(logger, path: Path, file_type: FileType, source=None,
|
|
148
203
|
template_engine: Optional[TemplateEngine] = None,
|
|
149
204
|
template_context: Optional[dict] = None) -> Iterable[dict]:
|
|
150
|
-
with open(path, "rb" if
|
|
205
|
+
with open(path, "rb" if file_type == FileType.BINARY else "rt") as f:
|
|
151
206
|
try:
|
|
152
|
-
if template_engine:
|
|
207
|
+
if template_engine and not file_type == FileType.BINARY:
|
|
153
208
|
raw_data = template_engine.from_string(f.read()).render(template_context)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
data = file_type.func(
|
|
209
|
+
else:
|
|
210
|
+
raw_data = f.read()
|
|
211
|
+
data = file_type.func(raw_data)
|
|
157
212
|
if isinstance(data, GeneratorType):
|
|
158
213
|
data = list(data)
|
|
159
214
|
return data
|
kubernator/plugins/istio.py
CHANGED
|
@@ -25,6 +25,7 @@ from pathlib import Path
|
|
|
25
25
|
from shutil import which
|
|
26
26
|
|
|
27
27
|
import yaml
|
|
28
|
+
|
|
28
29
|
from kubernator.api import (KubernatorPlugin, scan_dir,
|
|
29
30
|
TemplateEngine,
|
|
30
31
|
load_remote_file,
|
|
@@ -34,6 +35,7 @@ from kubernator.api import (KubernatorPlugin, scan_dir,
|
|
|
34
35
|
get_golang_os,
|
|
35
36
|
get_golang_machine,
|
|
36
37
|
prepend_os_path, jp, load_file)
|
|
38
|
+
from kubernator.plugins.k8s import api_exc_normalize_body, api_exc_format_body
|
|
37
39
|
from kubernator.plugins.k8s_api import K8SResourcePluginMixin
|
|
38
40
|
|
|
39
41
|
logger = logging.getLogger("kubernator.istio")
|
|
@@ -277,11 +279,17 @@ class IstioPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
277
279
|
try:
|
|
278
280
|
res.delete(dry_run=dry_run)
|
|
279
281
|
except ApiException as e:
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
skip =
|
|
283
|
-
|
|
282
|
+
api_exc_normalize_body(e)
|
|
283
|
+
try:
|
|
284
|
+
skip = False
|
|
285
|
+
if e.status == 404 and missing_ok:
|
|
286
|
+
skip = True
|
|
287
|
+
if not skip:
|
|
288
|
+
raise
|
|
289
|
+
except ApiException as e:
|
|
290
|
+
api_exc_format_body(e)
|
|
284
291
|
raise
|
|
292
|
+
|
|
285
293
|
return res
|
|
286
294
|
|
|
287
295
|
def _create_resource_internal(self, manifest, dry_run=True, exists_ok=False):
|
|
@@ -297,12 +305,18 @@ class IstioPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
297
305
|
res.create(dry_run=dry_run)
|
|
298
306
|
except ApiException as e:
|
|
299
307
|
skip = False
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if status
|
|
303
|
-
|
|
304
|
-
|
|
308
|
+
api_exc_normalize_body(e)
|
|
309
|
+
try:
|
|
310
|
+
if e.status == 409:
|
|
311
|
+
status = e.body
|
|
312
|
+
if status["reason"] == "AlreadyExists" and exists_ok:
|
|
313
|
+
skip = True
|
|
314
|
+
if not skip:
|
|
315
|
+
raise
|
|
316
|
+
except ApiException as e:
|
|
317
|
+
api_exc_format_body(e)
|
|
305
318
|
raise
|
|
319
|
+
|
|
306
320
|
return res
|
|
307
321
|
|
|
308
322
|
def _install(self, operators_file, dry_run):
|
kubernator/plugins/k8s.py
CHANGED
|
@@ -30,6 +30,7 @@ from typing import Iterable, Callable, Sequence
|
|
|
30
30
|
|
|
31
31
|
import jsonpatch
|
|
32
32
|
import yaml
|
|
33
|
+
from kubernetes.client import ApiException
|
|
33
34
|
|
|
34
35
|
from kubernator.api import (KubernatorPlugin,
|
|
35
36
|
Globs,
|
|
@@ -83,6 +84,21 @@ def normalize_pkg_version(v: str):
|
|
|
83
84
|
return tuple(map(int, v_split))
|
|
84
85
|
|
|
85
86
|
|
|
87
|
+
def api_exc_normalize_body(e: "ApiException"):
|
|
88
|
+
if e.headers and "content-type" in e.headers:
|
|
89
|
+
content_type = e.headers["content-type"]
|
|
90
|
+
if content_type == "application/json" or content_type.endswith("+json"):
|
|
91
|
+
e.body = json.loads(e.body)
|
|
92
|
+
elif (content_type in ("application/yaml", "application/x-yaml", "text/yaml",
|
|
93
|
+
"text/x-yaml") or content_type.endswith("+yaml")):
|
|
94
|
+
e.body = yaml.safe_load(e.body)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def api_exc_format_body(e: ApiException):
|
|
98
|
+
if not isinstance(e.body, (str, bytes)):
|
|
99
|
+
e.body = json.dumps(e.body, indent=4)
|
|
100
|
+
|
|
101
|
+
|
|
86
102
|
class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
87
103
|
logger = logger
|
|
88
104
|
|
|
@@ -96,6 +112,7 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
96
112
|
|
|
97
113
|
self._transformers = []
|
|
98
114
|
self._validators = []
|
|
115
|
+
self._manifest_patchers = []
|
|
99
116
|
self._summary = 0, 0, 0
|
|
100
117
|
self._template_engine = TemplateEngine(logger)
|
|
101
118
|
|
|
@@ -122,6 +139,7 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
122
139
|
("apps", "Deployment"): K8SPropagationPolicy.ORPHAN,
|
|
123
140
|
("storage.k8s.io", "StorageClass"): K8SPropagationPolicy.ORPHAN,
|
|
124
141
|
(None, "Pod"): K8SPropagationPolicy.BACKGROUND,
|
|
142
|
+
("batch", "Job"): K8SPropagationPolicy.ORPHAN,
|
|
125
143
|
},
|
|
126
144
|
default_includes=Globs(["*.yaml", "*.yml"], True),
|
|
127
145
|
default_excludes=Globs([".*"], True),
|
|
@@ -133,6 +151,7 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
133
151
|
add_transformer=self.api_add_transformer,
|
|
134
152
|
remove_transformer=self.api_remove_transformer,
|
|
135
153
|
add_validator=self.api_remove_validator,
|
|
154
|
+
add_manifest_patcher=self.api_add_manifest_patcher,
|
|
136
155
|
get_api_versions=self.get_api_versions,
|
|
137
156
|
create_resource=self.create_resource,
|
|
138
157
|
disable_client_patches=disable_client_patches,
|
|
@@ -356,6 +375,10 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
356
375
|
if validator not in self._validators:
|
|
357
376
|
self._validators.append(validator)
|
|
358
377
|
|
|
378
|
+
def api_add_manifest_patcher(self, patcher):
|
|
379
|
+
if patcher not in self._manifest_patchers:
|
|
380
|
+
self._manifest_patchers.append(patcher)
|
|
381
|
+
|
|
359
382
|
def api_remove_transformer(self, transformer):
|
|
360
383
|
if transformer in self._transformers:
|
|
361
384
|
self._transformers.remove(transformer)
|
|
@@ -374,6 +397,17 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
374
397
|
frame = frame.f_back
|
|
375
398
|
return ValueError((msg % args) if args else msg).with_traceback(tb)
|
|
376
399
|
|
|
400
|
+
def _patch_manifest(self,
|
|
401
|
+
manifest: dict,
|
|
402
|
+
resource_description: str):
|
|
403
|
+
for patcher in reversed(self._manifest_patchers):
|
|
404
|
+
logger.debug("Applying patcher %s to %s",
|
|
405
|
+
getattr(patcher, "__name__", patcher),
|
|
406
|
+
resource_description)
|
|
407
|
+
manifest = patcher(manifest, resource_description) or manifest
|
|
408
|
+
|
|
409
|
+
return manifest
|
|
410
|
+
|
|
377
411
|
def _transform_resource(self, resources: Sequence[K8SResource], resource: K8SResource) -> K8SResource:
|
|
378
412
|
for transformer in reversed(self._transformers):
|
|
379
413
|
logger.debug("Applying transformer %s to %s from %s",
|
|
@@ -412,8 +446,8 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
412
446
|
|
|
413
447
|
def handle_400_strict_validation_error(e: ApiException):
|
|
414
448
|
if e.status == 400:
|
|
415
|
-
|
|
416
|
-
|
|
449
|
+
# Assumes the body has been parsed
|
|
450
|
+
status = e.body
|
|
417
451
|
if status["status"] == "Failure":
|
|
418
452
|
if FIELD_VALIDATION_STRICT_MARKER in status["message"]:
|
|
419
453
|
message = status["message"]
|
|
@@ -435,19 +469,24 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
435
469
|
try:
|
|
436
470
|
create_func()
|
|
437
471
|
return
|
|
438
|
-
except ApiException as
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if status
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
472
|
+
except ApiException as __e:
|
|
473
|
+
api_exc_normalize_body(__e)
|
|
474
|
+
try:
|
|
475
|
+
if exists_ok or wait_for_delete:
|
|
476
|
+
if __e.status == 409:
|
|
477
|
+
status = __e.body
|
|
478
|
+
if status["reason"] == "AlreadyExists":
|
|
479
|
+
if wait_for_delete:
|
|
480
|
+
sleep(self.context.k8s.conflict_retry_delay)
|
|
481
|
+
logger.info("Retry creating resource %s%s%s", resource, status_msg,
|
|
482
|
+
" (ignoring existing)" if exists_ok else "")
|
|
483
|
+
continue
|
|
484
|
+
else:
|
|
485
|
+
return
|
|
486
|
+
raise
|
|
487
|
+
except ApiException as ___e:
|
|
488
|
+
api_exc_format_body(___e)
|
|
489
|
+
raise
|
|
451
490
|
|
|
452
491
|
merge_instrs, normalized_manifest = extract_merge_instructions(resource.manifest, resource)
|
|
453
492
|
if merge_instrs:
|
|
@@ -461,15 +500,20 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
461
500
|
remote_resource = resource.get()
|
|
462
501
|
logger.trace("Current resource %s: %s", resource, remote_resource)
|
|
463
502
|
except ApiException as e:
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
503
|
+
api_exc_normalize_body(e)
|
|
504
|
+
try:
|
|
505
|
+
if e.status == 404:
|
|
506
|
+
try:
|
|
507
|
+
create()
|
|
508
|
+
return 1, 0, 0
|
|
509
|
+
except ApiException as e:
|
|
510
|
+
api_exc_normalize_body(e)
|
|
511
|
+
if not handle_400_strict_validation_error(e):
|
|
512
|
+
raise
|
|
513
|
+
else:
|
|
514
|
+
raise
|
|
515
|
+
except ApiException as _e:
|
|
516
|
+
api_exc_format_body(_e)
|
|
473
517
|
raise
|
|
474
518
|
else:
|
|
475
519
|
logger.trace("Attempting to retrieve a normalized patch for resource %s: %s", resource, normalized_manifest)
|
|
@@ -479,36 +523,44 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
|
|
|
479
523
|
dry_run=True,
|
|
480
524
|
force=True)
|
|
481
525
|
except ApiException as e:
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
526
|
+
try:
|
|
527
|
+
api_exc_normalize_body(e)
|
|
528
|
+
|
|
529
|
+
if e.status == 422:
|
|
530
|
+
status = e.body
|
|
531
|
+
# Assumes the body has been unmarshalled
|
|
532
|
+
details = status["details"]
|
|
533
|
+
immutable_key = details.get("group"), details["kind"]
|
|
534
|
+
|
|
535
|
+
try:
|
|
536
|
+
propagation_policy = self.context.k8s.immutable_changes[immutable_key]
|
|
537
|
+
except KeyError:
|
|
538
|
+
raise e from None
|
|
539
|
+
else:
|
|
540
|
+
for cause in details["causes"]:
|
|
541
|
+
if (
|
|
542
|
+
cause["reason"] == "FieldValueInvalid" and
|
|
543
|
+
"field is immutable" in cause["message"]
|
|
544
|
+
or
|
|
545
|
+
cause["reason"] == "FieldValueForbidden" and
|
|
546
|
+
("Forbidden: updates to" in cause["message"]
|
|
547
|
+
or
|
|
548
|
+
"Forbidden: pod updates" in cause["message"])
|
|
549
|
+
):
|
|
550
|
+
logger.info("Deleting resource %s (cascade %s)%s", resource,
|
|
551
|
+
propagation_policy.policy,
|
|
552
|
+
status_msg)
|
|
553
|
+
delete_func(propagation_policy=propagation_policy)
|
|
554
|
+
create(exists_ok=dry_run, wait_for_delete=not dry_run)
|
|
555
|
+
return 1, 0, 1
|
|
556
|
+
raise
|
|
491
557
|
else:
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
("Forbidden: updates to" in cause["message"]
|
|
499
|
-
or
|
|
500
|
-
"Forbidden: pod updates" in cause["message"])
|
|
501
|
-
):
|
|
502
|
-
logger.info("Deleting resource %s (cascade %s)%s", resource,
|
|
503
|
-
propagation_policy.policy,
|
|
504
|
-
status_msg)
|
|
505
|
-
delete_func(propagation_policy=propagation_policy)
|
|
506
|
-
create(exists_ok=dry_run, wait_for_delete=not dry_run)
|
|
507
|
-
return 1, 0, 1
|
|
508
|
-
raise
|
|
509
|
-
else:
|
|
510
|
-
if not handle_400_strict_validation_error(e):
|
|
511
|
-
raise
|
|
558
|
+
if not handle_400_strict_validation_error(e):
|
|
559
|
+
raise
|
|
560
|
+
except ApiException as _e:
|
|
561
|
+
api_exc_format_body(_e)
|
|
562
|
+
raise
|
|
563
|
+
|
|
512
564
|
else:
|
|
513
565
|
logger.trace("Merged resource %s: %s", resource, merged_resource)
|
|
514
566
|
if merge_instrs:
|
kubernator/plugins/k8s_api.py
CHANGED
|
@@ -23,7 +23,6 @@ from collections import namedtuple
|
|
|
23
23
|
from collections.abc import Callable, Mapping, MutableMapping, Sequence, Iterable
|
|
24
24
|
from enum import Enum, auto
|
|
25
25
|
from functools import partial
|
|
26
|
-
from io import StringIO
|
|
27
26
|
from pathlib import Path
|
|
28
27
|
from typing import Union, Optional
|
|
29
28
|
|
|
@@ -34,7 +33,7 @@ from jsonschema.exceptions import ValidationError
|
|
|
34
33
|
from jsonschema.validators import extend, Draft7Validator
|
|
35
34
|
from openapi_schema_validator import OAS31Validator
|
|
36
35
|
|
|
37
|
-
from kubernator.api import load_file, FileType, load_remote_file, calling_frame_source
|
|
36
|
+
from kubernator.api import load_file, FileType, load_remote_file, calling_frame_source, parse_yaml_docs
|
|
38
37
|
|
|
39
38
|
K8S_WARNING_HEADER = re.compile(r'(?:,\s*)?(\d{3})\s+(\S+)\s+"(.+?)(?<!\\)"(?:\s+\"(.+?)(?<!\\)\")?\s*')
|
|
40
39
|
UPPER_FOLLOWED_BY_LOWER_RE = re.compile(r"(.)([A-Z][a-z]+)")
|
|
@@ -524,7 +523,7 @@ class K8SResourcePluginMixin:
|
|
|
524
523
|
source = calling_frame_source()
|
|
525
524
|
|
|
526
525
|
if isinstance(manifests, str):
|
|
527
|
-
manifests = list(
|
|
526
|
+
manifests = list(parse_yaml_docs(manifests, source))
|
|
528
527
|
|
|
529
528
|
if isinstance(manifests, (Mapping, dict)):
|
|
530
529
|
return self.add_resource(manifests, source)
|
|
@@ -557,7 +556,7 @@ class K8SResourcePluginMixin:
|
|
|
557
556
|
source = calling_frame_source()
|
|
558
557
|
|
|
559
558
|
if isinstance(manifests, str):
|
|
560
|
-
manifests = list(
|
|
559
|
+
manifests = list(parse_yaml_docs(manifests, source))
|
|
561
560
|
|
|
562
561
|
if isinstance(manifests, (Mapping, dict)):
|
|
563
562
|
return self.add_crd(manifests, source)
|
|
@@ -614,8 +613,13 @@ class K8SResourcePluginMixin:
|
|
|
614
613
|
|
|
615
614
|
def _create_resource(self, manifest: dict, source: Union[str, Path] = None):
|
|
616
615
|
resource_description = K8SResource.get_manifest_description(manifest, source)
|
|
617
|
-
self.logger.debug("Validating K8S manifest for %s", resource_description)
|
|
618
616
|
|
|
617
|
+
new_manifest = self._patch_manifest(manifest, resource_description)
|
|
618
|
+
if new_manifest != manifest:
|
|
619
|
+
manifest = new_manifest
|
|
620
|
+
resource_description = K8SResource.get_manifest_description(manifest, source)
|
|
621
|
+
|
|
622
|
+
self.logger.debug("Validating K8S manifest for %s", resource_description)
|
|
619
623
|
errors = list(self._validate_resource(manifest, source))
|
|
620
624
|
if errors:
|
|
621
625
|
for error in errors:
|
|
@@ -644,6 +648,11 @@ class K8SResourcePluginMixin:
|
|
|
644
648
|
|
|
645
649
|
return resource
|
|
646
650
|
|
|
651
|
+
def _patch_manifest(self,
|
|
652
|
+
manifest: dict,
|
|
653
|
+
resource_description: str):
|
|
654
|
+
return manifest
|
|
655
|
+
|
|
647
656
|
def _transform_resource(self,
|
|
648
657
|
resources: Sequence[K8SResource],
|
|
649
658
|
resource: K8SResource) -> K8SResource:
|
kubernator/plugins/kubectl.py
CHANGED
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
# limitations under the License.
|
|
17
17
|
#
|
|
18
18
|
|
|
19
|
-
import io
|
|
20
19
|
import json
|
|
21
20
|
import logging
|
|
22
21
|
import os
|
|
@@ -121,7 +120,7 @@ class KubectlPlugin(KubernatorPlugin):
|
|
|
121
120
|
args += ["-n", namespace]
|
|
122
121
|
args += ["-o", "yaml"]
|
|
123
122
|
|
|
124
|
-
res = list(yaml.safe_load_all(
|
|
123
|
+
res = list(yaml.safe_load_all(self.context.kubectl.run_capturing(*args)))
|
|
125
124
|
if len(res):
|
|
126
125
|
if len(res) > 1:
|
|
127
126
|
return res
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kubernator
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.24.dev20251028221359
|
|
4
4
|
Summary: Kubernator is the a pluggable framework for K8S provisioning
|
|
5
5
|
Home-page: https://github.com/karellen/kubernator
|
|
6
6
|
Author: Express Systems USA, Inc.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
kubernator/LICENSE,sha256=wKKdOCMTCPQRV5gDkVLAsXX8qSnRJ5owk7yWPO1KZNo,11387
|
|
2
|
-
kubernator/__init__.py,sha256=
|
|
2
|
+
kubernator/__init__.py,sha256=WHARX7iD1ynhZP3A9V92ZVg_I8fgalutzhfkByBwLAw,933
|
|
3
3
|
kubernator/__main__.py,sha256=f0S60wgpLu--1UlOhzfWail-xt8zyIuODodX98_yPN0,707
|
|
4
4
|
kubernator/_json_path.py,sha256=pjQKXxgbpQWETYBIrIuJZHgugF92IbEAM19AC7JUmAQ,3162
|
|
5
5
|
kubernator/_k8s_client_patches.py,sha256=PEeWPInnW38NDyK7G24_Dmw-x7xHpN3vJWZeckdqgK0,76892
|
|
6
|
-
kubernator/api.py,sha256=
|
|
6
|
+
kubernator/api.py,sha256=Dm-zStoFNcif_2Rw28PqhtyWvudx-Z2PHdntVSgbFNc,31431
|
|
7
7
|
kubernator/app.py,sha256=ETgysPcIKEDsMTbdIw00-enSLip7Z2cECJrRxjf9ciw,21214
|
|
8
8
|
kubernator/merge.py,sha256=eW5fajnDdI2n8aUqRfTmdG6GWDvDtcVKPKsp3fiB5Nk,5882
|
|
9
9
|
kubernator/proc.py,sha256=43jrpTe1FCdhDIK0b6hnB6XqU_m7iYu3wbzJyzO3pl0,5979
|
|
@@ -12,20 +12,20 @@ kubernator/plugins/awscli.py,sha256=S6X7-qFiaZ7NDVDl2Jg0t-ih9KAJ45cUjjzd5Qe93ZM,
|
|
|
12
12
|
kubernator/plugins/eks.py,sha256=xe7vyPHNwuP8gEYDSzPyBkm-RkAtP64wCOqs9U5I7xI,2273
|
|
13
13
|
kubernator/plugins/gke.py,sha256=HZc-Bu2W8MvF50EgoAcZ8W-CAVEWJ4y8f4yG_3s8C1w,3429
|
|
14
14
|
kubernator/plugins/helm.py,sha256=2563hLr0uJucw0xo9JLfbCtpGPRZ5e5gYTnapQrqy3w,12036
|
|
15
|
-
kubernator/plugins/istio.py,sha256=
|
|
16
|
-
kubernator/plugins/k8s.py,sha256=
|
|
17
|
-
kubernator/plugins/k8s_api.py,sha256=
|
|
15
|
+
kubernator/plugins/istio.py,sha256=UFSBJo-I2x4F-ZO5WCSMpConOr_oYNZZb66DNOI_nME,15399
|
|
16
|
+
kubernator/plugins/k8s.py,sha256=Y9QSaRzX5BDE_-nmlwjHYgVOEZK4Zs_hvnJIZ8PxZyQ,28030
|
|
17
|
+
kubernator/plugins/k8s_api.py,sha256=dP4W8AFgH6mTvsbwd10EGfmG55wG3E0SZ7RGQpDgpdw,27897
|
|
18
18
|
kubernator/plugins/kops.py,sha256=-yhpEjydz9E7Ep24WtEs93rLTXtw4yakdgVqXlIj1ww,9688
|
|
19
19
|
kubernator/plugins/kubeconfig.py,sha256=uwtHmF2I6LiTPrC3M88G5SfYxDWtuh0MqcMfrHHoNRA,2178
|
|
20
|
-
kubernator/plugins/kubectl.py,sha256=
|
|
20
|
+
kubernator/plugins/kubectl.py,sha256=kz2BKJrg0M2yRJ4Tug9rZgjSEURbT5ybVx4fScDZt58,5102
|
|
21
21
|
kubernator/plugins/minikube.py,sha256=zbboER1VsCvIsh-yUE3_XpzPNcT4c6vh1LigDonEm3U,12384
|
|
22
22
|
kubernator/plugins/template.py,sha256=542nyS4ZNgdwJHEoIA5aLP1d4C312ydd7sPM9ZFbHuI,8357
|
|
23
23
|
kubernator/plugins/terraform.py,sha256=a1MPl9G8Rznjd28uMRdYWrjpFDLlFAVmLFH4hFEsMsQ,5285
|
|
24
24
|
kubernator/plugins/terragrunt.py,sha256=-qN8tTqPUXJ9O7CEiJVUB0GSUQU3DUTkv-aWdIIsm7Q,5051
|
|
25
|
-
kubernator-1.0.
|
|
26
|
-
kubernator-1.0.
|
|
27
|
-
kubernator-1.0.
|
|
28
|
-
kubernator-1.0.
|
|
29
|
-
kubernator-1.0.
|
|
30
|
-
kubernator-1.0.
|
|
31
|
-
kubernator-1.0.
|
|
25
|
+
kubernator-1.0.24.dev20251028221359.dist-info/METADATA,sha256=zcqg9pH8ANX4v_ia4HNPMGPv7pXhnJtojPg6tdq0YDM,10840
|
|
26
|
+
kubernator-1.0.24.dev20251028221359.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
27
|
+
kubernator-1.0.24.dev20251028221359.dist-info/entry_points.txt,sha256=IWDtHzyTleRqDSuVRXEr5GImrI7z_kh21t5DWZ8ldcQ,47
|
|
28
|
+
kubernator-1.0.24.dev20251028221359.dist-info/namespace_packages.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
29
|
+
kubernator-1.0.24.dev20251028221359.dist-info/top_level.txt,sha256=_z1CxWeKMI55ckf2vC8HqjbCn_E2Y_P5RdrhE_QWcIs,11
|
|
30
|
+
kubernator-1.0.24.dev20251028221359.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
31
|
+
kubernator-1.0.24.dev20251028221359.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|