k8s_pod.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. from kubernetes.client import V1Pod
  10. from materialize.cloudtest import DEFAULT_K8S_NAMESPACE
  11. from materialize.cloudtest.k8s.api.k8s_resource import K8sResource
  12. class K8sPod(K8sResource):
  13. pod: V1Pod
  14. def __init__(self, namespace: str = DEFAULT_K8S_NAMESPACE):
  15. super().__init__(namespace)
  16. def kind(self) -> str:
  17. return "pod"
  18. def create(self) -> None:
  19. core_v1_api = self.api()
  20. core_v1_api.create_namespaced_pod(body=self.pod, namespace=self.namespace())
  21. def name(self) -> str:
  22. assert self.pod.metadata is not None
  23. assert self.pod.metadata.name is not None
  24. return self.pod.metadata.name
  25. def copy(self, source: str, destination: str) -> None:
  26. self.kubectl("cp", source, f"{self.name()}:{destination}")
  27. def delete(self, path: str) -> None:
  28. self.kubectl("exec", self.name(), "--", "rm", path)