-
Notifications
You must be signed in to change notification settings - Fork 394
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
Common packer vars and var validation #336
Common packer vars and var validation #336
Conversation
@codenrhoden: GitHub didn't allow me to request PR reviews from the following users: EleanorRigby. Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: codenrhoden The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
One interesting point is that if I take these commits, and throw away the first one (that one about the common vars) and run |
/hold |
/lgtm |
Just one thing I would like to add is that we can also extract some OS-specific variables to the top level and create ubuntu-args.json and centos-args.json...
|
If it's possible to do this in a future PR, that would be ideal since I have other time-sensitive dependencies on getting this merged. |
This is also a bit of a balancing act between what to improve here within the limitations we have given Packer templates, and what we can do with a full-fledged Go CLI and YAML templating. So I'm in favor of holding off on such a thing for now as well. @dvonthenen as for your dependencies, I'd at least like to get some input from @detiber or @CecileRobertMichon on this one, but the overlap with KubeCon makes that a bit harder. This PR doesn't introduce any user-facing changes, so I'll hold out through today and then consider removing the hold. |
/lgtm |
@EleanorRigby: changing LGTM is restricted to collaborators In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
There are a set of common Packer vars that are found in every cloud provider packer config, all passed to Ansible, and all with the same default value. Instead of re-defining these in each builder, define them in a common place and include them via the Makefile. There are a couple of limitations along with this. We can't move variables that use functions (e.g. user or env), and we can't have vars that reference other vars. We also can't move things that we want to define as nil.
This patch adds individual Make targets to run "packer validate" commands to verify that Packer templates are structured and filled properly. Additionally, there is a "validate-all" target that can be used to make sure that all builders are correct. Some builders are expecting values to be supplied via env var, and those can be supplied when calling make. For example, to validate every builder in the project as of this commit, this command can be used: AZURE_LOCATION=fake RESOURCE_GROUP_NAME=fake STORAGE_ACCOUNT_NAME=fake \ DIGITALOCEAN_ACCESS_TOKEN=fake GCP_PROJECT_ID=fake make -j validate-all
0df057b
to
39f37b1
Compare
/hold cancel |
/lgtm |
This PR has 2 commits.
The first PR fixes an issue seen where the Azure builder is missing the
http_proxy
variable. This was in the same vein as #335, and I'm still not quite sure why this happened for some users (@dvonthenen) and not others. The previously observed behavior had always been that if you used{{user `some_var`}}
and that var hadn't been defined, it ended up as an empty string. The errors that @dvonthenen say indicated otherwise. maybe it was a Packer version or something... Anyways, it has long bothered me that several of these variables were defined in multiple places, so I moved what could be moved into a common location. That's what this commit does. See commit message for a description of what couldn't be moved.The 2nd commit gives us a way to validate the config using
packer validate
. I had tried to do this once before in the past, but didn't see it through. This commit addsmake validate-*
targets that make sure everything is syntactically correct once you layer on all of your additional var files. For some builders, this works out of the box, for others it requires setting a few env vars. But the net result is that if you want, you can run the following command to quickly (~6s on my laptop) look for any syntax errors for Packer vars (of which we have encountered many over the life of this project):I thought about making a
make
target that would add these env vars for you, something likemake validate-all-test
or something similar. I wanted to see what others think. Regardless, I think this would make an excellent CI target as it would catch a large number of errors we end up encountering, without having to need cloud account credentials, and without kicking off a "real" build only to see it fail./assign @detiber @CecileRobertMichon
/cc @dvonthenen @EleanorRigby