application.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. import os
  10. import subprocess
  11. from materialize import ui
  12. from materialize.cloudtest import DEFAULT_K8S_CLUSTER_NAME, DEFAULT_K8S_CONTEXT_NAME
  13. from materialize.cloudtest.k8s.api.k8s_resource import K8sResource
  14. from materialize.cloudtest.util.common import log_subprocess_error
  15. class Application:
  16. resources: list[K8sResource]
  17. images: list[str]
  18. release_mode: bool
  19. aws_region: str | None
  20. def __init__(self) -> None:
  21. pass
  22. def create_resources(self) -> None:
  23. self.acquire_images()
  24. for resource in self.resources:
  25. resource.create()
  26. def coverage_mode(self) -> bool:
  27. return ui.env_is_truthy("CI_COVERAGE_ENABLED")
  28. def sanitizer_mode(self) -> str:
  29. return os.getenv("CI_SANITIZER", "none")
  30. def bazel(self) -> bool:
  31. return ui.env_is_truthy("CI_BAZEL_BUILD")
  32. def bazel_remote_cache(self) -> str | None:
  33. return os.getenv("CI_BAZEL_REMOTE_CACHE")
  34. def bazel_lto(self) -> bool:
  35. return ui.env_is_truthy("CI_BAZEL_LTO")
  36. def acquire_images(self) -> None:
  37. raise NotImplementedError
  38. def kubectl(self, *args: str, namespace: str | None = None) -> str:
  39. try:
  40. cmd = ["kubectl", "--context", self.context(), *args]
  41. if namespace is not None:
  42. cmd.extend(["--namespace", namespace])
  43. return subprocess.check_output(cmd, text=True)
  44. except subprocess.CalledProcessError as e:
  45. log_subprocess_error(e)
  46. raise e
  47. def context(self) -> str:
  48. return DEFAULT_K8S_CONTEXT_NAME
  49. def cluster_name(self) -> str:
  50. return DEFAULT_K8S_CLUSTER_NAME