Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

421
Vistas
Kubernetes Jobspec Passing Json Args: Why Is This Invalid Yaml And How To Fix?

I am trying to run jobs that call python apps that take dictionaries as parameters.

For example, running it locally might look like this:

 python3 examples/test.py '{"school":"EFG", "standard": "2", "name": "abc", "city": "miami"}'

So, in my jobspec I am trying to do this:

command: ["/bin/bash","-c"]
args: ["python3 examples/test.py '{"school":"EFG", "standard": "2", "name": "abc", "city": "miami"}'"]

However, I get a yaml error:

error: error parsing job.yaml.tmpl: error converting YAML to JSON: yaml: line 18: could not find expected ':'

I see in yaml lint that it is not valid. The only way I have managed to pass yaml validation is to escape every single quote, which is not scalable for hundreds of jobs that users will be running

args: 
  - "python3 examples/test.py '{\"school\":\"hello\", \"standard\": \"5\"}'"

Why is this not valid yaml and how can I do this without needing to escape every single quote in a given dictionary a user passes in?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It's hard to replicate your setup without your code, however below examples should work for you. In Kubernetes Docs - Run a command in a shell you can find information, that all commands should be wrapped.

In some cases, you need your command to run in a shell. For example, your command might consist of several commands piped together, or it might be a shell script. To run your command in a shell, wrap it.

Below you have default syntax

command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]

I've changed a bit your command and verified on yamllint, all passed.

Examples with only /bin/bash in command:

command: 
  - /bin/bash
args: 
  - "-c"
  - "python3 examples/test.py '{\"school\":\"EFG\", \"standard\": \"2\", \"name\": \"abc\", \"city\": \"miami\"}'\"]"

or

command: ["/bin/bash"]
args: ["-c", "python3 examples/test.py", '{"school":"EFG", "standard": "2", "name": "abc", "city": "miami"}']

Examples with /bin/bash and -c in command:

command: 
  - /bin/bash
  - "-c"
args: 
  - "python3 examples/test.py"
  - "{\"school\":\"EFG\", \"standard\": \"2\", \"name\": \"abc\", \"city\": \"miami\"}"

or

command: ["/bin/bash", "-c"]
args: ["python3 examples/test.py", '{"school":"EFG", "standard": "2", "name": "abc", "city": "miami"}']

In addition, there was a question about running multiple kubernetes commands in spec. You can find it here.

Let me know if this worked for you.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda