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

Clarify that debos recipes are pre-processed using go templating before yaml parsing #81

Open
elboulangero opened this issue May 30, 2018 · 8 comments

Comments

@elboulangero
Copy link
Contributor

Consider the following snippet in a recipe:

{{ $kver := "4.9.0" }}
#{{ $kver := "4.16.0" }}

Currently the value of kver will be set to 4.16.0, since the Golang templating engine is not aware of the YAML syntax. But this is definitely not what an user expects, comments should be ignored.

@smcv
Copy link
Contributor

smcv commented Jun 5, 2018

I'm not so sure this is a great idea. At the moment the processing model is reasonably easy to explain: the template undergoes Go templating evaluation, followed by YAML parsing. Applying a small fraction of YAML parsing, followed by Go templating evaluation, followed by full YAML parsing seems more confusing to me?

I think the source of confusion is that the recipes are sometimes described as YAML, which is not really true, because the templating instructions don't participate in YAML syntax. Instead, the recipes are Go templates that must output YAML.

@gctucker
Copy link

gctucker commented Jun 5, 2018

Use Go template comments maybe?
https://golang.org/pkg/text/template/#hdr-Actions

@elboulangero
Copy link
Contributor Author

If a line starting with # is a comment, then everything that comes after the # should be safe to write, don't you think?

@gctucker
Copy link

gctucker commented Jun 6, 2018

# is not a comment in the Go template language, but this {{/* */}} is:

# The line below should not appear in the YAML output:
{{/* {{ $arch := "riscv" }} */}}

I've verified it with a debos recipe.

@elboulangero
Copy link
Contributor Author

@gtucker, thanks for the example. Actually I understand that I can use Go template comments, but that's not the point I want to raise. I opened this issue because I care about the usability of the tool.

It appears than recipe files are both YAML format AND Go template language at the same time (smcv said it better above). So when you look at a debos recipe, what do you see? Maybe some users see a YAML file, some other users see Go templating at work. Some educated users see both and know how it works under the hood, but you can't expect that from new users.

Personally, the first debos recipes I've seen looked and behaved very much like a YAML file, and I had absolutely no idea what Go templating was. So I used it like a YAML file, and it was just fine, until I happened to comment a line containing a template, and then I lost an hour or two figuring out what the hell was going on. Then I became a bit more of an educated user :)

Every new user is different, sure, but I think that there's something confusing that could be improved here.

@smcv
Copy link
Contributor

smcv commented Jun 6, 2018

It appears than recipe files are both YAML format AND Go template language at the same time

No, they are a Go template that generates YAML. The difference between that and what I quoted is important.

You can't write a machine-readable language correctly unless you know what it is. It's the same as how you need to know whether you are writing Javascript or Javascript-embedded-in-HTML before you can write a less-than comparison using < (if in Javascript) or &lt; (if in Javascript embedded in HTML); if you get it wrong (in either direction!) then your code won't work.

If new users think the recipes are YAML, the solution is for the documentation to be clearer about the recipes being Go templates that generate YAML.

@gctucker
Copy link

gctucker commented Jun 6, 2018

Maybe the convention for naming recipe files should be something else than just .yaml as this can be misleading too.

@sjoerdsimons
Copy link
Member

Well if there is no go templating in there they are pure yaml indeed :). But yes it's a documentation not a technical issue, debos does as it's intended (which @smcv nicely explained).

Just looking around there is no clear convention in what to name go templates. E.g. the Helm best practises say it should be .yaml if it generates yaml (but there templates are in a template dir which gives a hint).. Others use .gothml and .goyaml which some editors recognize, While others (like the go vim plugin apparently) looks for .tmpl extension.

I'd personally be slightly in favour of .goyaml, but i'd be fine with a differntly colored bikeshed :).

@sjoerdsimons sjoerdsimons changed the title YAML comments should be ignored when executing the templates Clarify that debos recipes are pre-processed using go templating before yaml parsing Jun 14, 2018
refi64 pushed a commit to refi64/debos that referenced this issue Jan 24, 2023
Up to now, the assumption was that, given a kernel release `KREL`, the
kernel was installed under `/boot/vmlinuz-$KREL`.

While this is true at least on Debian and Ubuntu, this doesn't work for
distributions like ArchLinux or Manjaro. For those distributions, there
is no obvious way to match module directories and kernel filenames.

In order to support these distributions, we need to do more than that.

The solution chosen here is simply to look into the kernel binaries for
the kernel release as a static string, followed by a space. It works on
all the distos tested so far:

  # Debian
  $ strings /boot/vmlinuz-4.19.0-6-amd64 | grep '4.19.0-6-amd64 '
  4.19.0-6-amd64 ([email protected]) go-debos#1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11)
  4.19.0-6-amd64 ([email protected]) (gcc version 8.3.0 (Debian 8.3.0-6)) go-debos#1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11)

  # Ubuntu
  $ strings /boot/vmlinuz-4.15.0-72-generic | grep '4.15.0-72-generic '
  4.15.0-72-generic (buildd@lcy01-amd64-026) go-debos#81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019
  4.15.0-72-generic (buildd@lcy01-amd64-026) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) go-debos#81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019

  # ArchLinux
  $ strings /boot/vmlinuz-linux | grep '5.4.2-arch1-1 '
  5.4.2-arch1-1 (linux@archlinux) go-debos#1 SMP PREEMPT Thu, 05 Dec 2019 12:29:40 +0000
  5.4.2-arch1-1 (linux@archlinux) (gcc version 9.2.0 (GCC)) go-debos#1 SMP PREEMPT Thu, 05 Dec 2019 12:29:40 +0000

  # Manjaro
  $ strings /boot/vmlinuz-4.19-x86_64 | grep '4.19.88-1-MANJARO '
  4.19.88-1-MANJARO (builder@8898125bf991) go-debos#1 SMP PREEMPT Thu Dec 5 11:04:44 UTC 2019
  4.19.88-1-MANJARO (builder@8898125bf991) (gcc version 9.2.0 (GCC)) go-debos#1 SMP PREEMPT Thu Dec 5 11:04:44 UTC 2019

For reference, here's how Arch and Manjaro look like:

ArchLinux:

  # ls -1 /lib/modules
  4.19.88-1-lts
  5.3.15.a-1-hardened
  5.4.2-arch1-1
  5.4.2-zen1-1-zen

  # ls -1 /boot/vmlinuz-*
  /boot/vmlinuz-linux
  /boot/vmlinuz-linux-hardened
  /boot/vmlinuz-linux-lts
  /boot/vmlinuz-linux-zen

Manjaro:

  # ls -1 /lib/modules
  3.16.78-1-MANJARO
  4.19.72-rt26-MANJARO
  4.19.88-1-MANJARO
  5.2.21-rt14-MANJARO
  5.3.15-1-MANJARO
  5.4.2-1-MANJARO
  extramodules-3.16-MANJARO
  extramodules-4.19-MANJARO
  extramodules-4.19-rt-MANJARO
  extramodules-5.2-rt-MANJARO
  extramodules-5.3-MANJARO
  extramodules-5.4-MANJARO

  # ls -1 /boot/vmlinuz-*
  /boot/vmlinuz-3.16-x86_64
  /boot/vmlinuz-4.19-rt-x86_64
  /boot/vmlinuz-4.19-x86_64
  /boot/vmlinuz-5.2-rt-x86_64
  /boot/vmlinuz-5.3-x86_64
  /boot/vmlinuz-5.4-x86_64

Signed-off-by: Arnaud Rebillout <[email protected]>
[Santosh: move code machine.go->backend_kvm.go, fixup KernelPath()]
[Emil: reinstate authorship, commit message, stylistic changes]
Signed-off-by: Emil Velikov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants