Nomad: Docker key labels with dot aren't supported in HCL 2. Nomad v1.0.1

Created on 20 Dec 2020  路  2Comments  路  Source: hashicorp/nomad

  • Nomad version: Nomad v1.0.1 (c9c68aa55a7275f22d2338f2df53e67ebfcb9238)
  • Operating system and Environment details: Kubuntu 20.04

Issue

Docker key labels with dot aren't supported in HCL 2.

Reproduction steps

Attempt 1:

Create a example.nomad and run nomad job plan example.nomad

job "example" {
  datacenters = ["dc1"]
  type = "service"

  group "portal" {
    count = 2

    task "portal" {
      driver = "docker"

      config {
        image = "nginx:alpine"
        label {
          traefik.enable = "true"
        }
        //        labels = [
        //          "traefik.enable=true"
        //        ]
//        label = {
//          traefik.enable = "true"
//        }
      }
    }
  }
}

Error

Error getting job struct: Failed to parse using HCL 2. Use the HCL 1 parser with `nomad run -hcl1`, or address the following issues:
example.nomad:14,11-18: Argument or block definition required; An argument or block definition is required here. To set an argument, use the equals sign "=" to introduce the argument value.

Attempt 2

Create a example.nomad and run nomad job plan example.nomad. Now run nomad job run example.nomad and check the log events

job "example" {
  datacenters = ["dc1"]
  type = "service"

  group "portal" {
    count = 2

    task "portal" {
      driver = "docker"

      config {
        image = "nginx:alpine"
//        label {
//          traefik.enable = "true"
//        }
        labels = [
          "traefik.enable=true"
        ]
//        label = {
//          traefik.enable = "true"
//        }
      }
    }
  }
}

Error

2 errors occurred: * failed to parse config: * Incorrect attribute value type: Inappropriate value for attribute "labels": element 0: map of string required. 

image

Attempt 3:

Create a example.nomad and run nomad job plan example.nomad. Now run nomad job run example.nomad. The container is started, but, as can seen in plan, no one label is applied.

job "example" {
  datacenters = ["dc1"]
  type = "service"

  group "portal" {
    count = 2

    task "portal" {
      driver = "docker"

      config {
        image = "nginx:alpine"
//        label {
//          traefik.enable = "true"
//        }
//        labels = [
//          "traefik.enable=true"
//        ]
        label = {
          traefik.enable = "true"
        }
      }
    }
  }
}

Docker inspect:

When I run docker inspect portal-<UUID>, traefik.enable isn't sent

"Labels": {
    "com.hashicorp.nomad.alloc_id": "f90f7b86-4299-78f0-d5ef-fc5b3fdfd53f",
    "maintainer": "NGINX Docker Maintainers <[email protected]>"
},

Notes

If you run nomad job plan -hcl1 example.nomad and nomad job run -hcl1 example.nomad, in the attempt 1 and attempt 3, they will works as expected.

Most helpful comment

Hi @SrMouraSilva . Sorry for the confusion there. Indeed, the syntax changed a little. We highlighted it in The HCL2 Backward Incompatibility section covers it a bit, and we'll aim to highlight it more.

As traefic.enable is not a valid identifier, the following block

label {
  traefik.enable = "true"
}

needs to be re-writtern as:

label = {
  "traefik.enable" = "true"
}

I've just tested the job with your job and it seems to have worked. Can you double check on your end too and report your finding.

All 2 comments

Hi @SrMouraSilva . Sorry for the confusion there. Indeed, the syntax changed a little. We highlighted it in The HCL2 Backward Incompatibility section covers it a bit, and we'll aim to highlight it more.

As traefic.enable is not a valid identifier, the following block

label {
  traefik.enable = "true"
}

needs to be re-writtern as:

label = {
  "traefik.enable" = "true"
}

I've just tested the job with your job and it seems to have worked. Can you double check on your end too and report your finding.

Hi @notnoop. Thanks fot the answer. It works!

Was this page helpful?
0 / 5 - 0 ratings