Skip to content

feat(autodiscovery): Add Nomad integration #4957

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

Merged
merged 11 commits into from
Apr 30, 2025
Merged

Conversation

olblak
Copy link
Member

@olblak olblak commented Apr 28, 2025

Fix #2331

Add Nomad autodiscovery plugin to automate docker image update.
Please note that it only supports the Docker driver and HCL files.
We could improve it in the future to also handle JSON files

It handles the following scenario:

  • simple scenario such as image = "hashicorp/http-echo:latest"
  • handle scenario with one variable such as image = "grafana/grafana:${var.image_tag}"

In the second case, Updatecli will update the variable definition and not the task definition

Test

To test this pull request, you can run the following commands:

cd pkg/plugins/autodiscovery/nomad/
go test 

I also did some testing on https://github.com/fhemberger/nomad-demo

Additional Information

Checklist

Tradeoff

Potential improvement

  • Support credentials specified from config
  • Support json manifest

@olblak olblak added enhancement New feature or request autodiscovery All things related to the autodiscovery feature labels Apr 28, 2025
@olblak olblak requested a review from Copilot April 28, 2025 14:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Nomad integration to Updatecli’s autodiscovery feature, enabling automated updates for Nomad job files and supporting variable interpolation for docker image definitions.

  • Introduces Nomad plugin implementation with supporting utility and matching rule functions.
  • Adds tests and manifest templates specifically for Nomad.
  • Integrates the Nomad crawler into the autodiscovery pipeline.

Reviewed Changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/plugins/autodiscovery/nomad/utils_test.go Adds tests for Nomad file search, spec parsing, and variable extraction functions.
pkg/plugins/autodiscovery/nomad/utils.go Implements file search and Nomad spec parsing (note: update comment regarding Chart.yaml).
pkg/plugins/autodiscovery/nomad/matchingRule.go Implements rule matching logic but contains an accumulation bug in ruleResults.
pkg/plugins/autodiscovery/nomad/matchingRule_test.go Adds tests validating matching rule behavior for Nomad resources.
pkg/plugins/autodiscovery/nomad/manifestTemplate.go Provides manifest templates for generating updated Nomad configuration.
pkg/plugins/autodiscovery/nomad/main_test.go Tests the discovery of manifests from Nomad configuration files.
pkg/plugins/autodiscovery/nomad/main.go Implements the Nomad plugin’s initialization logic.
pkg/plugins/autodiscovery/nomad/dockerDriver.go Generates manifests for Nomad jobs via docker image parsing and templating.
pkg/core/pipeline/autodiscovery/main.go Registers the Nomad crawler into the autodiscovery pipeline.
Files not reviewed (2)
  • pkg/plugins/autodiscovery/nomad/testdata/simple/nomad.hcl: Language not supported
  • pkg/plugins/autodiscovery/nomad/testdata/variable/grafana.nomad: Language not supported
Comments suppressed due to low confidence (1)

pkg/plugins/autodiscovery/nomad/utils.go:17

  • [nitpick] The comment incorrectly references "Chart.yaml"; update it to indicate that the function searches for Nomad files based on the provided file patterns.
// searchNomadFiles will look, recursively, for every files named Chart.yaml from a root directory.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
loispostula
loispostula previously approved these changes Apr 29, 2025
Copy link
Contributor

@loispostula loispostula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, maybe it needs to be a touch clearer that it's only for the docker driver in hcl files, as you can have different drivers and also json spec

@olblak
Copy link
Member Author

olblak commented Apr 29, 2025

This looks good, maybe it needs to be a touch clearer that it's only for the docker driver in hcl files, as you can have different drivers and also json spec

Indeed good point

@allroundtechie
Copy link

Just want to mention, docker is not the only driver for container related workloads, there is also a podman driver.
Also authentication against a private container registry would be awesome.

@loispostula
Copy link
Contributor

Just want to mention, docker is not the only driver for container related workloads, there is also a podman driver. Also authentication against a private container registry would be awesome.

@allroundtechie usually this is left to the caller of updatecli, typically in ci what i do is have a login step (for docker registries, npm, cargo, ...) then call updatecli

@allroundtechie
Copy link

@loispostula Good point, thanks. I basically forgot how I was doing it with the docker-compose autodiscovery which I use at another project and a private registry and you are right, I also did this like you mentioned (within a CI pipeline step). This really says a lot about this tool, setup and forget, just works :-)

@olblak
Copy link
Member Author

olblak commented Apr 29, 2025

The way I see authentication today:

  • Rely on the default docker configuration (usually my preferred approach)
  • Specify credentials in the autodiscovery plugin, I must admit I never use this
  • Not supported yet, but we could also load information from nomad configuration as explained here

@allroundtechie
Copy link

allroundtechie commented Apr 29, 2025

The way I see authentication today:

  • Rely on the default docker configuration (usually my preferred approach)
  • Specify credentials in the autodiscovery plugin, I must admit I never use this
  • Not supported yet, but we could also load information from nomad configuration as explained here

Just my two cents:
I do not know what the majority of updatecli users do or how they use updatecli, I personally use it within CI pipelines only. That said you do not want to have credentials or other security related stuff in clear text in config files or in this case hcl/nomad files for authentication.
I struggled with this myself when deploying nomad job via a CI pipeline and do a replacement of "dummy" credentials in the nomad/hcl file with the real credentials form the vault or secrets store e.g.

sed -i 's|REGISTRY_USERNAME|'${{ env.USERNAME }}'|g' service.hcl
sed -i 's|REGISTRY_PASSWORD|'${{ env.TOKEN_PACKAGE_READ }}'|g' service.hcl

So from a security point of view the last option @olblak mentioned is at least in context of CI pipelines actually a no go. But of course this could makes sense for other people who do not use CI pipelines.
Basically @loispostula mentioning the docker login setup in the CI pipeline is all which is needed.

@loispostula
Copy link
Contributor

@allroundtechie back when I was using nomad, but I do use it for my k3s clusters, I actually set up containerd with authenticated mirrors on the hosts and don't even bother with credentials in the job definitions

@olblak
Copy link
Member Author

olblak commented Apr 29, 2025

Thanks for the feedback, I agree with you.

Updatecli is mostly used from a CI environment and rely on environment variables.
Updatecli could also load credentials from SOPS files, but I never heard anyone using this approach and I stopped using SOPS a long time ago 🤷🏾

Basically @loispostula mentioning the docker login setup in the CI pipeline is all which is needed.
That's all I use as well

So I guess the PR is ready in the current state and we could always improve it after

@olblak olblak enabled auto-merge (squash) April 30, 2025 13:12
@olblak olblak disabled auto-merge April 30, 2025 13:13
@olblak olblak merged commit 0ffbad9 into updatecli:main Apr 30, 2025
6 checks passed
@olblak olblak deleted the issue/2331 branch April 30, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autodiscovery All things related to the autodiscovery feature enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add autodiscovery for Hashicorp Nomad
3 participants