Skip to content

docs(only_os): name the field it really matches, and drop the RE2 lookahead - #340

Open
ci-robbot wants to merge 1 commit into
mudler:masterfrom
ci-robbot:docs/only-os-pretty-name
Open

ci-robbot wants to merge 1 commit into
mudler:masterfrom
ci-robbot:docs/only-os-pretty-name

Conversation

@ci-robbot

Copy link
Copy Markdown
Contributor

only_os is matched against sysinfo's OS.Name, and sysinfo puts os-release's
PRETTY_NAME there. ID goes to OS.Vendor, which nothing reads
(zcalusic/sysinfo@v1.1.3/os.go). The README says the opposite, so:

  • every lowercase example in it (only_os: "ubuntu|opensuse-leap",
    only_os: "ubuntu") matches nothing. A reader who copies one gets a stage
    that never runs, and the debug line says "doesn't match os name", naming a
    string they did not write a pattern for;
  • only_os: "^(?!ubuntu).*" is worse than not matching. Go's regexp is RE2,
    which has no lookahead, so it fails to compile and OnlyIfOS returns the
    compile error instead of an OS verdict.

Checked on this host (ID=alpine, PRETTY_NAME="Alpine Linux v3.24"):

"ubuntu|opensuse-leap"   vs "Ubuntu 24.04.1 LTS"   -> false
"^(?!ubuntu).*"          compile error: invalid or unsupported Perl syntax: `(?!`
"Ubuntu.*"               vs "Ubuntu 24.04.1 LTS"   -> true

only_os_version was documented correctly: VERSION_ID does land in
OS.Version.

Tests. pkg/plugins/if_os_fields_test.go:

  • two specs that read the host's own /etc/os-release and assert only_os
    matches its PRETTY_NAME and does not match its ID, skipping if the host
    cannot tell the two apart. Pointing OnlyIfOS at OS.Vendor fails both;
  • one that only_os_version matches VERSION_ID;
  • one per filter key that compiles every pattern the README documents, so a
    documented lookahead cannot stay documented. Restoring ^(?!ubuntu).* fails
    it.

Found while migrating kairos-io/kairos's bundled cloudconfigs onto only_os
(kairos-io/kairos#4696), where the docs sent me to the wrong field.

…kahead

only_os is matched against sysinfo's OS.Name, which is os-release's
PRETTY_NAME; os-release's ID lands in OS.Vendor and nothing reads it. So
every lowercase example in the README ('ubuntu', 'opensuse-leap') matches
nothing, and a reader who copies one gets a stage that silently never runs.

The 'everything but ubuntu' example is worse than wrong: Go's regexp is RE2,
which has no lookahead, so '^(?!ubuntu).*' fails to compile and OnlyIfOS
returns the compile error rather than any OS verdict.

Tests pin both. The first pair derives its patterns from the host's own
/etc/os-release and asserts only_os matches PRETTY_NAME and does not match
ID, so pointing OnlyIfOS at OS.Vendor fails them. The second compiles every
only_os, only_os_version and only_arch pattern the README documents, so a
documented lookahead cannot stay documented.

Signed-off-by: mudler-agent <105103991+ci-robbot@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

1 participant