Skip to content

refactor: migrate to rig v2#645

Open
kke wants to merge 1 commit into
Mirantis:mainfrom
kke:rig-v2
Open

refactor: migrate to rig v2#645
kke wants to merge 1 commit into
Mirantis:mainfrom
kke:rig-v2

Conversation

@kke

@kke kke commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

An automated migration from rig v0.x to rig v2 based on the lessons learned from k0sctl's migration and the migration guide.

@kke kke added non-breaking change Does not change functionality or require user actions dependencies Pull requests that update a dependency file go Pull requests that update go code smoke-test Run all smoke tests smoke-modern Run modern smoke test smoke-upgrade Run smoke-upgrade CI job smoke-mhupgrade smoke-airgapped-multi-hop smoke-cutting-edge Trigger cutting-edge smoke test labels Jul 3, 2026
Signed-off-by: Kimmo Lehto <kimmo.lehto@gmail.com>
@kke kke marked this pull request as ready for review July 3, 2026 12:54
@kke kke requested a review from Copilot July 3, 2026 13:39

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

This PR performs an automated migration of Launchpad’s host connectivity/execution layer from k0sproject/rig v0.x to k0sproject/rig/v2, updating how commands, file operations, OS detection, and sudo handling are implemented across MKE/MSR workflows and platform configurers.

Changes:

  • Replaces legacy rig v0 APIs (rig.Connection, exec.Option, configurer file helpers, OS registry) with rig v2 equivalents (rig.CompositeConfig, cmd.ExecOption, remotefs.FS, rig/os.Release).
  • Refactors host connection/execution to be client-based (*rig.Client) with per-host logger injection and sudo override handled during Host.Connect.
  • Introduces an internal OS-module registry (pkg/configurer/registry.go) to replace rig v0 OS module registration, updating all configurer init() registrations accordingly.

Reviewed changes

Copilot reviewed 60 out of 61 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/product/mke/reset.go Removes OverrideHostSudo phase from reset pipeline (sudo override now handled in Host.Connect).
pkg/product/mke/phase/validate_hosts.go Updates upload/stdin validation to rig v2 FS/cmd APIs.
pkg/product/mke/phase/validate_facts_test.go Migrates test host connection config structs to rig v2 SSH config.
pkg/product/mke/phase/upload_images.go Switches to rig v2 shellescape and FS path joining.
pkg/product/mke/phase/upgrade_mke.go Migrates exec options from exec.Option to cmd.ExecOption.
pkg/product/mke/phase/uninstall_mke.go Migrates exec options from exec.Option to cmd.ExecOption.
pkg/product/mke/phase/remove_nodes.go Migrates streamed output option to rig v2 cmd.
pkg/product/mke/phase/overridehostsudo.go Deletes legacy OverrideHostSudo phase (replaced by rig v2 sudo provider on connect).
pkg/product/mke/phase/join_workers.go Migrates redaction + Connect(ctx) signature change.
pkg/product/mke/phase/join_msr_replicas.go Refactors redaction options building for rig v2 cmd.
pkg/product/mke/phase/join_controllers.go Migrates streamed output + redaction to rig v2 cmd.
pkg/product/mke/phase/install_msr.go Migrates bootstrap exec options to rig v2 cmd and refactors redaction option building.
pkg/product/mke/phase/install_mke.go Migrates stdin streaming/redaction and file writes to rig v2 cmd/remotefs FS.
pkg/product/mke/phase/install_mke_certs.go Migrates cert file writes to rig v2 FS API.
pkg/product/mke/phase/init_swarm.go Migrates redact/hide-output to rig v2 cmd APIs.
pkg/product/mke/phase/gather_facts.go Migrates daemon.json reads + hostname and OS reporting to rig v2 FS/Release APIs.
pkg/product/mke/phase/detect_os.go Switches OS reporting from OSVersion to OSRelease.
pkg/product/mke/phase/describe.go Uses OSRelease when reporting host OS.
pkg/product/mke/exec.go Migrates ad-hoc exec flow to rig v2 CompositeConfig + Connect(ctx) and cmd options.
pkg/product/mke/describe.go Removes OverrideHostSudo phase from describe pipeline.
pkg/product/mke/client_config.go Removes OverrideHostSudo phase from client-config pipeline.
pkg/product/mke/apply.go Removes OverrideHostSudo phase from apply pipeline.
pkg/product/mke/config/hosts_test.go Updates tests for Connect(ctx) and rig v2 connection config.
pkg/product/mke/config/host.go Major refactor: host now wraps rig v2 client, adds Connect(ctx), FS-based IO, OSRelease caching, and rig slog→logrus bridge.
pkg/product/mke/config/host_test.go Updates tests to rig v2 SSH/WinRM configs.
pkg/product/mke/config/configurer.go Updates HostConfigurer interface to use new configurer.Host abstraction and removes deprecated file/HTTP helpers.
pkg/product/mke/config/cluster.go Updates default config init to rig v2 CompositeConfig + ssh.Config.
pkg/product/mke/config/cluster_spec.go Updates bastion host linking types to rig v2 ssh.Config.
pkg/product/mke/config/cluster_spec_test.go Updates test configs to rig v2 CompositeConfig + ssh.Config.
pkg/product/common/phase/run_hooks_test.go Migrates test host Exec/ExecOutput signatures to rig v2 cmd options.
pkg/product/common/phase/connect.go Updates connectable interface to Connect(ctx) and retry error sentinel to rig v2.
pkg/msr/bootstrap.go Migrates bootstrap ExecOptions type to rig v2 cmd.
pkg/mke/mke.go Migrates redaction option type to rig v2 cmd.
pkg/mke/bootstrap.go Migrates bootstrap ExecOptions type to rig v2 cmd.
pkg/docker/image.go Renames local workerpool variable (clarity) without functional change.
pkg/configurer/windows/windows_2025.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/windows/windows_2022.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/windows/windows_2019.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/windows.go Refactors Windows configurer to use rig v2 FS/remotefs and cmd options; removes old HTTPStatus.
pkg/configurer/ubuntu/xenial.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/ubuntu/ubuntu.go Refactors Ubuntu configurer to use rig v2 sudo/FS patterns and LinuxConfigurer package ops.
pkg/configurer/ubuntu/noble.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/ubuntu/jammy.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/ubuntu/focal.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/ubuntu/bionic.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/sles/sles.go Refactors SLES configurer to internal OS registry + rig v2 sh/sudo patterns.
pkg/configurer/registry.go Adds internal OS-module registry replacing rig v0 registry usage.
pkg/configurer/oracle/oracle.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/linux.go Major refactor to rig v2: package manager/service helpers, FS-based IO, remotefs patching, and updated Linux OS resolution.
pkg/configurer/host.go Adds configurer.Host interface for configurer methods (cmd runner + sudo + FS).
pkg/configurer/enterpriselinux/rockylinux.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/enterpriselinux/rhel.go Updates OS module registration to internal registry using rig v2 Release.
pkg/configurer/enterpriselinux/el.go Refactors EL configurer to rig v2 FS/sudo patterns and shared package manager removal.
pkg/configurer/common.go Switches docker info logging to logrus and uses new configurer Host interface.
pkg/configurer/centos/centos.go Updates OS module registration to internal registry using rig v2 Release.
pkg/config/config.go Migrates redact-disable flag wiring to rig v2 cmd global.
cmd/exec.go Replaces shellquote join with rig v2 shellescape join.
cmd/common.go Removes rig global logger setter and migrates redact-disable wiring to rig v2 cmd.
.golangci.yml Updates varnamelen config to include new configurer.Host identifier.
go.mod Drops rig v0 + old shellescape; adds rig v2 + slog-logrus bridge; updates indirect deps.
go.sum Updates sums to match dependency migration (rig v2, slog-logrus, and related indirect changes).

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

Comment on lines 78 to 82
log.Infof("%s: testing file upload", h)
defer func() {
if err := h.Configurer.DeleteFile(h, "launchpad.test"); err != nil {
if err := h.Sudo().FS().Remove("launchpad.test"); err != nil {
log.Debugf("%s: failed to delete test file: %s", h, err.Error())
}
Comment thread pkg/configurer/linux.go
Comment on lines +298 to +314
func (c LinuxConfigurer) UpdateEnvironment(h Host, env map[string]string) error {
fsys := h.Sudo().FS()
for k, v := range env {
if strings.ContainsAny(k, "=\n") {
return fmt.Errorf("invalid environment variable key %q: must not contain '=' or newline", k)
}
if strings.ContainsRune(v, '\n') {
return fmt.Errorf("invalid environment variable value for key %q: must not contain newline", k)
}
patch := remotefs.ReplaceOrAppend(remotefs.ByPrefix(k+"="), fmt.Sprintf("%s=%s", k, v))
if err := remotefs.PatchFile(fsys, "/etc/environment", []remotefs.Patch{patch}, remotefs.WithCreate(fs.FileMode(0o644))); err != nil {
return fmt.Errorf("failed updating the env: %w", err)
}
}

// Export the values into the current session environment using the
// in-memory values with proper shell escaping.
Comment thread pkg/configurer/windows.go
Comment on lines 64 to 66
licPath := filepath.Join(dockerRootDir, WindowsDockerLicenseFile)
if err := c.WriteFile(h, licPath, lic, "400"); err != nil {
if err := h.FS().WriteFile(licPath, []byte(lic), fs.FileMode(0o644)); err != nil {
return fmt.Errorf("license write; %w", err)
Comment thread cmd/common.go
Comment on lines 159 to 161
func initExec(ctx *cli.Context) error {
exec.Confirm = ctx.Bool("confirm")
exec.DisableRedact = ctx.Bool("disable-redact")
cmd.DisableRedact = ctx.Bool("disable-redact")
return nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file go Pull requests that update go code non-breaking change Does not change functionality or require user actions smoke-airgapped-multi-hop smoke-cutting-edge Trigger cutting-edge smoke test smoke-mhupgrade smoke-modern Run modern smoke test smoke-test Run all smoke tests smoke-upgrade Run smoke-upgrade CI job

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants