refactor: migrate to rig v2#645
Open
kke wants to merge 1 commit into
Open
Conversation
Signed-off-by: Kimmo Lehto <kimmo.lehto@gmail.com>
There was a problem hiding this comment.
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 duringHost.Connect. - Introduces an internal OS-module registry (
pkg/configurer/registry.go) to replace rig v0 OS module registration, updating all configurerinit()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 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 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 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An automated migration from rig v0.x to rig v2 based on the lessons learned from k0sctl's migration and the migration guide.