k8s_config_map.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 V1ConfigMap
  10. from kubernetes.client.exceptions import ApiException
  11. from materialize.cloudtest.k8s.api.k8s_resource import K8sResource
  12. class K8sConfigMap(K8sResource):
  13. config_map: V1ConfigMap
  14. def kind(self) -> str:
  15. return "configmap"
  16. def create(self) -> None:
  17. core_v1_api = self.api()
  18. # kubectl delete all -all does not clean up configmaps
  19. try:
  20. assert self.config_map.metadata is not None
  21. assert self.config_map.metadata.name is not None
  22. core_v1_api.delete_namespaced_config_map(
  23. name=self.config_map.metadata.name, namespace=self.namespace()
  24. )
  25. except ApiException:
  26. pass
  27. core_v1_api.create_namespaced_config_map(
  28. body=self.config_map, namespace=self.namespace()
  29. )