<commit_before>"""
utilities routines associated with Kubernetes python client

"""
import os
import six
import yaml
from pandaharvester.harvesterconfig import harvester_config
from pandaharvester.harvestercore.core_utils import SingletonWithID
from kubernetes import client, config
from kubernetes.client.rest import ApiException

NAMESPACE = harvester_config.k8s.NAMESPACE

class k8s_Client(six.with_metaclass(SingletonWithID, object)):

    def __init__(self):
        config.load_kube_config()
        self.corev1 = client.CoreV1Api()
        self.batchv1 = client.BatchV1Api()
        self.deletev1 = client.V1DeleteOptions(propagation_policy='Background')

    def create_job_from_yaml(self, yaml_file, workerID, cert):
        with open(os.path.join(os.path.dirname(__file__), yaml_file)) as f:
            job = yaml.load(f)
        job['metadata']['name'] = job['metadata']['name'] + "-" + workerID
        job_name = job['metadata']['name']

        for i in range(len(job['spec']['template']['spec']['containers'])):
            proxy_var = job['spec']['template']['spec']['containers'][i]['env']
            proxy_var.append({'name': 'proxyContent', 'value': self.set_proxy(cert)})
            proxy_var.append({'name': 'workerID', 'value': workerID})
            proxy_var.append({'name': 'logs_frontend_w', 'value': harvester_config.pandacon.pandaCacheURL_W})
            proxy_var.append({'name': 'logs_frontend_r', 'value': harvester_config.pandacon.pandaCacheURL_R})


        rsp = self.batchv1.create_namespaced_job(body=job, namespace=NAMESPACE)
        return job_name<commit_msg>Revised yaml_file read method<commit_after>"""
utilities routines associated with Kubernetes python client

"""
import os
import six
import yaml
from pandaharvester.harvesterconfig import harvester_config
from pandaharvester.harvestercore.core_utils import SingletonWithID
from kubernetes import client, config
from kubernetes.client.rest import ApiException

NAMESPACE = harvester_config.k8s.NAMESPACE

class k8s_Client(six.with_metaclass(SingletonWithID, object)):

    def __init__(self):
        config.load_kube_config()
        self.corev1 = client.CoreV1Api()
        self.batchv1 = client.BatchV1Api()
        self.deletev1 = client.V1DeleteOptions(propagation_policy='Background')

    def create_job_from_yaml(self, yaml_file, workerID, cert):
        with open(yaml_file) as f:
            job = yaml.load(f)
        job['metadata']['name'] = job['metadata']['name'] + "-" + workerID
        job_name = job['metadata']['name']

        for i in range(len(job['spec']['template']['spec']['containers'])):
            proxy_var = job['spec']['template']['spec']['containers'][i]['env']
            proxy_var.append({'name': 'proxyContent', 'value': self.set_proxy(cert)})
            proxy_var.append({'name': 'workerID', 'value': workerID})
            proxy_var.append({'name': 'logs_frontend_w', 'value': harvester_config.pandacon.pandaCacheURL_W})
            proxy_var.append({'name': 'logs_frontend_r', 'value': harvester_config.pandacon.pandaCacheURL_R})


        rsp = self.batchv1.create_namespaced_job(body=job, namespace=NAMESPACE)
        return job_name
{'fraction_non_alphanumeric': 0.13377400062952471, 'fraction_numerical': 0.0056657223796034, 'mean_word_length': 4.287853577371048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1999126', 'n_tokens_mistral': 1002, 'n_tokens_neox': 969, 'n_words': 179}