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

Common packer vars and var validation #336

Merged
merged 2 commits into from
Aug 24, 2020

Conversation

codenrhoden
Copy link
Contributor

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 adds make 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):

 AZURE_LOCATION=fake RESOURCE_GROUP_NAME=fake STORAGE_ACCOUNT_NAME=fake DIGITALOCEAN_ACCESS_TOKEN=fake GCP_PROJECT_ID=fake make -j validate-all

I thought about making a make target that would add these env vars for you, something like make 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

@k8s-ci-robot
Copy link
Contributor

@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:

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 adds make 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):

AZURE_LOCATION=fake RESOURCE_GROUP_NAME=fake STORAGE_ACCOUNT_NAME=fake DIGITALOCEAN_ACCESS_TOKEN=fake GCP_PROJECT_ID=fake make -j validate-all

I thought about making a make target that would add these env vars for you, something like make 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

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 20, 2020
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 20, 2020
@codenrhoden
Copy link
Contributor Author

One interesting point is that if I take these commits, and throw away the first one (that one about the common vars) and run validate-all, it passes. This is what I would have expected (meaning the repo was in good shape), but it doesn't explain the errors that @dvonthenen had been seeing in his own runs. So, @dvonthenen I'll have to work with you to track down the source of the errors you are seeing becuase something else is going on. I still think the change here has merit, because it makes the different vars more explicit, not duplicated, and is a net reduction of LOC.

@codenrhoden
Copy link
Contributor Author

/hold
Just in case a casual /lgtm comes in on this one. :)

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 20, 2020
@dvonthenen
Copy link

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 20, 2020
@EleanorRigby
Copy link
Contributor

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...
Some of these are:

  • Distribution
  • Version
  • build_name
    What do you think? It could be a separate PR

@dvonthenen
Copy link

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...
Some of these are:

  • Distribution
  • Version
  • build_name
    What do you think? It could be a separate PR

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.

@codenrhoden
Copy link
Contributor Author

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...
Some of these are:

  • Distribution
  • Version
  • build_name
    What do you think? It could be a separate PR

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.

@EleanorRigby
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

@EleanorRigby: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 23, 2020
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
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 24, 2020
@codenrhoden
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 24, 2020
@dvonthenen
Copy link

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 24, 2020
@k8s-ci-robot k8s-ci-robot merged commit f74b7d4 into kubernetes-sigs:master Aug 24, 2020
@codenrhoden codenrhoden deleted the common-packer-vars branch August 24, 2020 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants