kubernator 1.0.21.dev20250528230808__tar.gz → 1.0.23__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.
Files changed (36) hide show
  1. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/PKG-INFO +4 -4
  2. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/__init__.py +1 -1
  3. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/api.py +97 -57
  4. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/app.py +7 -3
  5. kubernator-1.0.23/kubernator/plugins/gke.py +105 -0
  6. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/helm.py +17 -4
  7. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/istio.py +28 -13
  8. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/k8s.py +105 -52
  9. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/k8s_api.py +7 -7
  10. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/kops.py +5 -4
  11. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/kubectl.py +36 -4
  12. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/minikube.py +42 -2
  13. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/proc.py +24 -2
  14. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator.egg-info/PKG-INFO +4 -4
  15. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator.egg-info/SOURCES.txt +1 -0
  16. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator.egg-info/requires.txt +1 -1
  17. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/setup.py +4 -4
  18. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/MANIFEST.in +0 -0
  19. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/LICENSE +0 -0
  20. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/__main__.py +0 -0
  21. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/_json_path.py +0 -0
  22. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/_k8s_client_patches.py +0 -0
  23. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/merge.py +0 -0
  24. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/__init__.py +0 -0
  25. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/awscli.py +0 -0
  26. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/eks.py +0 -0
  27. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/kubeconfig.py +0 -0
  28. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/template.py +0 -0
  29. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/terraform.py +0 -0
  30. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator/plugins/terragrunt.py +0 -0
  31. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator.egg-info/dependency_links.txt +0 -0
  32. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator.egg-info/entry_points.txt +0 -0
  33. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator.egg-info/namespace_packages.txt +0 -0
  34. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator.egg-info/top_level.txt +0 -0
  35. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/kubernator.egg-info/zip-safe +0 -0
  36. {kubernator-1.0.21.dev20250528230808 → kubernator-1.0.23}/setup.cfg +0 -0
@@ -1,23 +1,23 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kubernator
3
- Version: 1.0.21.dev20250528230808
3
+ Version: 1.0.23
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.
7
7
  Author-email:
8
8
  Maintainer: Karellen, Inc., Arcadiy Ivanov
9
9
  Maintainer-email: supervisor@karellen.co,arcadiy@karellen.co
10
- License: Apache License, Version 2.0
10
+ License: Apache-2.0
11
11
  Project-URL: Bug Tracker, https://github.com/karellen/kubernator/issues
12
12
  Project-URL: Documentation, https://github.com/karellen/kubernator/
13
13
  Project-URL: Source Code, https://github.com/karellen/kubernator/
14
14
  Keywords: kubernetes k8s kube top provisioning kOps terraform tf AWS
15
- Classifier: License :: OSI Approved :: Apache Software License
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
19
18
  Classifier: Programming Language :: Python :: 3.12
20
19
  Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
21
  Classifier: Operating System :: MacOS :: MacOS X
22
22
  Classifier: Operating System :: POSIX
23
23
  Classifier: Operating System :: POSIX :: Linux
@@ -45,7 +45,7 @@ Requires-Dist: kubernetes~=32.0
45
45
  Requires-Dist: openapi-schema-validator~=0.1
46
46
  Requires-Dist: openapi-spec-validator~=0.3
47
47
  Requires-Dist: platformdirs~=4.2
48
- Requires-Dist: requests<=2.31.0
48
+ Requires-Dist: requests>=2.31.0
49
49
  Dynamic: author
50
50
  Dynamic: classifier
51
51
  Dynamic: description
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- __version__ = "1.0.21.dev20250528230808"
19
+ __version__ = "1.0.23"
20
20
 
21
21
 
22
22
  def _main():
@@ -20,6 +20,7 @@ import fnmatch
20
20
  import json
21
21
  import logging
22
22
  import os
23
+ import io
23
24
  import platform
24
25
  import re
25
26
  import sys
@@ -58,6 +59,53 @@ _CACHE_HEADER_TRANSLATION = {"etag": "if-none-match",
58
59
  _CACHE_HEADERS = ("etag", "last-modified")
59
60
 
60
61
 
62
+ class TemplateEngine:
63
+ VARIABLE_START_STRING = "{${"
64
+ VARIABLE_END_STRING = "}$}"
65
+
66
+ def __init__(self, logger):
67
+ self.template_failures = 0
68
+ self.templates = {}
69
+
70
+ class CollectingUndefined(ChainableUndefined):
71
+ __slots__ = ()
72
+
73
+ def __str__(self):
74
+ self.template_failures += 1
75
+ return super().__str__()
76
+
77
+ logging_undefined = make_logging_undefined(
78
+ logger=logger,
79
+ base=CollectingUndefined
80
+ )
81
+
82
+ @pass_context
83
+ def variable_finalizer(ctx, value):
84
+ normalized_value = str(value)
85
+ if self.VARIABLE_START_STRING in normalized_value and self.VARIABLE_END_STRING in normalized_value:
86
+ value_template_content = sys.intern(normalized_value)
87
+ env: Environment = ctx.environment
88
+ value_template = self.templates.get(value_template_content)
89
+ if not value_template:
90
+ value_template = env.from_string(value_template_content, env.globals)
91
+ self.templates[value_template_content] = value_template
92
+ return value_template.render(ctx.parent)
93
+
94
+ return normalized_value
95
+
96
+ self.env = Environment(variable_start_string=self.VARIABLE_START_STRING,
97
+ variable_end_string=self.VARIABLE_END_STRING,
98
+ autoescape=False,
99
+ finalize=variable_finalizer,
100
+ undefined=logging_undefined)
101
+
102
+ def from_string(self, template):
103
+ return self.env.from_string(template)
104
+
105
+ def failures(self):
106
+ return self.template_failures
107
+
108
+
61
109
  def calling_frame_source(depth=2):
62
110
  f = traceback.extract_stack(limit=depth + 1)[0]
63
111
  return f"file {f.filename}, line {f.lineno} in {f.name}"
@@ -96,9 +144,15 @@ class FileType(Enum):
96
144
  self.func = func
97
145
 
98
146
 
99
- def _load_file(logger, path: Path, file_type: FileType, source=None) -> Iterable[dict]:
100
- with open(path, "rb") as f:
147
+ def _load_file(logger, path: Path, file_type: FileType, source=None,
148
+ template_engine: Optional[TemplateEngine] = None,
149
+ template_context: Optional[dict] = None) -> Iterable[dict]:
150
+ with open(path, "rb" if not template_engine else "rt") as f:
101
151
  try:
152
+ if template_engine:
153
+ raw_data = template_engine.from_string(f.read()).render(template_context)
154
+ f.close()
155
+ f = io.StringIO(raw_data)
102
156
  data = file_type.func(f)
103
157
  if isinstance(data, GeneratorType):
104
158
  data = list(data)
@@ -191,9 +245,12 @@ def load_remote_file(logger, url, file_type: FileType, category: str = "k8s", su
191
245
  return _load_file(logger, file_name, file_type, url)
192
246
 
193
247
 
194
- def load_file(logger, path: Path, file_type: FileType, source=None) -> Iterable[dict]:
248
+ def load_file(logger, path: Path, file_type: FileType, source=None,
249
+ template_engine: Optional[TemplateEngine] = None,
250
+ template_context: Optional[dict] = None) -> Iterable[dict]:
195
251
  logger.debug("Loading %s using %s", source or path, file_type.name)
196
- return _load_file(logger, path, file_type)
252
+ return _load_file(logger, path, file_type,
253
+ source, template_engine, template_context)
197
254
 
198
255
 
199
256
  def validator_with_defaults(validator_class):
@@ -513,53 +570,6 @@ class Globs(MutableSet[Union[str, re.Pattern]]):
513
570
  return f"Globs[{self._list}]"
514
571
 
515
572
 
516
- class TemplateEngine:
517
- VARIABLE_START_STRING = "{${"
518
- VARIABLE_END_STRING = "}$}"
519
-
520
- def __init__(self, logger):
521
- self.template_failures = 0
522
- self.templates = {}
523
-
524
- class CollectingUndefined(ChainableUndefined):
525
- __slots__ = ()
526
-
527
- def __str__(self):
528
- self.template_failures += 1
529
- return super().__str__()
530
-
531
- logging_undefined = make_logging_undefined(
532
- logger=logger,
533
- base=CollectingUndefined
534
- )
535
-
536
- @pass_context
537
- def variable_finalizer(ctx, value):
538
- normalized_value = str(value)
539
- if self.VARIABLE_START_STRING in normalized_value and self.VARIABLE_END_STRING in normalized_value:
540
- value_template_content = sys.intern(normalized_value)
541
- env: Environment = ctx.environment
542
- value_template = self.templates.get(value_template_content)
543
- if not value_template:
544
- value_template = env.from_string(value_template_content, env.globals)
545
- self.templates[value_template_content] = value_template
546
- return value_template.render(ctx.parent)
547
-
548
- return normalized_value
549
-
550
- self.env = Environment(variable_start_string=self.VARIABLE_START_STRING,
551
- variable_end_string=self.VARIABLE_END_STRING,
552
- autoescape=False,
553
- finalize=variable_finalizer,
554
- undefined=logging_undefined)
555
-
556
- def from_string(self, template):
557
- return self.env.from_string(template)
558
-
559
- def failures(self):
560
- return self.template_failures
561
-
562
-
563
573
  class Template:
564
574
  def __init__(self, name: str, template: JinjaTemplate, defaults: dict = None, path=None, source=None):
565
575
  self.name = name
@@ -768,7 +778,8 @@ class KubernatorPlugin:
768
778
  pass
769
779
 
770
780
 
771
- def install_python_k8s_client(run, package_major, logger, logger_stdout, logger_stderr, disable_patching):
781
+ def install_python_k8s_client(run, package_major, logger, logger_stdout, logger_stderr, disable_patching,
782
+ fallback=False):
772
783
  cache_dir = get_cache_dir("python")
773
784
  package_major_dir = cache_dir / str(package_major)
774
785
  package_major_dir_str = str(package_major_dir)
@@ -780,14 +791,43 @@ def install_python_k8s_client(run, package_major, logger, logger_stdout, logger_
780
791
  str(package_major), package_major_dir)
781
792
  rmtree(package_major_dir)
782
793
 
783
- if not package_major_dir.exists():
794
+ if not package_major_dir.exists() or not len(os.listdir(package_major_dir)):
784
795
  package_major_dir.mkdir(parents=True, exist_ok=True)
785
- run([sys.executable, "-m", "pip", "install", "--no-deps", "--no-input",
786
- "--root-user-action=ignore", "--break-system-packages", "--disable-pip-version-check",
787
- "--target", package_major_dir_str, f"kubernetes>={package_major!s}dev0,<{int(package_major) + 1!s}"],
788
- logger_stdout, logger_stderr).wait()
796
+ try:
797
+ run([sys.executable, "-m", "pip", "install", "--no-deps", "--no-input",
798
+ "--root-user-action=ignore", "--break-system-packages", "--disable-pip-version-check",
799
+ "--target", package_major_dir_str, f"kubernetes>={package_major!s}dev0,<{int(package_major) + 1!s}"],
800
+ logger_stdout, logger_stderr)
801
+ except CalledProcessError as e:
802
+ if not fallback and "No matching distribution found for" in e.stderr:
803
+ logger.warning("Kubernetes Client %s (%s) failed to install because the version wasn't found. "
804
+ "Falling back to a client of the previous version - %s",
805
+ str(package_major), package_major_dir, int(package_major) - 1)
806
+ return install_python_k8s_client(run,
807
+ int(package_major) - 1,
808
+ logger,
809
+ logger_stdout,
810
+ logger_stderr,
811
+ disable_patching,
812
+ fallback=True)
813
+ else:
814
+ raise
789
815
 
790
816
  if not patch_indicator.exists() and not disable_patching:
817
+ if not fallback and not len(os.listdir(package_major_dir)):
818
+ # Directory is empty
819
+ logger.warning("Kubernetes Client %s (%s) directory is empty - the client was not installed. "
820
+ "Falling back to a client of the previous version - %s",
821
+ str(package_major), package_major_dir, int(package_major) - 1)
822
+
823
+ return install_python_k8s_client(run,
824
+ int(package_major) - 1,
825
+ logger,
826
+ logger_stdout,
827
+ logger_stderr,
828
+ disable_patching,
829
+ fallback=True)
830
+
791
831
  for patch_text, target_file, skip_if_found, min_version, max_version, name in (
792
832
  URLLIB_HEADERS_PATCH, CUSTOM_OBJECT_PATCH_23, CUSTOM_OBJECT_PATCH_25):
793
833
  patch_target = package_major_dir / target_file
@@ -35,7 +35,7 @@ import kubernator
35
35
  from kubernator.api import (KubernatorPlugin, Globs, scan_dir, PropertyDict, config_as_dict, config_parent,
36
36
  download_remote_file, load_remote_file, Repository, StripNL, jp, get_app_cache_dir,
37
37
  get_cache_dir, install_python_k8s_client)
38
- from kubernator.proc import run, run_capturing_out
38
+ from kubernator.proc import run, run_capturing_out, run_pass_through_capturing
39
39
 
40
40
  TRACE = 5
41
41
 
@@ -215,7 +215,7 @@ class App(KubernatorPlugin):
215
215
  self.context = self._top_dir_context
216
216
  context = self.context
217
217
  self._run_handlers(KubernatorPlugin.handle_shutdown, True, context, None)
218
- except: # noqa E722
218
+ except: # noqa E722
219
219
  raise
220
220
  else:
221
221
  self.context = self._top_dir_context
@@ -348,6 +348,7 @@ class App(KubernatorPlugin):
348
348
  jp=jp,
349
349
  run=self._run,
350
350
  run_capturing_out=self._run_capturing_out,
351
+ run_passthrough_capturing=self._run_passthrough_capturing,
351
352
  repository=self.repository,
352
353
  StripNL=StripNL,
353
354
  default_includes=Globs(["*"], True),
@@ -465,6 +466,9 @@ class App(KubernatorPlugin):
465
466
  def _run_capturing_out(self, *args, **kwargs):
466
467
  return run_capturing_out(*args, **kwargs)
467
468
 
469
+ def _run_passthrough_capturing(self, *args, **kwargs):
470
+ return run_pass_through_capturing(*args, **kwargs)
471
+
468
472
  def __repr__(self):
469
473
  return "Kubernator"
470
474
 
@@ -493,7 +497,7 @@ def pre_cache_k8s_clients(*versions, disable_patching=False):
493
497
  for v in versions:
494
498
  logger.info("Caching K8S client library ~=v%s.0%s...", v,
495
499
  " (no patches)" if disable_patching else "")
496
- install_python_k8s_client(run, v, logger, stdout_logger, stderr_logger, disable_patching)
500
+ install_python_k8s_client(run_pass_through_capturing, v, logger, stdout_logger, stderr_logger, disable_patching)
497
501
 
498
502
 
499
503
  def main():
@@ -0,0 +1,105 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2020 Express Systems USA, Inc
4
+ # Copyright 2025 Karellen, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ import logging
20
+ import os
21
+ import tempfile
22
+ from pathlib import Path
23
+ from shutil import which
24
+
25
+ from kubernator.api import (KubernatorPlugin,
26
+ StripNL
27
+ )
28
+
29
+ logger = logging.getLogger("kubernator.gke")
30
+ proc_logger = logger.getChild("proc")
31
+ stdout_logger = StripNL(proc_logger.info)
32
+ stderr_logger = StripNL(proc_logger.warning)
33
+
34
+
35
+ class GkePlugin(KubernatorPlugin):
36
+ logger = logger
37
+
38
+ _name = "gke"
39
+
40
+ def __init__(self):
41
+ self.context = None
42
+ self.kubeconfig_dir = tempfile.TemporaryDirectory()
43
+ self.name = None
44
+ self.region = None
45
+ self.project = None
46
+ self.gcloud_file = None
47
+
48
+ super().__init__()
49
+
50
+ def set_context(self, context):
51
+ self.context = context
52
+
53
+ def register(self, *, name=None, region=None, project=None):
54
+ context = self.context
55
+
56
+ if not name:
57
+ raise ValueError("`name` is required")
58
+ if not region:
59
+ raise ValueError("`region` is required")
60
+ if not project:
61
+ raise ValueError("`project` is required")
62
+
63
+ self.name = name
64
+ self.region = region
65
+ self.project = project
66
+
67
+ # Use current version
68
+ gcloud_file = which("gcloud")
69
+ if not gcloud_file:
70
+ raise RuntimeError("`gcloud` cannot be found")
71
+ logger.debug("Found gcloud in %r", gcloud_file)
72
+ self.gcloud_file = gcloud_file
73
+
74
+ context.app.register_plugin("kubeconfig")
75
+
76
+ context.globals.gke = dict(kubeconfig=str(Path(self.kubeconfig_dir.name) / "config"),
77
+ name=name,
78
+ region=region,
79
+ project=project,
80
+ gcloud_file=gcloud_file
81
+ )
82
+
83
+ def handle_init(self):
84
+ context = self.context
85
+
86
+ env = dict(os.environ)
87
+ env["KUBECONFIG"] = str(context.gke.kubeconfig)
88
+ self.context.app.run([context.gke.gcloud_file, "components", "install", "gke-gcloud-auth-plugin"],
89
+ stdout_logger,
90
+ stderr_logger).wait()
91
+ self.context.app.run([context.gke.gcloud_file, "container", "clusters", "get-credentials",
92
+ context.gke.name,
93
+ "--region", context.gke.region,
94
+ "--project", context.gke.project],
95
+ stdout_logger,
96
+ stderr_logger,
97
+ env=env).wait()
98
+
99
+ context.kubeconfig.set(context.gke.kubeconfig)
100
+
101
+ def handle_shutdown(self):
102
+ self.kubeconfig_dir.cleanup()
103
+
104
+ def __repr__(self):
105
+ return "GKE Plugin"
@@ -37,7 +37,7 @@ from kubernator.api import (KubernatorPlugin, Globs, StripNL,
37
37
  validator_with_defaults,
38
38
  get_golang_os,
39
39
  get_golang_machine,
40
- prepend_os_path
40
+ prepend_os_path, TemplateEngine
41
41
  )
42
42
  from kubernator.plugins.k8s_api import K8SResource
43
43
  from kubernator.proc import DEVNULL
@@ -102,6 +102,7 @@ class HelmPlugin(KubernatorPlugin):
102
102
  self.context = None
103
103
  self.repositories = set()
104
104
  self.helm_dir = None
105
+ self.template_engine = TemplateEngine(logger)
105
106
 
106
107
  def set_context(self, context):
107
108
  self.context = context
@@ -180,7 +181,9 @@ class HelmPlugin(KubernatorPlugin):
180
181
  display_p = context.app.display_path(p)
181
182
  logger.debug("Adding Helm template from %s", display_p)
182
183
 
183
- helm_templates = load_file(logger, p, FileType.YAML, display_p)
184
+ helm_templates = load_file(logger, p, FileType.YAML, display_p,
185
+ self.template_engine,
186
+ {"ktor": context})
184
187
 
185
188
  for helm_template in helm_templates:
186
189
  self._add_helm(helm_template, display_p)
@@ -232,6 +235,17 @@ class HelmPlugin(KubernatorPlugin):
232
235
  values_file = Path(values_file)
233
236
  if not values_file.is_absolute():
234
237
  values_file = self.context.app.cwd / values_file
238
+ values = list(load_file(logger, values_file, FileType.YAML,
239
+ template_engine=self.template_engine,
240
+ template_context={"ktor": self.context,
241
+ "helm": {"chart": chart,
242
+ "name": name,
243
+ "namespace": namespace,
244
+ "include_crds": include_crds,
245
+ "repository": repository,
246
+ "version": version,
247
+ }}))
248
+ values = values[0] if values else {}
235
249
 
236
250
  version_spec = []
237
251
  if repository:
@@ -260,8 +274,7 @@ class HelmPlugin(KubernatorPlugin):
260
274
  ] +
261
275
  version_spec +
262
276
  (["--include-crds"] if include_crds else []) +
263
- (["-f", values_file] if values_file else []) +
264
- (["-f", "-"] if values else []),
277
+ ["-f", "-"],
265
278
  stderr_logger,
266
279
  stdin=stdin,
267
280
  )
@@ -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,
@@ -33,7 +34,8 @@ from kubernator.api import (KubernatorPlugin, scan_dir,
33
34
  Globs,
34
35
  get_golang_os,
35
36
  get_golang_machine,
36
- prepend_os_path, jp)
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")
@@ -210,10 +212,11 @@ class IstioPlugin(KubernatorPlugin, K8SResourcePluginMixin):
210
212
  display_p = context.app.display_path(p)
211
213
  logger.info("Adding Istio Operator from %s", display_p)
212
214
 
213
- with open(p, "rt") as file:
214
- template = self.template_engine.from_string(file.read())
215
+ manifests = load_file(logger, p, FileType.YAML, display_p,
216
+ self.template_engine,
217
+ {"ktor": context})
215
218
 
216
- self.add_resources(template.render({"ktor": context}), display_p)
219
+ self.add_resources(manifests, display_p)
217
220
 
218
221
  def handle_apply(self):
219
222
  context = self.context
@@ -276,11 +279,17 @@ class IstioPlugin(KubernatorPlugin, K8SResourcePluginMixin):
276
279
  try:
277
280
  res.delete(dry_run=dry_run)
278
281
  except ApiException as e:
279
- skip = False
280
- if e.status == 404 and missing_ok:
281
- skip = True
282
- 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)
283
291
  raise
