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

consul-lock: a pack demonstrating Consul leadership election #122

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tgross
Copy link
Member

@tgross tgross commented Apr 21, 2022

A pack that demonstrates a script for ensuring that a single Nomad allocation of a job is running at one time. Based on the Consul Learn Guide for application leader elections.

@tgross tgross added the pack label Apr 21, 2022
@tgross tgross requested review from angrycub and mikenomitch April 21, 2022 20:57
@tgross tgross marked this pull request as draft April 22, 2022 15:49
@tgross
Copy link
Member Author

tgross commented Apr 22, 2022

Moving this back to draft b/c I somehow broke it. Need to retest. Figured that out... I needed an extra refresh loop for the blocking case and I'd never left it blocking long enough in my bench testing to hit that case.

@tgross tgross marked this pull request as ready for review April 22, 2022 17:44
@MikaelHashiCorp
Copy link

This pack fails for me.

SETUP

vagrant@pack:~/nomad-autoscaler/jobs$ nomad-pack registry add default github.com/mikaelhashicorp/nomad-pack-community-registry --target=consul_lock
go-getter URL is github.com/mikaelhashicorp/nomad-pack-community-registry.git//packs/consul_lock
Registry successfully cloned at /home/vagrant/.cache/nomad/packs/nomad-pack-tmp
Processing pack entries at /home/vagrant/.cache/nomad/packs/nomad-pack-tmp
found pack entry consul_lock
Processing pack consul_lock@latest
Updating pack
Removing previous latest
Writing pack to /home/vagrant/.cache/nomad/packs/default/consul_lock@latest
Loading cloned pack from /home/vagrant/.cache/nomad/packs/default/consul_lock@latest
Calculating SHA for latest
error calculating SHA
  temp directory deleted
  Registry successfully added to cache.
   PACK NAME  |  REF   | METADATA VERSION | REGISTRY |     REGISTRY URL      
--------------+--------+------------------+----------+-----------------------
  consul_lock | latest | 0.1.0            | default  | github.com/hashicorp  

  Try running one the packs you just added liked this
  
    nomad-pack run consul_lock --registry=default --ref=latest
vagrant@pack:~/nomad-autoscaler/jobs$ nomad-pack info consul_lock
Pack Name          consul_lock
Description        A pack demonstrating the use of Consul session locks for ensuring that only a single allocation of a job is running at a time.
Application URL    https://learn.hashicorp.com/tutorials/consul/application-leader-elections
Application Author HashiCorp, Inc.

Pack "consul_lock" Variables:
        - "constraints" (list of object) - Additional constraints to apply to the jobs.
        - "resources" (object) - The resources to assign to the main task.
        - "namespace" (string) - The namespace for the job.
        - "locker_key" (string) - The path to the locker script
        - "application_image" (string) - The container image for the main task.
        - "application_args" (string) - The command and args for the main task's application.
        - "application_port_name" (string) - The name of the port the application listens on.
        - "application_port" (string) - The port the application listens on.
        - "job_name" (string) - The name of the job.
        - "datacenters" (list of string) - A list of datacenters in the region which are eligible for task placement.
        - "region" (string) - The region where the job should be placed.
        - "locker_image" (string) - The container image for the lock task (needs curl).
        - "locker_script_path" (string) - The path to the locker script

ERRORS

  • Doing command nomad-pack render consul_lock fails with nil pointer:
vagrant@pack:~/nomad-autoscaler/jobs$ nomad-pack render consul_lock
! Failed To Process Pack

        Error:   failed to render consul_lock/templates/example.nomad.tpl: template: consul_lock/templates/example.nomad.tpl:1:11: executing "consul_lock/templates/example.nomad.tpl" at <.my.job_name>: nil pointer
evaluating interface {}.job_name
        Type:    *errors.errorString
        Context: 
                 - Registry Name: default
                 - Pack Name: consul_lock
                 - Pack Ref: latest
  • Doing command nomad-pack plan consul_lock fails with nil pointer:
vagrant@pack:~/nomad-autoscaler/jobs$ nomad-pack plan consul_lock
! Failed To Process Pack

        Error:   failed to render consul_lock/templates/example.nomad.tpl: template: consul_lock/templates/example.nomad.tpl:1:11: executing "consul_lock/templates/example.nomad.tpl"
at <.my.job_name>: nil pointer evaluating interface {}.job_name
        Type:    *errors.errorString
        Context: 
                 - Registry Name: default
                 - Pack Name: consul_lock
                 - Pack Ref: latest
                 - Deployment Name: consul_lock@latest
  • Doing command nomad-pack run consul_lock --registry=default --ref=latest fails with nil pointer:
vagrant@pack:~/nomad-autoscaler/jobs$ nomad-pack run consul_lock --registry=default --ref=latest
! Failed To Process Pack

        Error:   failed to render consul_lock/templates/example.nomad.tpl: template: consul_lock/templates/example.nomad.tpl:1:11: executing "consul_lock/templates/example.nomad.tpl" at
<.my.job_name>: nil pointer evaluating interface {}.job_name
        Type:    *errors.errorString
        Context: 
                 - Registry Name: default
                 - Pack Name: consul_lock
                 - Pack Ref: latest
                 - Deployment Name: consul_lock@latest

@MikaelHashiCorp
Copy link

MikaelHashiCorp commented May 28, 2022

Reference to the nil pointer issue: https://discuss.hashicorp.com/t/nil-pointer-evaluating-interface-region/32973
Reference to .my. issue: hashicorp/nomad-pack#248

@tgross
Copy link
Member Author

tgross commented May 31, 2022

@MikaelHashiCorp can you explain what you mean with those two links? I see in your error log that there's a nil pointer on the template for some reason but as far as I can tell the value is set as the default variable. Is there some insight in those links that suggests why?

@MikaelHashiCorp
Copy link

@tgross:

I referenced the two links in case they may help you in anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants