Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in CLI during file parsing when using environment variables inside HCL templates #10333

Closed
the-maldridge opened this issue Apr 8, 2021 · 5 comments
Assignees
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/cli type/bug

Comments

@the-maldridge
Copy link

Nomad version

$ nomad version
Nomad v1.0.4 (a480eed0815c54612856d9115a34bb1d1a773e8c)

Operating system and Environment details

Void Linux on amd64.

Issue

Trying to run the provided job file causes a panic.

Reproduction steps

Load the file provided, run it, observe the panic.

Expected Result

No panic.

Actual Result

Nomad panics.

Job file (if appropriate)

job "redis" {
  type = "service"

  group "app" {
    network {
      mode = "bridge"
      port "redis" { to = 6379 }
    }

    service {
      name = "redis"
      port = "redis"
      check {
        type = "tcp"
        interval = "10s"
        timeout = "2s"
        address_mode = "host"
      }
    }

    task "redis" {
      driver = "docker"

      config {
        image = "redis:6-alpine"
        ports = ["redis"]
      }
    }

    task "memset" {
      driver = "docker"
      lifecycle {
        hook = "poststart"
      }
      config {
        image = "redis:6-alpine"
        entrypoint = ["/usr/local/bin/redis-cli"]
        args = [
          "-h", "${env["NOMAD_IP_app_redis"]}",
          "-p", "${env["NOMAD_PORT_app_redis"]}",
          "CONFIG SET maxmemory 285MB",
        ]
      }
    }
  }
}

Nomad Client logs (if appropriate)

$ nomad job plan redis.nomad 
panic: interface conversion: hcl.Traverser is hcl.TraverseIndex, not hcl.TraverseAttr

goroutine 1 [running]:
github.com/hashicorp/hcl/v2.Traversal.toStringValue(0xc000425660, 0x2, 0x2, 0x3, 0x4c81a00)
	/builddir/nomad-1.0.4/vendor/github.com/hashicorp/hcl/v2/traversal.go:140 +0x566
