How to access Nomad variables from a task driver plugin

Dear Nomad community,

I am learning Nomad and trying to create a task driver plugin, I would like to read/update Nomad variables from the task driver.

Is there an example I can check showing this?

thank you very much

let me understand more. if you need to update variables, other applications using this variables will be affected?

Hi,

short answer:

No other applications will get affected.
Yes other Nomad jobs will get affected because the idea is to use this variable like a semaphore to sync different Nomad job instances.

long answer:

So the goal for this task driver is to install/uninstall applications.

The job will:

  1. install a list of packages during the prestart lifehook
  2. sleep during leader lifehook
  3. uninstall the list of packages during the poststop lifehook

The problem of this driver is that the user can stop and then start the job. The issue is that the poststop and the prestart may overlap and therefore the final state of the system is unpredictable.

We want to use a Nomad variable to sync this process.

When a job starts, if the variable does not exists, then it assumes the packages have not been installed and then proceeds, otherwise, if the variable exists, then, the prestart task should wait because it needs to wait the previous job to stop.

Please let me know if clean or need more clarification

thank you very much

1 Like

wow, very clean your objective now! if you use consul in your nomad cluster, you can use consul k/v

If you want other way to solve this problem, explain here. I will think other way to solve your challenge.

Hi, yes

basically I am quite noob with Golang and hashicorp/Nomad sdk…

I was wondering if I could get some guidance on which function/module/struct should I use in order to be able to do CRUD operations with Nomad variables.

I am not using consul at the moment

thank you very much

1 Like

Don’t problem with you level of knowledge about this tools/languages.

I’m happy to share with you my experience :smiley:

feel confortable to bring more questions!

ok,

one of the questions I have is.

in a Nomad plugin of type executer, do I need to create a Nomad client in order to create a Nomad variable?

thank you

@claytonsilva any idea about what is the best way to get variable data within a nomad plugin?