292
+
284
293
  return res
285
294
 
286
295
  def _create_resource_internal(self, manifest, dry_run=True, exists_ok=False):
@@ -296,12 +305,18 @@ class IstioPlugin(KubernatorPlugin, K8SResourcePluginMixin):
296
305
  res.create(dry_run=dry_run)
297
306
  except ApiException as e:
298
307
  skip = False
299
- if e.status == 409:
300
- status = json.loads(e.body)
301
- if status["reason"] == "AlreadyExists" and exists_ok:
302
- skip = True
303
- 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)
304
318
  raise
319
+
305
320
  return res
306
321
 
307
322
  def _install(self, operators_file, dry_run):
@@ -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,
@@ -38,7 +39,9 @@ from kubernator.api import (KubernatorPlugin,
38
39
  FileType,
39
40
  load_remote_file,
40
41
  StripNL,
41
- install_python_k8s_client)
42
+ install_python_k8s_client,
43
+ TemplateEngine,
44
+ sleep)
42
45
  from kubernator.merge import extract_merge_instructions, apply_merge_instructions
43
46
  from kubernator.plugins.k8s_api import (K8SResourcePluginMixin,
44
47
  K8SResource,
@@ -81,6 +84,21 @@ def normalize_pkg_version(v: str):
81
84
  return tuple(map(int, v_split))
82
85
 
83
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
+
84
102
  class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
85
103
  logger = logger
86
104
 
@@ -95,6 +113,7 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
95
113
  self._transformers = []
96
114
  self._validators = []
97
115
  self._summary = 0, 0, 0
116
+ self._template_engine = TemplateEngine(logger)
98
117
 
99
118
  def set_context(self, context):
100
119
  self.context = context
@@ -118,6 +137,8 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
118
137
  ("apps", "StatefulSet"): K8SPropagationPolicy.ORPHAN,
119
138
  ("apps", "Deployment"): K8SPropagationPolicy.ORPHAN,
120
139
  ("storage.k8s.io", "StorageClass"): K8SPropagationPolicy.ORPHAN,
140
+ (None, "Pod"): K8SPropagationPolicy.BACKGROUND,
141
+ ("batch", "Job"): K8SPropagationPolicy.ORPHAN,
121
142
  },
122
143
  default_includes=Globs(["*.yaml", "*.yml"], True),
123
144
  default_excludes=Globs([".*"], True),
@@ -135,6 +156,7 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
135
156
  field_validation=field_validation,
136
157
  field_validation_warn_fatal=field_validation_warn_fatal,
137
158
  field_validation_warnings=0,
159
+ conflict_retry_delay=0.3,
138
160
  _k8s=self,
139
161
  )
140
162
  context.k8s = dict(default_includes=Globs(context.globals.k8s.default_includes),
@@ -164,7 +186,7 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
164
186
 
165
187
  logger.info("Using Kubernetes client version =~%s.0 for server version %s",
166
188
  server_minor, ".".join(k8s.server_version))
167
- pkg_dir = install_python_k8s_client(self.context.app.run, server_minor, logger,
189
+ pkg_dir = install_python_k8s_client(self.context.app.run_passthrough_capturing, server_minor, logger,
168
190
  stdout_logger, stderr_logger, k8s.disable_client_patches)
169
191
 
170
192
  modules_to_delete = []
@@ -197,7 +219,7 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
197
219
 
198
220
  k8s.client = self._setup_k8s_client()
199
221
  version = client.VersionApi(k8s.client).get_code()
200
- if "-eks-" in version.git_version:
222
+ if "-eks-" or "-gke" in version.git_version:
201
223
  git_version = version.git_version.split("-")[0]
202
224
  else:
203
225
  git_version = version.git_version
@@ -239,7 +261,10 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
239
261
  display_p = context.app.display_path(p)
240
262
  logger.debug("Adding Kubernetes manifest from %s", display_p)
241
263
 
242
- manifests = load_file(logger, p, FileType.YAML, display_p)
264
+ manifests = load_file(logger, p, FileType.YAML, display_p,
265
+ self._template_engine,
266
+ {"ktor": context}
267
+ )
243
268
 
244
269
  for manifest in manifests:
245
270
  if manifest:
@@ -404,8 +429,8 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
404
429
 
405
430
  def handle_400_strict_validation_error(e: ApiException):
406
431
  if e.status == 400:
407
- status = json.loads(e.body)
408
-
432
+ # Assumes the body has been parsed
433
+ status = e.body
409
434
  if status["status"] == "Failure":
410
435
  if FIELD_VALIDATION_STRICT_MARKER in status["message"]:
411
436
  message = status["message"]
@@ -420,18 +445,31 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
420
445
  resource, resource.source, status["message"])
421
446
  raise e from None
422
447
 
423
- def create(exists_ok=False):
448
+ def create(exists_ok=False, wait_for_delete=False):
424
449
  logger.info("Creating resource %s%s%s", resource, status_msg,
425
450
  " (ignoring existing)" if exists_ok else "")
426
- try:
427
- create_func()
428
- except ApiException as e:
429
- if exists_ok:
430
- if e.status == 409:
431
- status = json.loads(e.body)
432
- if status["reason"] == "AlreadyExists":
433
- return
434
- raise
451
+ while True:
452
+ try:
453
+ create_func()
454
+ return
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
435
473
 
436
474
  merge_instrs, normalized_manifest = extract_merge_instructions(resource.manifest, resource)
437
475
  if merge_instrs:
@@ -445,15 +483,20 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
445
483
  remote_resource = resource.get()
446
484
  logger.trace("Current resource %s: %s", resource, remote_resource)
447
485
  except ApiException as e:
448
- if e.status == 404:
449
- try:
450
- create()
451
- return 1, 0, 0
452
- except ApiException as e:
453
- if not handle_400_strict_validation_error(e):
454
- raise
455
-
456
- 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)
457
500
  raise
458
501
  else:
459
502
  logger.trace("Attempting to retrieve a normalized patch for resource %s: %s", resource, normalized_manifest)
@@ -463,34 +506,44 @@ class KubernetesPlugin(KubernatorPlugin, K8SResourcePluginMixin):
463
506
  dry_run=True,
464
507
  force=True)
465
508
  except ApiException as e:
466
- if e.status == 422:
467
- status = json.loads(e.body)
468
- details = status["details"]
469
- immutable_key = details["group"], details["kind"]
470
-
471
- try:
472
- propagation_policy = self.context.k8s.immutable_changes[immutable_key]
473
- except KeyError:
474
- 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
475
540
  else:
476
- for cause in details["causes"]:
477
- if (
478
- cause["reason"] == "FieldValueInvalid" and
479
- "field is immutable" in cause["message"]
480
- or
481
- cause["reason"] == "FieldValueForbidden" and
482
- "Forbidden: updates to" in cause["message"]
483
- ):
484
- logger.info("Deleting resource %s (cascade %s)%s", resource,
485
- propagation_policy.policy,
486
- status_msg)
487
- delete_func(propagation_policy=propagation_policy)
488
- create(exists_ok=dry_run)
489
- return 1, 0, 1
490
- raise
491
- else:
492
- if not handle_400_strict_validation_error(e):
493
- 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
+
494
547
  else:
495
548
  logger.trace("Merged resource %s: %s", resource, merged_resource)
496
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)
@@ -30,7 +30,7 @@ from kubernator.api import (KubernatorPlugin, scan_dir,
30
30
  io_StringIO,
31
31
  TemplateEngine,
32
32
  StripNL,
33
- Globs)
33
+ Globs, load_file)
34
34
  from kubernator.plugins.k8s_api import K8SResourcePluginMixin
35
35
  from kubernator.proc import CalledProcessError
36
36
 
@@ -136,10 +136,11 @@ class KopsPlugin(KubernatorPlugin, K8SResourcePluginMixin):
136
136
  display_p = context.app.display_path(p)
137
137
  logger.debug("Adding Kops resources from %s", display_p)
138
138
 
139
- with open(p, "rt") as file:
140
- template = self.template_engine.from_string(file.read())
139
+ manifests = load_file(logger, p, FileType.YAML, display_p,
140
+ self.template_engine,
141
+ {"ktor": context})
141
142
 
142
- self.add_resources(template.render({"ktor": context}), display_p)
143
+ self.add_resources(manifests, display_p)
143
144
 
144
145
  def update(self):
145
146
  context = self.context
@@ -16,6 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ import io
19
20
  import json
20
21
  import logging
21
22
  import os
@@ -23,6 +24,8 @@ import tempfile
23
24
  from pathlib import Path
24
25
  from shutil import which, copy
25
26
 
27
+ import yaml
28
+
26
29
  from kubernator.api import (KubernatorPlugin,
27
30
  prepend_os_path,
28
31
  StripNL,
@@ -89,15 +92,44 @@ class KubectlPlugin(KubernatorPlugin):
89
92
  context.globals.kubectl = dict(version=version,
90
93
  kubectl_file=kubectl_file,
91
94
  stanza=self.stanza,
92
- test=self.test_kubectl
95
+ test=self.test_kubectl,
96
+ run=self.run,
97
+ run_capturing=self.run_capturing,
98
+ get=self.get,
93
99
  )
94
100
 
95
101
  context.globals.kubectl.version = context.kubectl.test()
96
102
 
103
+ def run_capturing(self, *args, **kwargs):
104
+ return self.context.app.run_capturing_out(self.stanza() +
105
+ list(args),
106
+ stderr_logger,
107
+ **kwargs
108
+ )
109
+
110
+ def run(self, *args, **kwargs):
111
+ self.context.app.run(self.stanza() +
112
+ list(args),
113
+ stdout_logger,
114
+ stderr_logger,
115
+ **kwargs
116
+ ).wait()
117
+
118
+ def get(self, resource_type, resource_name, namespace=None):
119
+ args = ["get", resource_type, resource_name]
120
+ if namespace:
121
+ args += ["-n", namespace]
122
+ args += ["-o", "yaml"]
123
+
124
+ res = list(yaml.safe_load_all(io.StringIO(self.context.kubectl.run_capturing(*args))))
125
+ if len(res):
126
+ if len(res) > 1:
127
+ return res
128
+ return res[0]
129
+ return None
130
+
97
131
  def test_kubectl(self):
98
- version_out: str = self.context.app.run_capturing_out(self.stanza() +
99
- ["version", "--client=true", "-o", "json"],
100
- stderr_logger)
132
+ version_out: str = self.run_capturing("version", "--client=true", "-o", "json")
101
133
 
102
134
  version_out_js = json.loads(version_out)
103
135
  kubectl_version = version_out_js["clientVersion"]["gitVersion"][1:]
@@ -15,7 +15,7 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
-
18
+ import json
19
19
  import logging
20
20
  import os
21
21
  import tempfile
@@ -35,6 +35,8 @@ proc_logger = logger.getChild("proc")
35
35
  stdout_logger = StripNL(proc_logger.info)
36
36
  stderr_logger = StripNL(proc_logger.warning)
37
37
 
38
+ MINIKUBE_MAX_VERSION_LEGACY = "1.36.0"
39
+
38
40
 
39
41
  class MinikubePlugin(KubernatorPlugin):
40
42
  logger = logger
@@ -89,7 +91,7 @@ class MinikubePlugin(KubernatorPlugin):
89
91
 
90
92
  def register(self, minikube_version=None, profile="default", k8s_version=None,
91
93
  keep_running=False, start_fresh=False,
92
- nodes=1, driver=None, cpus="no-limit", extra_args=None):
94
+ nodes=1, driver=None, cpus="no-limit", extra_args=None, extra_addons=None):
93
95
  context = self.context
94
96
 
95
97
  context.app.register_plugin("kubeconfig")
@@ -99,9 +101,17 @@ class MinikubePlugin(KubernatorPlugin):
99
101
  logger.critical(msg)
100
102
  raise RuntimeError(msg)
101
103
 
104
+ k8s_version_tuple = tuple(map(int, k8s_version.split(".")))
105
+
102
106
  if not minikube_version:
103
107
  minikube_version = self.get_latest_minikube_version()
104
108
  logger.info("No minikube version is specified, latest is %s", minikube_version)
109
+ if k8s_version_tuple < (1, 28, 0):
110
+ logger.info("While latest minikube version is %s, "
111
+ "the requested K8S version %s requires %s or earlier - choosing %s",
112
+ minikube_version, k8s_version, MINIKUBE_MAX_VERSION_LEGACY,
113
+ MINIKUBE_MAX_VERSION_LEGACY)
114
+ minikube_version = MINIKUBE_MAX_VERSION_LEGACY
105
115
 
106
116
  minikube_dl_file, _ = context.app.download_remote_file(logger,
107
117
  f"https://github.com/kubernetes/minikube/releases"
@@ -156,12 +166,14 @@ class MinikubePlugin(KubernatorPlugin):
156
166
  minikube_file=str(minikube_file),
157
167
  profile=profile,
158
168
  k8s_version=k8s_version,
169
+ k8s_version_tuple=k8s_version_tuple,
159
170
  start_fresh=start_fresh,
160
171
  keep_running=keep_running,
161
172
  nodes=nodes,
162
173
  driver=driver,
163
174
  cpus=cpus,
164
175
  extra_args=extra_args or [],
176
+ extra_addons=extra_addons or [],
165
177
  kubeconfig=str(self.kubeconfig_dir / "config"),
166
178
  cmd=self.cmd,
167
179
  cmd_out=self.cmd_out
@@ -192,6 +204,16 @@ class MinikubePlugin(KubernatorPlugin):
192
204
  "--wait", "apiserver",
193
205
  "--nodes", str(minikube.nodes)]
194
206
 
207
+ addons = []
208
+ if minikube.k8s_version_tuple >= (1, 28):
209
+ addons += ["volumesnapshots", "csi-hostpath-driver"]
210
+
211
+ if minikube.extra_addons:
212
+ addons += minikube.extra_addons
213
+
214
+ if addons:
215
+ args += ["--addons", ",".join(addons)]
216
+
195
217
  if minikube.driver == "docker":
196
218
  args.extend(["--cpus", str(minikube.cpus)])
197
219
 
@@ -202,6 +224,24 @@ class MinikubePlugin(KubernatorPlugin):
202
224
  logger.info("Updating minikube profile %r context", minikube.profile)
203
225
  self.cmd("update-context")
204
226
 
227
+ if minikube.k8s_version_tuple >= (1, 28):
228
+ logger.info("Disabling old storage addons")
229
+ self.cmd("addons", "disable", "storage-provisioner")
230
+ self.cmd("addons", "disable", "default-storageclass")
231
+
232
+ logger.info("Running initialization scripts for profile %r", minikube.profile)
233
+ self.context.app.register_plugin("kubectl", version=minikube.k8s_version)
234
+ if minikube.k8s_version_tuple >= (1, 28):
235
+ storage_class = self.context.kubectl.get("storageclass", "csi-hostpath-sc")
236
+ self.context.kubectl.run("delete", "storageclass", "csi-hostpath-sc")
237
+ storage_class["metadata"]["annotations"]["storageclass.kubernetes.io/is-default-class"] = "true"
238
+ storage_class["volumeBindingMode"] = "WaitForFirstConsumer"
239
+
240
+ def write_stdin():
241
+ return json.dumps(storage_class)
242
+
243
+ self.context.kubectl.run("create", "-f", "-", stdin=write_stdin)
244
+
205
245
  def minikube_stop(self):
206
246
  minikube = self.context.minikube
207
247
  if self.minikube_is_running():
@@ -108,7 +108,7 @@ class ProcessRunner:
108
108
  raise RuntimeError("not available")
109
109
  return self._proc.stdin
110
110
 
111
- def wait(self, fail=True, timeout=None, _out_func=None):
111
+ def wait(self, fail=True, timeout=None, _out_func=None, _stderr_func=None):
112
112
  with Timeout(timeout, TimeoutExpired):
113
113
  retcode = self._proc.wait()
114
114
  if self._stdin_writer:
@@ -119,9 +119,12 @@ class ProcessRunner:
119
119
  self._stderr_reader.join()
120
120
  if fail and retcode:
121
121
  output = None
122
+ stderr = None
122
123
  if _out_func:
123
124
  output = _out_func()
124
- raise CalledProcessError(retcode, self._safe_args, output=output)
125
+ if _stderr_func:
126
+ stderr = _stderr_func()
127
+ raise CalledProcessError(retcode, self._safe_args, output=output, stderr=stderr)
125
128
  return retcode
126
129
 
127
130
  def terminate(self):
@@ -134,6 +137,25 @@ class ProcessRunner:
134
137
  run = ProcessRunner
135
138
 
136
139
 
140
+ def run_pass_through_capturing(args, stdout_logger, stderr_logger, stdin=DEVNULL, *, safe_args=None,
141
+ universal_newlines=True, **kwargs):
142
+ out = StringIO(trimmed=False) if universal_newlines else BytesIO()
143
+ err = StringIO(trimmed=False) if universal_newlines else BytesIO()
144
+
145
+ def write_out(data):
146
+ out.write(data)
147
+ stdout_logger(data)
148
+
149
+ def write_err(data):
150
+ err.write(data)
151
+ stderr_logger(data)
152
+
153
+ proc = run(args, write_out, write_err, stdin, safe_args=safe_args, universal_newlines=universal_newlines,
154
+ **kwargs)
155
+ proc.wait(_out_func=lambda: out.getvalue(), _stderr_func=lambda: err.getvalue())
156
+ return out.getvalue(), err.getvalue()
157
+
158
+
137
159
  def run_capturing_out(args, stderr_logger, stdin=DEVNULL, *, safe_args=None, universal_newlines=True, **kwargs):
138
160
  out = StringIO(trimmed=False) if universal_newlines else BytesIO()
139
161
  proc = run(args, out.write, stderr_logger, stdin, safe_args=safe_args, universal_newlines=universal_newlines,
@@ -1,23 +1,23 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kubernator
3
- Version: 1.0.21.dev20250528230808
3
+ Version: 1.0.23
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.
7
7
  Author-email:
8
8
  Maintainer: Karellen, Inc., Arcadiy Ivanov
9
9
  Maintainer-email: supervisor@karellen.co,arcadiy@karellen.co
10
- License: Apache License, Version 2.0
10
+ License: Apache-2.0
11
11
  Project-URL: Bug Tracker, https://github.com/karellen/kubernator/issues
12
12
  Project-URL: Documentation, https://github.com/karellen/kubernator/
13
13
  Project-URL: Source Code, https://github.com/karellen/kubernator/
14
14
  Keywords: kubernetes k8s kube top provisioning kOps terraform tf AWS
15
- Classifier: License :: OSI Approved :: Apache Software License
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
19
18
  Classifier: Programming Language :: Python :: 3.12
20
19
  Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
21
  Classifier: Operating System :: MacOS :: MacOS X
22
22
  Classifier: Operating System :: POSIX
23
23
  Classifier: Operating System :: POSIX :: Linux
@@ -45,7 +45,7 @@ Requires-Dist: kubernetes~=32.0
45
45
  Requires-Dist: openapi-schema-validator~=0.1
46
46
  Requires-Dist: openapi-spec-validator~=0.3
47
47
  Requires-Dist: platformdirs~=4.2
48
- Requires-Dist: requests<=2.31.0
48
+ Requires-Dist: requests>=2.31.0
49
49
  Dynamic: author
50
50
  Dynamic: classifier
51
51
  Dynamic: description
@@ -20,6 +20,7 @@ kubernator.egg-info/zip-safe
20
20
  kubernator/plugins/__init__.py
21
21
  kubernator/plugins/awscli.py
22
22
  kubernator/plugins/eks.py
23
+ kubernator/plugins/gke.py
23
24
  kubernator/plugins/helm.py
24
25
  kubernator/plugins/istio.py
25
26
  kubernator/plugins/k8s.py
@@ -11,4 +11,4 @@ kubernetes~=32.0
11
11
  openapi-schema-validator~=0.1
12
12
  openapi-spec-validator~=0.3
13
13
  platformdirs~=4.2
14
- requests<=2.31.0
14
+ requests>=2.31.0
@@ -21,17 +21,17 @@ class install(_install):
21
21
  if __name__ == '__main__':
22
22
  setup(
23
23
  name = 'kubernator',
24
- version = '1.0.21.dev20250528230808',
24
+ version = '1.0.23',
25
25
  description = 'Kubernator is the a pluggable framework for K8S provisioning',
26
26
  long_description = '# Kubernator\n\nKubernator™ (Ktor™) is an integrated solution for the Kubernetes state management. It operates on directories,\nprocessing their content via a collection of plugins, generating Kubernetes resources in the process, validating them,\ntransforming them and then applying against the Kubernetes cluster.\n\n[![Gitter](https://img.shields.io/gitter/room/karellen/lobby?logo=gitter)](https://gitter.im/karellen/Lobby)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/karellen/kubernator/kubernator.yml?branch=master)](https://github.com/karellen/kubernator/actions/workflows/kubernator.yml)\n[![Coverage Status](https://img.shields.io/coveralls/github/karellen/kubernator/master?logo=coveralls)](https://coveralls.io/r/karellen/kubernator?branch=master)\n\n[![Kubernator Version](https://img.shields.io/pypi/v/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n[![Kubernator Python Versions](https://img.shields.io/pypi/pyversions/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n[![Kubernator Downloads Per Day](https://img.shields.io/pypi/dd/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n[![Kubernator Downloads Per Week](https://img.shields.io/pypi/dw/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n[![Kubernator Downloads Per Month](https://img.shields.io/pypi/dm/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n\n## Notices\n\n### Beta Software\n\nWhile fully functional in the current state and used in production, this software is in **BETA**. A lot of things\nare expected to change rapidly, including main APIs, initialization procedures and some core features. Documentation at\nthis stage is basically non-existent.\n\n### License\n\nThe product is licensed under the Apache License, Version 2.0. Please see LICENSE for further details.\n\n### Warranties and Liability\n\nKubernator and its plugins are provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\nexpress or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,\nMERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of\nusing or redistributing Kubernator and assume any risks associated with doing so.\n\n### Trademarks\n\n"Kubernator" and "Ktor" are trademarks or registered trademarks of Express Systems USA, Inc and Karellen, Inc. All other\ntrademarks are property of their respective owners.\n\n## Problem Statement\n\n## Solution\n\n## Using Kubernator with Docker\n\nA simple example is as follows:\n```\n$ docker run --mount type=bind,source="$(pwd)",target=/root,readonly -t ghcr.io/karellen/kubernator:latest\n```\n\n## Using Kubernator on MacOS\n\n```\n$ brew install python3.11\n$ pip3.11 install \'kubernator~=1.0.9\'\n$ kubernator --version\n```\n\nPlease note, that some plugins (e.g. `awscli`, `eks`) may require additional volume mounts or environmental\nvariables to be passed for credentials and other external configuration.\n\n## Mode of Operation\n\nKubernator is a command line utility. Upon startup and processing of the command line arguments and initializing\nlogging, Kubernator initializes plugins. Current plugins include:\n\n0. Kubernator App\n1. Terraform\n2. kOps\n3. Kubernetes\n4. Helm\n5. Template\n\nThe order of initialization matters as it\'s the order the plugin handlers are executed!\n\nThe entire application operates in the following stages by invoking each plugin\'s stage handler in sequence:\n\n1. Plugin Init Stage\n2. Pre-start script (if specified)\n3. Plugin Start Stage\n4. For each directory in the pipeline:\n 1. Plugin Before Directory Stage\n 2. If `.kubernator.py` is present in the directory:\n 1. Plugin Before Script Stage\n 2. `.kubernator.py` script\n 3. Plugin After Script Stage\n 3. Plugin After Directory Stage\n5. Plugin End Stage\n\nEach plugin individually plays a specific role and performs a specific function which will be described in a later\nsection.\n\n## State/Context\n\nThere is a global state that is carried through as the application is running. It is a hierarchy of objects (`context`)\nthat follows the parent-child relationship as the application traverses the directory structure. For example, given the\ndirectory structure `/a/b`, `/a/c`, and `/a/c/d` any value of the context set or modified in context scoped to\ndirectory `/a` is visible in directories `/a/b`, `/a/c` and `/a/c/d`, while the same modified or set in `/a/b` is only\nvisible there, while one in `/a/c` is visible in `/a/c` and in `/a/c/d` but not `/a` or `/a/b`.\n\nAdditionally, there is a `context.globals` which is the top-most context that is available in all stages that are not\nassociated with the directory structure.\n\nNote, that in cases where the directory structure traversal moves to remote directories (that are actualized by local\ntemporary directories), such remote directory structure enters the context hierarchy as a child of the directory in\nwhich remote was registered.\n\nAlso note, that context carries not just data by references to essential functions.\n\nIn pre-start and `.kubernator.py` scripts the context is fully available as a global variable `ktor`.\n\n### Plugins\n\n#### Kubernator App Plugin\n\nThe role of the Kubernator App Plugin is to traverse the directory structure, expose essential functions through context\nand to run Kubernator scripts.\n\nIn the *After Directory Stage* Kubernator app scans the directories immediately available in the current, sorts them in\nthe alphabetic order, excludes those matching any of the patterns in `context.app.excludes` and then queues up the\nremaining directories in the order the match the patterns in `context.app.includes`.\n\nThus, for a directory content `/a/foo`, `/a/bal`, `/a/bar`, `/a/baz`, excludes `f*`, and includes `baz` and `*`, the\nresulting queue of directories to traverse will be `/a/baz`, `/a/bal`, `/a/bar`.\n\nNotice, that user can further interfere with processing order of the directory queue by asking Kubernator to walk\narbitrary paths, both local and remote.\n\n##### Context\n\n* `ktor.app.args`\n > Namespace containing command line argument values\n* `ktor.app.walk_local(*paths: Union[Path, str, bytes])`\n > Immediately schedules the paths to be traversed after the current directory by adding them to the queue\n > Relative path is relative to the current directory\n* `ktor.app.walk_remote(repo, *path_prefixes: Union[Path, str, bytes])`\n > Immediately schedules the path prefixes under the remote repo URL to be traversed after the current directory by\n > adding them to the queue. Only Git URLs are currently supported.\n > All absolute path prefixes are relativized based on the repository.\n* `ktor.app.repository_credentials_provider(func: Callable)`\n > Sets a repository credentials provider function `func` that sets/overwrites credentials for URLs being specified by\n > `walk_remote`. The callable `func` accepts a single argument containing a parsed URL in a form of tuple. The `func`\n > is expected to return a tuple of three elements representing URL schema, username and password. If the value should\n > not be changed it should be None. To convert from `git://repo.com/hello` to HTTPS authentication one should write\n > a function returning `("https", "username", "password")`. The best utility is achieved by logic that allows running\n > the plan both in CI and local environments using different authentication mechanics in different environments.\n\n#### Terraform\n\nThis is exclusively designed to pull the configuration options out of Terraform and to allow scripts and plugins to\nutilize that data.\n\n##### Context\n\n* `ktor.tf`\n > A dictionary containing the values from Terraform output\n\n#### Kops\n\n##### Context\n\n#### Kubernetes\n\n##### Context\n\n#### Helm\n\n##### Context\n\n#### Templates\n\n##### Context\n\n## Examples\n\n### Adding Remote Directory\n\n```python\nktor.app.repository_credentials_provider(lambda r: ("ssh", "git", None))\nktor.app.walk_remote("git://repo.example.com/org/project?ref=dev", "/project")\n```\n\n### Adding Local Directory\n\n```python\nktor.app.walk_local("/home/username/local-dir")\n```\n\n### Using Transformers\n\n```python\ndef remove_replicas(resources, r: "K8SResource"):\n if (r.group == "apps" and r.kind in ("StatefulSet", "Deployment")\n and "replicas" in r.manifest["spec"]):\n logger.warning("Resource %s in %s contains `replica` specification that will be removed. Use HPA!!!",\n r, r.source)\n del r.manifest["spec"]["replicas"]\n\n\nktor.k8s.add_transformer(remove_replicas)\n```\n',
27
27
  long_description_content_type = 'text/markdown',
28
28
  classifiers = [
29
- 'License :: OSI Approved :: Apache Software License',
30
29
  'Programming Language :: Python :: 3.9',
31
30
  'Programming Language :: Python :: 3.10',
32
31
  'Programming Language :: Python :: 3.11',
33
32
  'Programming Language :: Python :: 3.12',
34
33
  'Programming Language :: Python :: 3.13',
34
+ 'Programming Language :: Python :: 3.14',
35
35
  'Operating System :: MacOS :: MacOS X',
36
36
  'Operating System :: POSIX',
37
37
  'Operating System :: POSIX :: Linux',
@@ -52,7 +52,7 @@ if __name__ == '__main__':
52
52
  maintainer = 'Karellen, Inc., Arcadiy Ivanov',
53
53
  maintainer_email = 'supervisor@karellen.co,arcadiy@karellen.co',
54
54
 
55
- license = 'Apache License, Version 2.0',
55
+ license = 'Apache-2.0',
56
56
 
57
57
  url = 'https://github.com/karellen/kubernator',
58
58
  project_urls = {
@@ -89,7 +89,7 @@ if __name__ == '__main__':
89
89
  'openapi-schema-validator~=0.1',
90
90
  'openapi-spec-validator~=0.3',
91
91
  'platformdirs~=4.2',
92
- 'requests<=2.31.0'
92
+ 'requests>=2.31.0'
93
93
  ],
94
94
  dependency_links = [],
95
95
  zip_safe = True,