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

Validation error when submitting task with template.change_mode = "script" #14478

Closed
RobbieFernandez opened this issue Sep 7, 2022 · 3 comments · Fixed by hashicorp/nomad-pack#288

Comments

@RobbieFernandez
Copy link

Nomad version

Output from nomad version
Nomad v1.3.5 (1359c25)

I am submitting the job via nomad-pack:
Nomad Pack v0.0.1-techpreview.3 (3b4163b)

Operating system and Environment details

Ubuntu 22.04 LTS

Issue

I'm attempting to submit a Nomad task where a template generates an nginx config file. I'm trying to use the change_mode = "script" and change_script:

        data = <<-EOH
          upstream nextjs {
            {{ range nomadService "nextjs" }}
            server {{ .Address }}:{{ .Port }};
            {{- end }}
          }

          server {
            server_name _;
            listen 80;
            location / {
              proxy_pass http://nextjs;
            }
          }
        EOH

        destination = "local/nginx.conf"
        change_mode = "script"
        change_script {
          command       = "/usr/sbin/nginx"
          args          = ["-s", "reload"]
          timeout       = "5s"
          fail_on_error = true
        }
      }

I am getting the following error complaining that change_script must be set, which as you can see above it is:

  Job 'afid-backend' in pack deployment 'afid' registered successfully
! Failed To Register Job

	Error:   1 error occurred:
	* Task group nextjs-balancer validation failed: 1 error occurred:
	* Task nextjs-balancer validation failed: 1 error occurred:
	* Template 1 validation failed: 1 error occurred:
	* must specify change script configuration value when change mode is script








	Type:    *v1.APIError
	Context: 
	         - Registry Name: <<local folder>>
	         - Pack Name: afid
	         - Pack Ref: <<none>>
	         - Pack Path: /home/robbie/Projects/afid-deploy/nomad/packs/afid
	         - Deployment Name: afid
	         - Template Name: afid/templates/afid-frontend.nomad.tpl
	         - Job Name: afid-frontend

I'm submitting the job with nomad-pack, so I'm not sure if that could be causing any issues too. Happy to move the issue to the nomad-pack repo if that is the case. I am also not sure if this is related to this issue: #14367 but it seems that should be fixed in the version of Nomad I'm using.

Setting the change_mode to "restart" does work.

Reproduction steps

Submit job with template change_mode "script", and a change_script set (possibly only through nomad-pack?)

Expected Result

Job should be validated and sent correctly.

Actual Result

A validation error is raised.

Job file (if appropriate)

job "afid-frontend" {
  datacenters = ["dc1"]

  group "nextjs" {
    count = [[ .afid.resources.nextjs.count ]]

    network {
      mode = "bridge"

      port "nextjs" {
        to = 3000
      }
    }

    service {
      name     = "nextjs"
      port     = "nextjs"
      provider = "nomad"
    }

    task "nextjs" {
      template {
        data = <<-EOH
        {{$allocID := env "NOMAD_ALLOC_ID" -}}
        {{range nomadService 1 $allocID "afid-web"}}
        APP_URL=http://{{.Address}}:{{.Port}}
        {{- end}}
        EOH

        destination = "local/nextjs.env"
        env         = true
        change_mode = "restart"
      }

      driver = "docker"

      config {
        image = "privaterepo/image" # (Redacted for this issue)
        ports = ["nextjs"]
      }

      resources {
        memory = [[ .afid.resources.nextjs.memory ]]
        cpu    = [[ .afid.resources.nextjs.cpu ]]
      }
    }
  }

  group "nextjs-balancer" {
    count = 1

    network {
      mode = "bridge"

      port "http" {
        to = 80
      }
    }

    service {
      name     = "nextjs-balancer"
      port     = "http"
      provider = "nomad"
    }

    task "nextjs-balancer" {
      template {
        data = <<-EOH
          upstream nextjs {
            {{ range nomadService "nextjs" }}
            server {{ .Address }}:{{ .Port }};
            {{- end }}
          }

          server {
            server_name _;
            listen 80;
            location / {
              proxy_pass http://nextjs;
            }
          }
        EOH

        destination = "local/nginx.conf"
        change_mode = "script"
        change_script {
          command       = "/usr/sbin/nginx"
          args          = ["-s", "reload"]
          timeout       = "5s"
          fail_on_error = true
        }
      }

      driver = "docker"

      config {
        image = "nginx:1.23.1-alpine"
        ports = ["http"]

        volumes = [
          "local/nginx.conf:/etc/nginx/conf.d/default.conf"
        ]
      }
    }
  }
}

Nomad Server logs (if appropriate)

2022-09-07T04:58:04.036Z [ERROR] http: request failed: method=POST path=/v1/jobs?region=global
  error=
  | 1 error occurred:
  | 	* Task group nextjs-balancer validation failed: 1 error occurred:
  | 	* Task nextjs-balancer validation failed: 1 error occurred:
  | 	* Template 1 validation failed: 1 error occurred:
  | 	* must specify change script configuration value when change mode is script
  | 
  | 
  | 
  | 
  | 
  | 
  | 
   code=500

Nomad Client logs (if appropriate)

@DerekStrickland
Copy link
Contributor

Hi @RobbieFernandez. Thanks for reporting this issue. I'll take a look at this, and thanks for pointing out the Pack aspect.

@pkazmierczak
Copy link
Contributor

Hey @RobbieFernandez, it was indeed an issue with Nomad Pack, its API dependency package wasn't updated along with the changes we introduced in Nomad. Apologies—I overlooked this while working on the feature.

pkazmierczak added a commit to hashicorp/nomad-pack that referenced this issue Sep 12, 2022
This is a dependency update. Also resolves hashicorp/nomad#14478
@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 Jan 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

Successfully merging a pull request may close this issue.

3 participants