Skip to content

machine-tags: extend syntax to support key/value pairs#42618

Merged
bluca merged 3 commits into
systemd:mainfrom
poettering:machine-tags-kv
Jun 22, 2026
Merged

machine-tags: extend syntax to support key/value pairs#42618
bluca merged 3 commits into
systemd:mainfrom
poettering:machine-tags-kv

Conversation

@poettering

Copy link
Copy Markdown
Member

This is a minor extension, to move the machine tags concept more closely towards what higher-level solutions support for tagging machines, such as kubernetes, simply to reduce the conceptual impedance mismatch.

@poettering poettering added pid1 hostname please-review PR is ready for (re-)review by a maintainer claude-review labels Jun 16, 2026
@poettering poettering added this to the v262 milestone Jun 16, 2026
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

Claude review of PR #42618 (59621f2)

The change is sound. Across correctness, memory safety, resource lifetimes, security, and the key/value tag semantics there are no defects: the split_pair() optional-parameter change is safe on every path and for every existing caller, the key-uniqueness strneq(np) prefix logic correctly distinguishes "same key, different value" from keys that are prefixes of one another, and the graceful/strict dedup paths are mutually consistent. Most prior items have been addressed in the latest revision.

Suggestions

  • man page last-char rule contradicts codeman/machine-info.xml:154 — paragraph claims the last char of any tag may not be -/., but values may end in -/. (the PR's own tests assert foo=bar- and foo=.bar are valid); scope the rule to the key / unparameterized tags.
  • factor out the shared same-key testsrc/basic/hostname-util.c:353 — the np = eq - *i + 1 + prefix-compare idiom is duplicated in machine_tag_list_is_valid() and machine_tags_from_string().

Nits

  • prefer strneq() over strncmp() == 0src/basic/hostname-util.c:307 — CODING_STYLE convention.
  • prefer strneq() over strncmp() == 0src/basic/hostname-util.c:359 — CODING_STYLE convention.
  • graceful tag limit counts suppressed duplicatessrc/basic/hostname-util.c:353 — the MACHINE_TAGS_MAX check happens before duplicate-key suppression, so skipped same-key tags still count toward the limit (only matters for >1024 same-key entries).

Workflow run

Comment thread man/machine-info.xml Outdated
Comment thread src/basic/hostname-util.c
Comment thread src/basic/hostname-util.c Outdated
Comment thread src/basic/hostname-util.c Outdated
@poettering poettering added the downstream/amutable Issues that apply to downstream amutable distribution label Jun 17, 2026
Comment thread src/basic/hostname-util.c
Other systems (kubernetes…) allow tagging machines with key/value pairs.
Let's extend our allowed syntax slightly to allow that too. Thankfully,
we enforced a pretty strict ruleset on machine tags, hence we can
introduce this without breaking compatibility.

This basically allows tags to contain "=". If so, then the left-hand
side of it must be unique among machine tags.

When matching against a machine tag, we apply the same rules as before.
This means, that if people want to check if a tag with value applies
they can do:

    ConditionMachineTag=foo=bar

If they just want to check if "foo=" is set to anything, they can use
the usual glob matching:

    ConditionMachineTag=foo=*
@bluca bluca added unproductive Spam, trolling, run-away bots, etc. ci-failure-appears-unrelated and removed please-review PR is ready for (re-)review by a maintainer unproductive Spam, trolling, run-away bots, etc. labels Jun 22, 2026
@bluca bluca merged commit 4dc1e31 into systemd:main Jun 22, 2026
72 of 84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants