diff --git a/app/k8s.py b/app/k8s.py new file mode 100755 index 0000000000000000000000000000000000000000..e922c8fc9e8e2e730b57be261c872b7cb203167d --- /dev/null +++ b/app/k8s.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +from kubernetes import client, config +from kubernetes.client.rest import ApiException +import logging + +logger = logging.getLogger(__name__) + +def get_opa_config(namespace="osdu-services", name="opa-config"): + # Configs can be set in Configuration class directly or using helper utility + config.load_kube_config() + v1 = client.CoreV1Api() + + pretty = True + try: + api_response = v1.read_namespaced_config_map(namespace=namespace, name=name, pretty=pretty) + except ApiException as err: + logger.error(f"Exception when calling CoreV1Api->list_namespaced_config_map: {err}") + return api_response.data["config"] + + +if __name__ == '__main__': + data_partition = 'osdu' + name = "opa-config" + r = get_opa_config(data_partition=data_partition, name=name) + if f"osdu/partition/{data_partition}" in r and f"bundle-{data_partition}.tar.gz" in r: + print(f"found '{data_partition}' in configmap {name}") + else: + print(f"not found '{data_partition}' in configmap {name}") \ No newline at end of file