k8s_secret.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 V1Secret
  10. from kubernetes.client.exceptions import ApiException
  11. from materialize.cloudtest import DEFAULT_K8S_NAMESPACE
  12. from materialize.cloudtest.k8s.api.k8s_resource import K8sResource
  13. class K8sSecret(K8sResource):
  14. secret = V1Secret
  15. def __init__(self, namespace: str = DEFAULT_K8S_NAMESPACE):
  16. super().__init__(namespace)
  17. def kind(self) -> str:
  18. return "secret"
  19. # kubectl delete all -all does not clean up secrets
  20. def create(self) -> None:
  21. core_v1_api = self.api()
  22. try:
  23. assert self.secret.metadata is not None
  24. assert self.secret.metadata.name is not None
  25. core_v1_api.delete_namespaced_secret(
  26. name=self.secret.metadata.name, namespace=self.namespace()
  27. )
  28. except ApiException:
  29. pass
  30. core_v1_api.create_namespaced_secret(
  31. body=self.secret, namespace=self.namespace() # type: ignore
  32. )