We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
submit master pod using k8s python client instead of kubectl 
use k8s python client to submit master pod instead of using the command below
`os.system('kubectl run ...')`

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `elasticdl/client/client.py`
Content:
```
1 import os
2 import inspect
3 import shutil
4 import time
5 import getpass
6 from string import Template
7 import docker
8 
9 
10 def run(model_class, train_data_dir=None, 
11         num_epoch=1, minibatch_size=10, 
12         record_per_task=100, num_worker=1, grads_to_wait=2):
13     m_path, m_file = _getModelFile()
14     m_file_in_docker = "/model/" + m_file 
15     timestamp = int(round(time.time() * 1000))
16     _build_docker_image(m_path, m_file, m_file_in_docker, timestamp)
17     yaml_file = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, 
18             num_epoch=num_epoch, minibatch_size=minibatch_size, 
19             record_per_task=record_per_task, num_worker=num_worker, 
20             grads_to_wait=grads_to_wait, timestamp=timestamp)
21     _submit(yaml_file)
22 
23 def _getModelFile():
24     m_file = inspect.currentframe().f_back.f_back.f_code.co_filename
25     m_path = os.path.abspath(os.path.dirname(m_file))
26     return m_path, m_file
27 
28 def _build_docker_image(m_path, m_file, m_file_in_docker, timestamp):
29     d_path = os.path.abspath(os.path.dirname(
30         inspect.currentframe().f_back.f_code.co_filename))
31     new_dfile = m_path + "/Dockerfile"
32     shutil.copyfile(d_path + "/../Dockerfile.dev", new_dfile)
33 
34     with open(new_dfile, 'a') as df:
35         df.write("COPY " + m_file + " " + m_file_in_docker)
36     client = docker.APIClient(base_url='unix://var/run/docker.sock') 
37     for line in client.build(dockerfile='Dockerfile', path='.', tag='elasticdl:dev_' + str(timestamp)):
38         print(str(line, encoding = "utf-8"))
39 
40     # TODO: upload docker image to docker hub.
41 
42 def _generate_yaml(m_file, m_class,
43                    train_data_dir=None, num_epoch=1,
44                    minibatch_size=10, record_per_task=100, 
45                    num_worker=1, grads_to_wait=2, timestamp=1):
46   YAML_TEMPLATE = """
47   apiVersion: v1
48   kind: Pod
49   metadata:
50     name: elasticdl-master-$timestamp
51     labels:
52       purpose: test-command
53   spec:
54     containers:
55     - name: elasticdl-master-$timestamp
56       image: elasticdl:dev_$timestamp
57       command: ["python"]
58       args: ["-m", "elasticdl.master.main",
59            "--model-file", "$m_file",
60            "--num_worker", "$num_worker",
61            "--worker_image", "elasticdl:dev_$timestamp",
62            "--job_name", "elasticdl-$timestamp",
63            "--model-class", "$m_class",
64            "--train_data_dir", "$train_data_dir",
65            "--num_epoch", "$num_epoch",
66            "--grads_to_wait", "$grads_to_wait",
67            "--minibatch_size", "$minibatch_size",
68            "--record_per_task", "$record_per_task"]
69       imagePullPolicy: Never
70       env:
71       - name: MY_POD_IP
72         valueFrom:
73           fieldRef:
74             fieldPath: status.podIP
75     restartPolicy: Never
76   """
77   t = Template(YAML_TEMPLATE)
78   yaml_file = 'job_desc.yaml'
79   with open(yaml_file, "w") as yaml:
80       yaml.write(t.substitute(m_file=m_file, m_class=m_class, 
81           train_data_dir=train_data_dir, 
82           timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,
83           minibatch_size=minibatch_size, record_per_task=record_per_task,
84           user=getpass.getuser(), grads_to_wait=grads_to_wait))
85   return yaml_file
86 
87 def _submit(yaml_file):
88     os.system('kubectl create -f ' + yaml_file)
89
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/elasticdl/client/client.py b/elasticdl/client/client.py
--- a/elasticdl/client/client.py
+++ b/elasticdl/client/client.py
@@ -5,6 +5,9 @@
 import getpass
 from string import Template
 import docker
+import yaml
+from kubernetes.client.apis import core_v1_api
+from kubernetes import config
 
 
 def run(model_class, train_data_dir=None, 
@@ -14,11 +17,11 @@
     m_file_in_docker = "/model/" + m_file 
     timestamp = int(round(time.time() * 1000))
     _build_docker_image(m_path, m_file, m_file_in_docker, timestamp)
-    yaml_file = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, 
+    yaml_content = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, 
             num_epoch=num_epoch, minibatch_size=minibatch_size, 
             record_per_task=record_per_task, num_worker=num_worker, 
             grads_to_wait=grads_to_wait, timestamp=timestamp)
-    _submit(yaml_file)
+    _submit(yaml_content)
 
 def _getModelFile():
     m_file = inspect.currentframe().f_back.f_back.f_code.co_filename
@@ -75,14 +78,15 @@
     restartPolicy: Never
   """
   t = Template(YAML_TEMPLATE)
-  yaml_file = 'job_desc.yaml'
-  with open(yaml_file, "w") as yaml:
-      yaml.write(t.substitute(m_file=m_file, m_class=m_class, 
-          train_data_dir=train_data_dir, 
-          timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,
-          minibatch_size=minibatch_size, record_per_task=record_per_task,
-          user=getpass.getuser(), grads_to_wait=grads_to_wait))
-  return yaml_file
+  return t.substitute(m_file=m_file, m_class=m_class, 
+             train_data_dir=train_data_dir, 
+             timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,
+             minibatch_size=minibatch_size, record_per_task=record_per_task,
+             user=getpass.getuser(), grads_to_wait=grads_to_wait)
 
-def _submit(yaml_file):
-    os.system('kubectl create -f ' + yaml_file)
+def _submit(yaml_content):
+    config.load_kube_config()
+    pod_desc = yaml.safe_load(yaml_content)
+    api = core_v1_api.CoreV1Api()
+    resp = api.create_namespaced_pod(body=pod_desc, namespace='default')
+    print("Pod created. status='%s'" % str(resp.status))

{"golden_diff": "diff --git a/elasticdl/client/client.py b/elasticdl/client/client.py\n--- a/elasticdl/client/client.py\n+++ b/elasticdl/client/client.py\n@@ -5,6 +5,9 @@\n import getpass\n from string import Template\n import docker\n+import yaml\n+from kubernetes.client.apis import core_v1_api\n+from kubernetes import config\n \n \n def run(model_class, train_data_dir=None, \n@@ -14,11 +17,11 @@\n     m_file_in_docker = \"/model/\" + m_file \n     timestamp = int(round(time.time() * 1000))\n     _build_docker_image(m_path, m_file, m_file_in_docker, timestamp)\n-    yaml_file = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, \n+    yaml_content = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, \n             num_epoch=num_epoch, minibatch_size=minibatch_size, \n             record_per_task=record_per_task, num_worker=num_worker, \n             grads_to_wait=grads_to_wait, timestamp=timestamp)\n-    _submit(yaml_file)\n+    _submit(yaml_content)\n \n def _getModelFile():\n     m_file = inspect.currentframe().f_back.f_back.f_code.co_filename\n@@ -75,14 +78,15 @@\n     restartPolicy: Never\n   \"\"\"\n   t = Template(YAML_TEMPLATE)\n-  yaml_file = 'job_desc.yaml'\n-  with open(yaml_file, \"w\") as yaml:\n-      yaml.write(t.substitute(m_file=m_file, m_class=m_class, \n-          train_data_dir=train_data_dir, \n-          timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,\n-          minibatch_size=minibatch_size, record_per_task=record_per_task,\n-          user=getpass.getuser(), grads_to_wait=grads_to_wait))\n-  return yaml_file\n+  return t.substitute(m_file=m_file, m_class=m_class, \n+             train_data_dir=train_data_dir, \n+             timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,\n+             minibatch_size=minibatch_size, record_per_task=record_per_task,\n+             user=getpass.getuser(), grads_to_wait=grads_to_wait)\n \n-def _submit(yaml_file):\n-    os.system('kubectl create -f ' + yaml_file)\n+def _submit(yaml_content):\n+    config.load_kube_config()\n+    pod_desc = yaml.safe_load(yaml_content)\n+    api = core_v1_api.CoreV1Api()\n+    resp = api.create_namespaced_pod(body=pod_desc, namespace='default')\n+    print(\"Pod created. status='%s'\" % str(resp.status))\n", "issue": "submit master pod using k8s python client instead of kubectl \nuse k8s python client to submit master pod instead of using the command below\r\n`os.system('kubectl run ...')`\n", "before_files": [{"content": "import os\nimport inspect\nimport shutil\nimport time\nimport getpass\nfrom string import Template\nimport docker\n\n\ndef run(model_class, train_data_dir=None, \n        num_epoch=1, minibatch_size=10, \n        record_per_task=100, num_worker=1, grads_to_wait=2):\n    m_path, m_file = _getModelFile()\n    m_file_in_docker = \"/model/\" + m_file \n    timestamp = int(round(time.time() * 1000))\n    _build_docker_image(m_path, m_file, m_file_in_docker, timestamp)\n    yaml_file = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, \n            num_epoch=num_epoch, minibatch_size=minibatch_size, \n            record_per_task=record_per_task, num_worker=num_worker, \n            grads_to_wait=grads_to_wait, timestamp=timestamp)\n    _submit(yaml_file)\n\ndef _getModelFile():\n    m_file = inspect.currentframe().f_back.f_back.f_code.co_filename\n    m_path = os.path.abspath(os.path.dirname(m_file))\n    return m_path, m_file\n\ndef _build_docker_image(m_path, m_file, m_file_in_docker, timestamp):\n    d_path = os.path.abspath(os.path.dirname(\n        inspect.currentframe().f_back.f_code.co_filename))\n    new_dfile = m_path + \"/Dockerfile\"\n    shutil.copyfile(d_path + \"/../Dockerfile.dev\", new_dfile)\n\n    with open(new_dfile, 'a') as df:\n        df.write(\"COPY \" + m_file + \" \" + m_file_in_docker)\n    client = docker.APIClient(base_url='unix://var/run/docker.sock') \n    for line in client.build(dockerfile='Dockerfile', path='.', tag='elasticdl:dev_' + str(timestamp)):\n        print(str(line, encoding = \"utf-8\"))\n\n    # TODO: upload docker image to docker hub.\n\ndef _generate_yaml(m_file, m_class,\n                   train_data_dir=None, num_epoch=1,\n                   minibatch_size=10, record_per_task=100, \n                   num_worker=1, grads_to_wait=2, timestamp=1):\n  YAML_TEMPLATE = \"\"\"\n  apiVersion: v1\n  kind: Pod\n  metadata:\n    name: elasticdl-master-$timestamp\n    labels:\n      purpose: test-command\n  spec:\n    containers:\n    - name: elasticdl-master-$timestamp\n      image: elasticdl:dev_$timestamp\n      command: [\"python\"]\n      args: [\"-m\", \"elasticdl.master.main\",\n           \"--model-file\", \"$m_file\",\n           \"--num_worker\", \"$num_worker\",\n           \"--worker_image\", \"elasticdl:dev_$timestamp\",\n           \"--job_name\", \"elasticdl-$timestamp\",\n           \"--model-class\", \"$m_class\",\n           \"--train_data_dir\", \"$train_data_dir\",\n           \"--num_epoch\", \"$num_epoch\",\n           \"--grads_to_wait\", \"$grads_to_wait\",\n           \"--minibatch_size\", \"$minibatch_size\",\n           \"--record_per_task\", \"$record_per_task\"]\n      imagePullPolicy: Never\n      env:\n      - name: MY_POD_IP\n        valueFrom:\n          fieldRef:\n            fieldPath: status.podIP\n    restartPolicy: Never\n  \"\"\"\n  t = Template(YAML_TEMPLATE)\n  yaml_file = 'job_desc.yaml'\n  with open(yaml_file, \"w\") as yaml:\n      yaml.write(t.substitute(m_file=m_file, m_class=m_class, \n          train_data_dir=train_data_dir, \n          timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,\n          minibatch_size=minibatch_size, record_per_task=record_per_task,\n          user=getpass.getuser(), grads_to_wait=grads_to_wait))\n  return yaml_file\n\ndef _submit(yaml_file):\n    os.system('kubectl create -f ' + yaml_file)\n", "path": "elasticdl/client/client.py"}], "after_files": [{"content": "import os\nimport inspect\nimport shutil\nimport time\nimport getpass\nfrom string import Template\nimport docker\nimport yaml\nfrom kubernetes.client.apis import core_v1_api\nfrom kubernetes import config\n\n\ndef run(model_class, train_data_dir=None, \n        num_epoch=1, minibatch_size=10, \n        record_per_task=100, num_worker=1, grads_to_wait=2):\n    m_path, m_file = _getModelFile()\n    m_file_in_docker = \"/model/\" + m_file \n    timestamp = int(round(time.time() * 1000))\n    _build_docker_image(m_path, m_file, m_file_in_docker, timestamp)\n    yaml_content = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, \n            num_epoch=num_epoch, minibatch_size=minibatch_size, \n            record_per_task=record_per_task, num_worker=num_worker, \n            grads_to_wait=grads_to_wait, timestamp=timestamp)\n    _submit(yaml_content)\n\ndef _getModelFile():\n    m_file = inspect.currentframe().f_back.f_back.f_code.co_filename\n    m_path = os.path.abspath(os.path.dirname(m_file))\n    return m_path, m_file\n\ndef _build_docker_image(m_path, m_file, m_file_in_docker, timestamp):\n    d_path = os.path.abspath(os.path.dirname(\n        inspect.currentframe().f_back.f_code.co_filename))\n    new_dfile = m_path + \"/Dockerfile\"\n    shutil.copyfile(d_path + \"/../Dockerfile.dev\", new_dfile)\n\n    with open(new_dfile, 'a') as df:\n        df.write(\"COPY \" + m_file + \" \" + m_file_in_docker)\n    client = docker.APIClient(base_url='unix://var/run/docker.sock') \n    for line in client.build(dockerfile='Dockerfile', path='.', tag='elasticdl:dev_' + str(timestamp)):\n        print(str(line, encoding = \"utf-8\"))\n\n    # TODO: upload docker image to docker hub.\n\ndef _generate_yaml(m_file, m_class,\n                   train_data_dir=None, num_epoch=1,\n                   minibatch_size=10, record_per_task=100, \n                   num_worker=1, grads_to_wait=2, timestamp=1):\n  YAML_TEMPLATE = \"\"\"\n  apiVersion: v1\n  kind: Pod\n  metadata:\n    name: elasticdl-master-$timestamp\n    labels:\n      purpose: test-command\n  spec:\n    containers:\n    - name: elasticdl-master-$timestamp\n      image: elasticdl:dev_$timestamp\n      command: [\"python\"]\n      args: [\"-m\", \"elasticdl.master.main\",\n           \"--model-file\", \"$m_file\",\n           \"--num_worker\", \"$num_worker\",\n           \"--worker_image\", \"elasticdl:dev_$timestamp\",\n           \"--job_name\", \"elasticdl-$timestamp\",\n           \"--model-class\", \"$m_class\",\n           \"--train_data_dir\", \"$train_data_dir\",\n           \"--num_epoch\", \"$num_epoch\",\n           \"--grads_to_wait\", \"$grads_to_wait\",\n           \"--minibatch_size\", \"$minibatch_size\",\n           \"--record_per_task\", \"$record_per_task\"]\n      imagePullPolicy: Never\n      env:\n      - name: MY_POD_IP\n        valueFrom:\n          fieldRef:\n            fieldPath: status.podIP\n    restartPolicy: Never\n  \"\"\"\n  t = Template(YAML_TEMPLATE)\n  return t.substitute(m_file=m_file, m_class=m_class, \n             train_data_dir=train_data_dir, \n             timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,\n             minibatch_size=minibatch_size, record_per_task=record_per_task,\n             user=getpass.getuser(), grads_to_wait=grads_to_wait)\n\ndef _submit(yaml_content):\n    config.load_kube_config()\n    pod_desc = yaml.safe_load(yaml_content)\n    api = core_v1_api.CoreV1Api()\n    resp = api.create_namespaced_pod(body=pod_desc, namespace='default')\n    print(\"Pod created. status='%s'\" % str(resp.status))\n", "path": "elasticdl/client/client.py"}]}