github.com/hashicorp/hcl/v2.Traversal.TraverseAbs(0xc000425660, 0x2, 0x2, 0xc0006931e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/builddir/nomad-1.0.4/vendor/github.com/hashicorp/hcl/v2/traversal.go:94 +0x9e5
github.com/hashicorp/hcl/v2/hclsyntax.(*ScopeTraversalExpr).Value(0xc0005207e0, 0xc0006931e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/builddir/nomad-1.0.4/vendor/github.com/hashicorp/hcl/v2/hclsyntax/expression.go:109 +0x65
github.com/hashicorp/hcl/v2/hclsyntax.(*TemplateWrapExpr).Value(0xc000216500, 0xc0006931e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/builddir/nomad-1.0.4/vendor/github.com/hashicorp/hcl/v2/hclsyntax/expression_template.go:224 +0x42
github.com/hashicorp/hcl/v2/hclsyntax.(*TupleConsExpr).Value(0xc000439680, 0xc0006931e0, 0xc000115fc0, 0xc00030176c, 0xc000680000, 0x419cfb, 0xc000115fc0, 0xc0004ff848, 0x10)
	/builddir/nomad-1.0.4/vendor/github.com/hashicorp/hcl/v2/hclsyntax/expression.go:712 +0xf0
github.com/hashicorp/nomad/jobspec2.decodeInterface(0x7fb1dc3f4480, 0xc000439680, 0xc0006931e0, 0x2902d01, 0x27dfb00, 0xc0000d1680, 0x2a5eda0, 0xc000115fc0)
	/builddir/nomad-1.0.4/jobspec2/parse_map.go:65 +0x59
github.com/hashicorp/nomad/jobspec2.(*walker).Map(0xc000693200, 0x2af37a0, 0xc000303a58, 0x195, 0xc000693200, 0x2b84201)
	/builddir/nomad-1.0.4/jobspec2/parse_map.go:52 +0x20a
github.com/mitchellh/reflectwalk.walkMap(0x2af37a0, 0xc000303a58, 0x195, 0x2b5ce20, 0xc000693200, 0x3727f00, 0x2af37a0)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:205 +0x586
github.com/mitchellh/reflectwalk.walk(0x2af37a0, 0xc000303a58, 0x195, 0x2b5ce20, 0xc000693200, 0x0, 0x2af37a0)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:182 +0x43a
github.com/mitchellh/reflectwalk.walkStruct(0x319d880, 0xc000303a20, 0x199, 0x2b5ce20, 0xc000693200, 0x100, 0x0)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:386 +0x3ed
github.com/mitchellh/reflectwalk.walk(0x2e776e0, 0xc00007f538, 0x196, 0x2b5ce20, 0xc000693200, 0xc00007f500, 0x196)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:188 +0x4e5
github.com/mitchellh/reflectwalk.walkSlice(0x2879680, 0xc000360130, 0x197, 0x2b5ce20, 0xc000693200, 0x3727f00, 0x2879680)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:284 +0x211
github.com/mitchellh/reflectwalk.walk(0x2879680, 0xc000360130, 0x197, 0x2b5ce20, 0xc000693200, 0x0, 0x2879680)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:185 +0x3ab
github.com/mitchellh/reflectwalk.walkStruct(0x31757c0, 0xc0003600f0, 0x199, 0x2b5ce20, 0xc000693200, 0x100, 0x412590)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:386 +0x3ed
github.com/mitchellh/reflectwalk.walk(0x2e777a0, 0xc000208918, 0x196, 0x2b5ce20, 0xc000693200, 0xc000208900, 0x196)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:188 +0x4e5
github.com/mitchellh/reflectwalk.walkSlice(0x2879780, 0xc000102800, 0x197, 0x2b5ce20, 0xc000693200, 0x3727f00, 0x2879780)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:284 +0x211
github.com/mitchellh/reflectwalk.walk(0x2879780, 0xc000102800, 0x197, 0x2b5ce20, 0xc000693200, 0x0, 0x2879780)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:185 +0x3ab
github.com/mitchellh/reflectwalk.walkStruct(0x31bc4a0, 0xc000102780, 0x199, 0x2b5ce20, 0xc000693200, 0x100, 0x0)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:386 +0x3ed
github.com/mitchellh/reflectwalk.walk(0x27b6640, 0xc00044a390, 0x16, 0x2b5ce20, 0xc000693200, 0x7464fc7ce3d82500, 0x0)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:188 +0x4e5
github.com/mitchellh/reflectwalk.Walk(0x27b6640, 0xc00044a390, 0x2b5ce20, 0xc000693200, 0x2af37a0, 0x36e8280)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:92 +0x18f
github.com/hashicorp/nomad/jobspec2.decodeMapInterfaceType(0x27b6640, 0xc00044a390, 0xc0006931e0, 0x0, 0x0, 0x0)
	/builddir/nomad-1.0.4/jobspec2/parse_map.go:21 +0x7f
github.com/hashicorp/nomad/jobspec2.decode(0xc00044a380, 0xc00044a380, 0x31f9415)
	/builddir/nomad-1.0.4/jobspec2/parse.go:108 +0x71b
github.com/hashicorp/nomad/jobspec2.ParseWithConfig(0xc0004fc4d0, 0xc0004fc4d0, 0x2b, 0xc000208c40)
	/builddir/nomad-1.0.4/jobspec2/parse.go:44 +0xa8
github.com/hashicorp/nomad/command.(*JobGetter).ApiJobWithArgs(0xc0003b4800, 0x7ffc73f8848e, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/builddir/nomad-1.0.4/command/helpers.go:455 +0x41f
github.com/hashicorp/nomad/command.(*JobPlanCommand).Run(0xc0003b4750, 0xc00004e0f0, 0x1, 0x1, 0xc0001143b0)
	/builddir/nomad-1.0.4/command/job_plan.go:145 +0x3e5
github.com/mitchellh/cli.(*CLI).Run(0xc0003e4000, 0xc0003e4000, 0xc000204ec0, 0x37)
	/builddir/nomad-1.0.4/vendor/github.com/mitchellh/cli/cli.go:260 +0x1cf
main.RunCustom(0xc00004e0d0, 0x3, 0x3, 0xc00005a0b8)
	/builddir/nomad-1.0.4/main.go:142 +0x4a5
main.Run(...)
	/builddir/nomad-1.0.4/main.go:87
main.main()
	/builddir/nomad-1.0.4/main.go:83 +0x65
@notnoop
Copy link
Contributor

notnoop commented Apr 8, 2021

Thanks @the-maldridge for reporting it. I just pushed a fix for this panic in #10326, which should be out in the next release . For now, I'd suggest using --hcl1 flag (e.g. nomad job run --hcl1 file.hcl) to fallback to using the hcl1 parser.

@the-maldridge
Copy link
Author

slick! I think it might be worth creating a patch to the documentation as well until the next release. This page is what led me to believe that this syntax would work.

@notnoop
Copy link
Contributor

notnoop commented Apr 8, 2021

Good points. Will update the upgrade guide too.

@shoenig shoenig added stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/cli labels Apr 9, 2021
@shoenig shoenig added this to Needs Triage in Nomad - Community Issues Triage via automation Apr 9, 2021
@shoenig shoenig moved this from Needs Triage to In Progress in Nomad - Community Issues Triage Apr 9, 2021
@the-maldridge
Copy link
Author

This was released as part of 1.1.0 iirc.

Nomad - Community Issues Triage automation moved this from In Progress to Done Aug 16, 2021
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/cli type/bug
Projects
None yet
Development

No branches or pull requests

3 participants