kubernator 1.0.23.dev20251010010455__py3-none-any.whl → 1.0.23.dev20251016050525__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 CHANGED
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- __version__ = "1.0.23.dev20251010010455"
19
+ __version__ = "1.0.23.dev20251016050525"
20
20
 
21
21
 
22
22
  def _main():
@@ -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
- skip = False
281
- if e.status == 404 and missing_ok:
282
- skip = True
283
- if not skip:
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
- if e.status == 409:
301
- status = json.loads(e.body)
302
- if status["reason"] == "AlreadyExists" and exists_ok:
303
- skip = True
304
- if not skip:
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
 
@@ -122,6 +138,7 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
122
138
  ("apps", "Deployment"): K8SPropagationPolicy.ORPHAN,
123
139
  ("storage.k8s.io", "StorageClass"): K8SPropagationPolicy.ORPHAN,
124
140
  (None, "Pod"): K8SPropagationPolicy.BACKGROUND,
141
+ ("batch", "Job"): K8SPropagationPolicy.ORPHAN,
125
142
  },
126
143
  default_includes=Globs(["*.yaml", "*.yml"], True),
127
144
  default_excludes=Globs([".*"], True),
@@ -412,8 +429,8 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
412
429
 
413
430
  def handle_400_strict_validation_error(e: ApiException):
414
431
  if e.status == 400:
415
- status = json.loads(e.body)
416
-
432
+ # Assumes the body has been parsed
433
+ status = e.body
417
434
  if status["status"] == "Failure":
418
435
  if FIELD_VALIDATION_STRICT_MARKER in status["message"]:
419
436
  message = status["message"]
@@ -435,19 +452,24 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
435
452
  try:
436
453
  create_func()
437
454
  return
438
- except ApiException as e:
439
- if exists_ok or wait_for_delete:
440
- if e.status == 409:
441
- status = json.loads(e.body)
442
- if status["reason"] == "AlreadyExists":
443
- if wait_for_delete:
444
- sleep(self.context.k8s.conflict_retry_delay)
445
- logger.info("Retry creating resource %s%s%s", resource, status_msg,
446
- " (ignoring existing)" if exists_ok else "")
447
- continue
448
- else:
449
- return
450
- raise
455
+ except ApiException as __e:
456
+ api_exc_normalize_body(__e)
457
+ try:
458
+ if exists_ok or wait_for_delete:
459
+ if __e.status == 409:
460
+ status = __e.body
461
+ if status["reason"] == "AlreadyExists":
462
+ if wait_for_delete:
463
+ sleep(self.context.k8s.conflict_retry_delay)
464
+ logger.info("Retry creating resource %s%s%s", resource, status_msg,
465
+ " (ignoring existing)" if exists_ok else "")
466
+ continue
467
+ else:
468
+ return
469
+ raise
470
+ except ApiException as ___e:
471
+ api_exc_format_body(___e)
472
+ raise
451
473
 
452
474
  merge_instrs, normalized_manifest = extract_merge_instructions(resource.manifest, resource)
453
475
  if merge_instrs:
@@ -461,15 +483,20 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
461
483
  remote_resource = resource.get()
462
484
  logger.trace("Current resource %s: %s", resource, remote_resource)
463
485
  except ApiException as e:
464
- if e.status == 404:
465
- try:
466
- create()
467
- return 1, 0, 0
468
- except ApiException as e:
469
- if not handle_400_strict_validation_error(e):
470
- raise
471
-
472
- else:
486
+ api_exc_normalize_body(e)
487
+ try:
488
+ if e.status == 404:
489
+ try:
490
+ create()
491
+ return 1, 0, 0
492
+ except ApiException as e:
493
+ api_exc_normalize_body(e)
494
+ if not handle_400_strict_validation_error(e):
495
+ raise
496
+ else:
497
+ raise
498
+ except ApiException as _e:
499
+ api_exc_format_body(_e)
473
500
  raise
474
501
  else:
475
502
  logger.trace("Attempting to retrieve a normalized patch for resource %s: %s", resource, normalized_manifest)
@@ -479,36 +506,44 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
479
506
  dry_run=True,
480
507
  force=True)
481
508
  except ApiException as e:
482
- if e.status == 422:
483
- status = json.loads(e.body)
484
- details = status["details"]
485
- immutable_key = details.get("group"), details["kind"]
486
-
487
- try:
488
- propagation_policy = self.context.k8s.immutable_changes[immutable_key]
489
- except KeyError:
490
- raise e from None
509
+ try:
510
+ api_exc_normalize_body(e)
511
+
512
+ if e.status == 422:
513
+ status = e.body
514
+ # Assumes the body has been unmarshalled
515
+ details = status["details"]
516
+ immutable_key = details.get("group"), details["kind"]
517
+
518
+ try:
519
+ propagation_policy = self.context.k8s.immutable_changes[immutable_key]
520
+ except KeyError:
521
+ raise e from None
522
+ else:
523
+ for cause in details["causes"]:
524
+ if (
525
+ cause["reason"] == "FieldValueInvalid" and
526
+ "field is immutable" in cause["message"]
527
+ or
528
+ cause["reason"] == "FieldValueForbidden" and
529
+ ("Forbidden: updates to" in cause["message"]
530
+ or
531
+ "Forbidden: pod updates" in cause["message"])
532
+ ):
533
+ logger.info("Deleting resource %s (cascade %s)%s", resource,
534
+ propagation_policy.policy,
535
+ status_msg)
536
+ delete_func(propagation_policy=propagation_policy)
537
+ create(exists_ok=dry_run, wait_for_delete=not dry_run)
538
+ return 1, 0, 1
539
+ raise
491
540
  else:
492
- for cause in details["causes"]:
493
- if (
494
- cause["reason"] == "FieldValueInvalid" and
495
- "field is immutable" in cause["message"]
496
- or
497
- cause["reason"] == "FieldValueForbidden" and
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
541
+ if not handle_400_strict_validation_error(e):
542
+ raise
543
+ except ApiException as _e:
544
+ api_exc_format_body(_e)
545
+ raise
546
+
512
547
  else:
513
548
  logger.trace("Merged resource %s: %s", resource, merged_resource)
514
549
  if merge_instrs:
@@ -116,22 +116,22 @@ k8s_format_checker = FormatChecker()
116
116
 
117
117
  @k8s_format_checker.checks("int32")
118
118
  def check_int32(value):
119
- return -2147483648 < value < 2147483647
119
+ return value is not None and (-2147483648 < value < 2147483647)
120
120
 
121
121
 
122
122
  @k8s_format_checker.checks("int64")
123
123
  def check_int64(value):
124
- return -9223372036854775808 < value < 9223372036854775807
124
+ return value is not None and (-9223372036854775808 < value < 9223372036854775807)
125
125
 
126
126
 
127
127
  @k8s_format_checker.checks("float")
128
128
  def check_float(value):
129
- return -3.4E+38 < value < +3.4E+38
129
+ return value is not None and (-3.4E+38 < value < +3.4E+38)
130
130
 
131
131
 
132
132
  @k8s_format_checker.checks("double")
133
133
  def check_double(value):
134
- return -1.7E+308 < value < +1.7E+308
134
+ return value is not None and (-1.7E+308 < value < +1.7E+308)
135
135
 
136
136
 
137
137
  @k8s_format_checker.checks("byte", ValueError)
@@ -619,9 +619,9 @@ class K8SResourcePluginMixin:
619
619
  errors = list(self._validate_resource(manifest, source))
620
620
  if errors:
621
621
  for error in errors:
622
- if source:
623
- self.logger.error("Error detected in K8S manifest %s from %s",
624
- resource_description, source, exc_info=error)
622
+ self.logger.error("Error detected in K8S manifest %s from %s: \n%s",
623
+ resource_description, source or "<unknown>", yaml.safe_dump(manifest, None),
624
+ exc_info=error)
625
625
  raise errors[0]
626
626
 
627
627
  rdef = self._get_manifest_rdef(manifest)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kubernator
3
- Version: 1.0.23.dev20251010010455
3
+ Version: 1.0.23.dev20251016050525
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,5 +1,5 @@
1
1
  kubernator/LICENSE,sha256=wKKdOCMTCPQRV5gDkVLAsXX8qSnRJ5owk7yWPO1KZNo,11387
2
- kubernator/__init__.py,sha256=FzbtCh5XegjNjaDe91xX09kYGd2bMEThMPsx_8OBoQY,933
2
+ kubernator/__init__.py,sha256=5Jv1CmY-id1D3S3zLQ3LLcy6PVGc7WlSa6Sj3I56beI,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
@@ -12,9 +12,9 @@ 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=1dHjD9r6Kk2-tw6OFMOfBpksnqGMguTyyF1FwwWEtI8,14977
16
- kubernator/plugins/k8s.py,sha256=fvmkVaBz9CuGKmu_w6S1X0tWzSQvV6S6jx8c-X_ZIXI,25673
17
- kubernator/plugins/k8s_api.py,sha256=PDa7MB9q3WMm_9tr8T6LY_ojrHpyGYiNTlvBZinbgFY,27379
15
+ kubernator/plugins/istio.py,sha256=UFSBJo-I2x4F-ZO5WCSMpConOr_oYNZZb66DNOI_nME,15399
16
+ kubernator/plugins/k8s.py,sha256=A2qSOjkPasgBEc1Le2UXuSKTItd0Qz63E6Vv8WVQ0hQ,27307
17
+ kubernator/plugins/k8s_api.py,sha256=IkiegYwHJUasH5BlBxLo2_064cuzOGr3OJ1ToGy1p-s,27527
18
18
  kubernator/plugins/kops.py,sha256=-yhpEjydz9E7Ep24WtEs93rLTXtw4yakdgVqXlIj1ww,9688
19
19
  kubernator/plugins/kubeconfig.py,sha256=uwtHmF2I6LiTPrC3M88G5SfYxDWtuh0MqcMfrHHoNRA,2178
20
20
  kubernator/plugins/kubectl.py,sha256=hV6rnTj0XmQe5QJp3p6fNK3EQrWdNlam0qxsK3IkD5g,5125
@@ -22,10 +22,10 @@ kubernator/plugins/minikube.py,sha256=zbboER1VsCvIsh-yUE3_XpzPNcT4c6vh1LigDonEm3
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.23.dev20251010010455.dist-info/METADATA,sha256=XN7fMdues-A_taikGGhY-goi9SIng_5XrqyFscMzP5g,10840
26
- kubernator-1.0.23.dev20251010010455.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- kubernator-1.0.23.dev20251010010455.dist-info/entry_points.txt,sha256=IWDtHzyTleRqDSuVRXEr5GImrI7z_kh21t5DWZ8ldcQ,47
28
- kubernator-1.0.23.dev20251010010455.dist-info/namespace_packages.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
29
- kubernator-1.0.23.dev20251010010455.dist-info/top_level.txt,sha256=_z1CxWeKMI55ckf2vC8HqjbCn_E2Y_P5RdrhE_QWcIs,11
30
- kubernator-1.0.23.dev20251010010455.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
31
- kubernator-1.0.23.dev20251010010455.dist-info/RECORD,,
25
+ kubernator-1.0.23.dev20251016050525.dist-info/METADATA,sha256=BWAjtLDqU_LtP7LceuFmKkVPNjv4x6QznztRFqdBH4k,10840
26
+ kubernator-1.0.23.dev20251016050525.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ kubernator-1.0.23.dev20251016050525.dist-info/entry_points.txt,sha256=IWDtHzyTleRqDSuVRXEr5GImrI7z_kh21t5DWZ8ldcQ,47
28
+ kubernator-1.0.23.dev20251016050525.dist-info/namespace_packages.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
29
+ kubernator-1.0.23.dev20251016050525.dist-info/top_level.txt,sha256=_z1CxWeKMI55ckf2vC8HqjbCn_E2Y_P5RdrhE_QWcIs,11
30
+ kubernator-1.0.23.dev20251016050525.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
31
+ kubernator-1.0.23.dev20251016050525.dist-info/RECORD,,