Skip to content

Make keyword converters type-safe and fix related issues - #1107

Merged
cgalibern merged 5 commits into
opensvc:mainfrom
cgalibern:dev
Sep 7, 2026
Merged

Make keyword converters type-safe and fix related issues#1107
cgalibern merged 5 commits into
opensvc:mainfrom
cgalibern:dev

Conversation

@cgalibern

Copy link
Copy Markdown
Contributor

Summary

This pull request enhances type safety for keyword converters by transitioning from string-based naming to direct type references. Previously, string-based errors could remain undetected until evaluation, causing runtime failures. Additionally, a sanity test is added to validate converter registration and correctness.

Key Changes

  • Refactored keywords.Keyword.Converter to use converters.Converter directly, replacing string-based definitions.
  • Implemented converters.Get() to safely retrieve converters and prevent panics on unknown names.
  • Corrected converter name mismatch for fs.sgcp_nfs_cg driver ("boolean" replaced with "bool" to fix runtime errors).
  • Added a sanity test to enforce proper keyword converter registrations.

Notes

These changes do not affect the external API schema, maintaining compatibility with existing integrations.

The failover keyword of the fs.sgcp_nfs_cg driver names a "boolean"
converter, which is not registered. converters.Lookup() panics on an
unknown name, so starting an object with such a resource crashes in
configureResource(), through EvalKeywordAs() and xconfig.convert().

The registered name is "bool".
A keyword used to name its converter with a string, resolved at
evaluation time by converters.Lookup(), which panics when no converter
is registered under that name. A typo in a keyword definition was thus
undetectable until an object using that keyword was started.

Change keywords.Keyword.Converter to a converters.Converter, and export
a singleton for each converter, so a keyword definition references the
converter instead of naming it. A typo is now a compilation error. A nil
Converter means no conversion, which the empty name used to mean.

converters.Lookup() is replaced by:

  * converters.Get(), which reports whether the name is known instead of
    panicking. It is only needed at the daemon API boundary, where the
    converter name of a keyword definition comes from a peer daemon that
    may run a different version, and so may name a converter this
    version does not know. Such a keyword now degrades to no conversion
    instead of crashing the client.

  * converters.Name(), which returns the name a converter is registered
    as, to feed the string field of the API keyword definition item.

The API schema is unchanged: KeywordDefinitionItem.Converter remains a
string.

The nodes and peers converters, which live in core/xconfig because they
depend on the node selector, get the same treatment through
xconfig.NodesConverter and xconfig.PeersConverter.
Now that a keyword references its converter instead of naming it, the
compiler rejects an unknown converter. Two mistakes remain possible: a
converter implemented but never registered, which would break the name
exposed by the API, and a keyword default value the keyword converter
refuses.

Add a test walking the node keyword store, the keyword store of every
object kind and the keyword store of every registered driver, and
asserting both. The per-driver stores are walked because a driver
manifest declaring no kind is not reachable from
object.KeywordStoreWithDrivers().
@cgalibern
cgalibern merged commit 90c9abd into opensvc:main Sep 7, 2026
1 check passed
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