# Buggy code
def _gen_master_def(image_name, model_file, argv, timestamp):
    master_yaml = """
apiVersion: v1
kind: Pod
metadata:
  name: elasticdl-master-{timestamp}
  labels:
    purpose: test-command
spec:
  containers:
  - name: elasticdl-master-{timestamp}
    image: {image_name}
    command: ["python"]
    args: [
        "-m", "elasticdl.master.main",
        "--worker_image", {image_name},
        "--model_file", "{m_file}"
    ]
    imagePullPolicy: IfNotPresent 
    env:
    - name: MY_POD_IP
      valueFrom:
        fieldRef:
          fieldPath: status.podIP
  restartPolicy: Never
""".format(
        m_file=_m_file_in_docker(model_file), image_name=image_name, timestamp=timestamp
    )

    master_def = yaml.safe_load(master_yaml)

    # Build master arguments
    master_def["spec"]["containers"][0]["args"].extend(argv)
    return master_def


# Traceback (yaml.scanner.ScannerError)
Traceback (most recent call last):
File "elasticdl/client/client.py", line 96, in <module>
main()
File "elasticdl/client/client.py", line 92, in main
_submit(image_name, args.model_file, argv, timestamp)
File "elasticdl/client/client.py", line 74, in _submit
master_def = _gen_master_def(image_name, model_file, argv, timestamp)
File "elasticdl/client/client.py", line 67, in _gen_master_def
master_def = yaml.safe_load(master_yaml)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/__init__.py", line 94, in safe_load
return load(stream, SafeLoader)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/__init__.py", line 72, in load
return loader.get_single_data()
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/constructor.py", line 35, in get_single_data
node = self.get_single_node()
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 36, in get_single_node
document = self.compose_document()
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 55, in compose_document
node = self.compose_node(None, None)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 84, in compose_node
node = self.compose_mapping_node(anchor)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 133, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 84, in compose_node
node = self.compose_mapping_node(anchor)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 133, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 82, in compose_node
node = self.compose_sequence_node(anchor)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 111, in compose_sequence_node
node.value.append(self.compose_node(node, index))
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 84, in compose_node
node = self.compose_mapping_node(anchor)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 133, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 82, in compose_node
node = self.compose_sequence_node(anchor)
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/composer.py", line 110, in compose_sequence_node
while not self.check_event(SequenceEndEvent):
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/parser.py", line 98, in check_event
self.current_event = self.state()
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/parser.py", line 486, in parse_flow_sequence_entry
if self.check_token(KeyToken):
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/scanner.py", line 116, in check_token
self.fetch_more_tokens()
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/scanner.py", line 252, in fetch_more_tokens
return self.fetch_plain()
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/scanner.py", line 676, in fetch_plain
self.tokens.append(self.scan_plain())
File "/usr/local/anaconda3/lib/python3.6/site-packages/yaml/scanner.py", line 1299, in scan_plain
"Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.")
yaml.scanner.ScannerError: while scanning a plain scalar
in "<unicode string>", line 15, column 27:
"--worker_image", elasticdl:dev_1558332476444,
^
found unexpected ':'
in "<unicode string>", line 15, column 36:
"--worker_image", elasticdl:dev_1558332476444,
^

# Fixed code
def _gen_master_def(image_name, model_file, argv, timestamp):
    master_yaml = """
apiVersion: v1
kind: Pod
metadata:
  name: "elasticdl-master-{timestamp}"
  labels:
    purpose: test-command
spec:
  containers:
  - name: "elasticdl-master-{timestamp}"
    image: "{image_name}"
    command: ["python"]
    args: [
        "-m", "elasticdl.master.main",
        "--worker_image", "{image_name}",
        "--model_file", "{m_file}"
    ]
    imagePullPolicy: IfNotPresent 
    env:
    - name: MY_POD_IP
      valueFrom:
        fieldRef:
          fieldPath: status.podIP
  restartPolicy: Never
""".format(
        m_file=_m_file_in_docker(model_file), image_name=image_name, timestamp=timestamp
    )

    master_def = yaml.safe_load(master_yaml)

    # Build master arguments
    master_def["spec"]["containers"][0]["args"].extend(argv)
    return master_def