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 when attribute is unset inside constraint stanza. #14488

Closed
chuckyz opened this issue Sep 8, 2022 · 2 comments
Closed

Panic when attribute is unset inside constraint stanza. #14488

chuckyz opened this issue Sep 8, 2022 · 2 comments
Assignees
Labels

Comments

@chuckyz
Copy link
Contributor

chuckyz commented Sep 8, 2022

Nomad version

v1.2.3

Operating system and Environment details

macohs big sir

Issue

Big ol' panic when trying to do nomad job plan on a job with a constraint stanza with an empty attribute value.

Reproduction steps

add

constraint {
  attribute =
  value = "foo"
  operator = "="
}

to any job

Expected Result

Something like Error: no attribute set in constraint stanza (line number)

Actual Result

panic: value is unknown

goroutine 1 [running]:
github.com/zclconf/go-cty/cty.Value.AsString({{{0x1045bc828, 0x1400011cbb9}}, {0x10405f7c0, 0x105763940}})
	github.com/zclconf/[email protected]/cty/value_ops.go:1257 +0x150
github.com/hashicorp/nomad/jobspec2.decodeConstraint.func1({0x1039a4f3d, 0x9})
	github.com/hashicorp/nomad/jobspec2/hcl_conversions.go:199 +0xc0
github.com/hashicorp/nomad/jobspec2.decodeConstraint({0x1045bb750, 0x140002f2150}, 0x14000389840, {0x103ee83a0, 0x1400083f440})
	github.com/hashicorp/nomad/jobspec2/hcl_conversions.go:202 +0x100
github.com/hashicorp/hcl/v2/gohcl.(*Decoder).decodeBodyToStruct(0x140004b8c50, {0x1045bb750, 0x140002f2150}, 0x14000389840, {0x10429c120, 0x1400083f440, 0x199})
	github.com/hashicorp/hcl/[email protected]/gohcl/decode.go:102 +0xa80
github.com/hashicorp/hcl/v2/gohcl.(*Decoder).decodeBodyToValue(0x140004b8c50, {0x1045bb750, 0x140002f2150}, 0x14000389840, {0x10429c120, 0x1400083f440, 0x199})
	github.com/hashicorp/hcl/[email protected]/gohcl/decode.go:92 +0xa4
github.com/hashicorp/hcl/v2/gohcl.(*Decoder).decodeBlockToValue(0x140004b8c50, 0x1400029dee0, 0x14000389840, {0x10429c120, 0x1400083f440, 0x199})
	github.com/hashicorp/hcl/[email protected]/gohcl/decode.go:365 +0x348
github.com/hashicorp/hcl/v2/gohcl.(*Decoder).decodeBodyToStruct(0x140004b8c50, {0x1045bb750, 0x140007f7920}, 0x14000389840, {0x1044e3e60, 0x14000622d00, 0x199})
	github.com/hashicorp/hcl/[email protected]/gohcl/decode.go:255 +0x284c
github.com/hashicorp/hcl/v2/gohcl.(*Decoder).decodeBodyToValue(0x140004b8c50, {0x1045bb750, 0x140007f7920}, 0x14000389840, {0x1044e3e60, 0x14000622d00, 0x199})
	github.com/hashicorp/hcl/[email protected]/gohcl/decode.go:92 +0xa4
github.com/hashicorp/hcl/v2/gohcl.(*Decoder).DecodeBody(0x140004b8c50, {0x1045bb750, 0x140007f7920}, 0x14000389840, {0x1043f3320, 0x14000622d00})
	github.com/hashicorp/hcl/[email protected]/gohcl/decode.go:85 +0x134
github.com/hashicorp/nomad/jobspec2.(*jobConfig).decodeJob(0x140007c4070, 0x14000834f60, 0x14000389840)
	github.com/hashicorp/nomad/jobspec2/types.config.go:283 +0x608
github.com/hashicorp/nomad/jobspec2.(*jobConfig).decodeBody(0x140007c4070, {0x1045bb9b8, 0x14000807c30})
	github.com/hashicorp/nomad/jobspec2/types.config.go:83 +0x5a0
github.com/hashicorp/nomad/jobspec2.decode(0x140007c4070)
	github.com/hashicorp/nomad/jobspec2/parse.go:99 +0xb8
github.com/hashicorp/nomad/jobspec2.ParseWithConfig(0x14000806210)
	github.com/hashicorp/nomad/jobspec2/parse.go:44 +0x118
github.com/hashicorp/nomad/command.(*JobGetter).ApiJobWithArgs(0x14000413ec0, {0x16da87487, 0x19}, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}, 0x1)
	github.com/hashicorp/nomad/command/helpers.go:455 +0x664
github.com/hashicorp/nomad/command.(*JobPlanCommand).Run(0x14000413e10, {0x1400003c0b0, 0x1, 0x1})
	github.com/hashicorp/nomad/command/job_plan.go:152 +0x3c4
github.com/mitchellh/cli.(*CLI).Run(0x1400046be00)
	github.com/mitchellh/[email protected]/cli.go:260 +0x5c4
main.RunCustom({0x1400003c090, 0x3, 0x3})
	github.com/hashicorp/nomad/main.go:116 +0x3a4
main.Run(...)
	github.com/hashicorp/nomad/main.go:86
main.main()
	github.com/hashicorp/nomad/main.go:82 +0x60

Job file (if appropriate)

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

  constraint {
    attribute =
    value = "foo"
    operator = "="
  }

  group "cache" {
    network {
      port "db" {
        to = 6379
      }
    }

    task "redis" {
      driver = "docker"

      config {
        image = "redis:3.2"

        ports = ["db"]
      }

      resources {
        cpu    = 500
        memory = 256
      }
    }
  }
}
@jrasell jrasell self-assigned this Sep 8, 2022
@jrasell
Copy link
Member

jrasell commented Sep 8, 2022

Hi @chuckyz and thanks for the report. I was able to reproduce this using v1.2.3, however, can confirm this bug has been fixed within v1.2.6 a later. I am not sure why the changelog entry is not correctly populated and will look into this, however, #13036 contained the fix.

@jrasell jrasell closed this as completed Sep 8, 2022
@github-actions
Copy link

github-actions bot commented Jan 7, 2023

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 Jan 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Development

No branches or pull requests

2 participants