Skip to content

Generate JSON schemas for the configuration objects - #267

Merged
kke merged 11 commits into
release-0.xfrom
jsonschema
Jun 4, 2026
Merged

kke merged 11 commits into
release-0.xfrom
jsonschema

Conversation

@kke

@kke kke commented May 23, 2025

Copy link
Copy Markdown
Contributor

This is a requirement for k0sproject/k0sctl#860

@a1994sc

a1994sc commented Mar 30, 2026

Copy link
Copy Markdown

Hey @kke, is there any chance of getting this into the v0 branch?

@kke

kke commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

Hey @kke, is there any chance of getting this into the v0 branch?

I haven't tried to use it at all so I have no clue if it works or if it's useful.

@a1994sc

a1994sc commented May 4, 2026

Copy link
Copy Markdown

Hey @kke, is there any chance of getting this into the v0 branch?

I haven't tried to use it at all so I have no clue if it works or if it's useful.

Well I created #327 to help get it merged in, mostly that PR addresses the linting issues... I did lean on //nolint for a few things as I didn't want to change too much of the code base.

kke added 2 commits May 12, 2026 21:19
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
- Add sentinel errors and wrap external errors (err113, wrapcheck)
- Handle unchecked error returns in examples (errcheck)
- Fix import ordering in resolver.go (gci)
- Define osWindows constant to replace repeated literals (goconst)
- Remove duplicate package doc in os/linux/ubuntu.go (godoclint)
- Add nolint comments for intentional gosec patterns (G702, G115)
- Apply modernize suggestions: maps.Copy, slices.Contains, WaitGroup.Go,
  string concatenation over fmt.Sprintf, slice preallocation, build tags
- Add nolint for noctx on long-running SSH processes
- Add missing doc comments for exported symbols (revive)
- Add package comments to example programs (revive)
- Migrate examples/password from deprecated terminal to golang.org/x/term
- Remove unnecessary type conversion in examples/password (unconvert)
- Rename short variable names in examples (varnamelen)

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a JSON Schema generation workflow for rig connection configuration structs (SSH/OpenSSH/WinRM/Localhost), enabling downstream projects (e.g., k0sctl) to validate and offer editor support for configs.

Changes:

  • Annotates connection config structs with json/jsonschema metadata and introduces a schema generator tool.
  • Adds generated JSON/YAML schema artifacts under schemas/ and enforces consistency in CI.
  • Includes a set of small refactors/cleanups (string building, error wrapping, command construction, comments).

Reviewed changes

Copilot reviewed 35 out of 37 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
winrm.go Adds JSON + jsonschema tags and field docs for WinRM config.
ssh.go Adds JSON + jsonschema tags for SSH config; minor refactors.
openssh.go Adds JSON + jsonschema tags for OpenSSH config; minor refactors and lints.
localhost.go Adds JSON + jsonschema tags for Localhost config; adds nolint notes.
connection.go Adds JSON tags to embedded connection configs; small comment/lint updates.
resolver.go Minor doc/format tweaks; uses constant for Windows ID.
resolver_test.go Minor formatting changes.
signals.go Removes legacy build tag; adds guards around terminal size values.
errors.go Re-documents exported sentinel errors without inline trailing comments.
pkg/rigfs/withname.go Improves const docs for operation names.
pkg/rigfs/winfsys.go Replaces fmt.Sprintf with concatenation for command strings.
pkg/rigfs/posixfsys.go Fixes option slice construction; replaces fmt.Sprintf with concatenation for commands.
os/windows/windows2019.go Uses a constant for Windows OS ID in matcher.
os/windows.go Replaces fmt.Sprintf with concatenation for command strings.
os/linux.go Replaces some fmt.Sprintf usages with concatenation.
os/linux/ubuntu.go Removes redundant package comment (still present elsewhere in package).
os/registry/registry.go Exports OS module builder function type; doc tweaks.
connection_test.go Formatting-only adjustments for mock client methods.
internal/jsonschema/gen_schema.go Adds schema generation CLI (JSON/YAML output).
internal/jsonschema/go.mod Introduces a separate module for schema generation tool.
internal/jsonschema/go.sum Adds dependency lockfile for schema generation tool.
internal/jsonschema/Makefile Adds targets to generate schema files into /schemas.
schemas/ssh.json Generated JSON schema for SSH config.
schemas/ssh.yaml Generated YAML schema for SSH config.
schemas/openssh.json Generated JSON schema for OpenSSH config.
schemas/openssh.yaml Generated YAML schema for OpenSSH config.
schemas/winrm.json Generated JSON schema for WinRM config.
schemas/winrm.yaml Generated YAML schema for WinRM config.
schemas/localhost.json Generated JSON schema for Localhost config.
schemas/localhost.yaml Generated YAML schema for Localhost config.
Makefile Adds make schemas wrapper target.
.github/workflows/golangci-lint.yaml Adds CI step to verify generated schemas are up-to-date.
examples/upload/upload.go Improves variable names and error wrapping.
examples/password/password.go Updates password prompt to use golang.org/x/term.
examples/os/stock/stock.go Improves error wrapping and variable names.
examples/logging/logging.go Avoids ignoring returned errors silently by assigning to _.
examples/confirmation/confirmation.go Improves variable naming and avoids ignoring returned errors silently.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread winrm.go Outdated
Comment thread winrm.go Outdated
Comment thread winrm.go Outdated
Comment thread ssh.go Outdated
Comment thread ssh.go Outdated
Comment thread internal/jsonschema/Makefile Outdated
Comment thread internal/jsonschema/gen_schema.go
Comment thread resolver_test.go Outdated
Comment thread .github/workflows/golangci-lint.yaml
Comment thread localhost.go
kke added 2 commits May 12, 2026 21:49
- Add anyOf hostname/ipv4/ipv6 constraint for address fields in SSH and WinRM schemas
- Skip address format constraint for OpenSSH (accepts ssh_config aliases)
- Add const:true constraint for Localhost.enabled field
- Make SSH User and Port optional in schema (both have runtime defaults)
- Add omitempty to optional WinRM boolean/int fields so they are not required
- Update CI workflow to trigger on schema and jsonschema generator changes
- Fix empty const block in resolver_test.go
- Fix trailing quote in connection.go comment
Validates required fields, format constraints (hostname/ipv4/ipv6), port
ranges, const values, and additionalProperties rejection for SSH, OpenSSH,
WinRM, and Localhost schemas. Uses santhosh-tekuri/jsonschema/v6 with format
assertions enabled so address format rules are enforced in tests.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 40 changed files in this pull request and generated 2 comments.

Comment thread go.mod
Comment thread .github/workflows/golangci-lint.yaml Outdated
kke added 2 commits May 12, 2026 22:14
- Mark santhosh-tekuri/jsonschema/v6 as direct dependency in go.mod
- Remove trailing whitespace from golangci-lint workflow
…-module

Keeps santhosh-tekuri/jsonschema/v6 out of rig's main go.mod — the
library is a test-only concern and belongs in the isolated sub-module
alongside the schema generator.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 39 changed files in this pull request and generated 3 comments.

Comment thread openssh.go Outdated
Comment thread openssh.go Outdated
Comment thread .github/workflows/golangci-lint.yaml
…s.ToArgs() call

- closeControl: remove redundant c.userhost() append — c.args() already
  includes the destination; passing it twice broke ssh -O exit
- startControl: store opts.ToArgs() in a local variable to avoid calling
  it twice (extra work + non-deterministic map iteration)
- ci: add step to run schema validation tests in internal/jsonschema,
  which go test ./... from the root module skips

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 39 changed files in this pull request and generated no new comments.

@a1994sc

a1994sc commented May 13, 2026

Copy link
Copy Markdown

I have tested locally and this seems to work just fine. Thank you @kke

# Conflicts:
#	os/windows.go
#	pkg/rigfs/posixfsys.go
Resolve conflicts from lint fixes in release-0.x (c19e696):
- Accept CommandContext(context.Background()) replacements for all
  exec.Command calls in localhost.go and openssh.go
- Accept extracted setExtraOSReleaseField helper in resolver.go
- Accept minor comment/wording improvements across files
- Keep HEAD's IsWindows() in openssh.go (release-0.x has invalid Go syntax)
- Keep HEAD's closeControl() args in openssh.go (release-0.x re-introduced
  the duplicate userhost bug fixed in da237d4)
- Fix release-0.x typo in upload.go example (*usr → *user)
- Fix duplicate osWindows const introduced by merge in connection.go
@kke
kke merged commit dcdbe7f into release-0.x Jun 4, 2026
7 checks passed
@kke
kke deleted the jsonschema branch June 4, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants