Skip to content

refactor: extract backend detection into testable interface with strict precedence#814

Open
Devansh-567 wants to merge 2 commits into
uyuni-project:mainfrom
Devansh-567:feature/deterministic-backend-detector
Open

refactor: extract backend detection into testable interface with strict precedence#814
Devansh-567 wants to merge 2 commits into
uyuni-project:mainfrom
Devansh-567:feature/deterministic-backend-detector

Conversation

@Devansh-567

Copy link
Copy Markdown

What does this PR change?

GetCommand() in shared/connection.go previously coupled host system concerns interleaving PATH lookups, podman inspect evaluations, systemd service inspections, live kubectl deployment probes, and helm release queries into a single 70-line block. This structural configuration created high maintenance risk and made the detection pipeline untestable without a live environment.

This PR isolates these responsibilities by extracting the entire workflow into a decoupled shared/backend package under a new BackendDetector interface. Individual I/O concerns (PATH lookups, container tracking, systemd tracking, and Kubernetes evaluations) have been split into targeted structural interfaces. This allows test environments to mock system states safely through fakes without invoking actual sub-processes. GetCommand() has been simplified into a 12-line validation pass that coordinates caching alongside a distinct Detect() call.

Additionally, this change addresses a silent regression where the auto-detection branch's Helm release check failed to pass along the targeted --kubeconfig context, introducing environmental edge-case failures across k3s clusters.

Explicit Backend Precedence Rule:

  1. kubectl execution containing an active deployment matching kubernetesFilter.
  2. podman / podman-remote executing with an actively running instance of the target container.
  3. podman supported by an installed uyuni-server or uyuni-proxy-pod systemd service unit.
  4. kubectl operating against an active Helm release sequence designated as uyuni or uyuni-proxy.

Files changed:

File Status
shared/backend/detector.go New
shared/backend/detector_test.go New
shared/connection.go Modified
shared/connection_test.go Modified
shared/testutils/systemd.go Modified

Note on new files: shared/backend/detector.go and shared/backend/detector_test.go carry the SUSE LLC copyright header consistent with the rest of the project. Is there anything else required a REUSE entry, a changelog fragment, or a specific reviewer for new packages?

Test coverage

  • Unit tests were added

New tests in shared/backend/detector_test.go:

  • Validates execution bounds across explicit backends (podman, podman-remote, kubectl, host) during both active presence and missing state environments within the user's PATH.
  • Isolates and evaluates all rungs of the precedence ladder, including cluster-unreachable scenarios falling through to podman checkpoints.
  • Ensures exact error-string matching and checks structural idempotency characteristics.

New tests in shared/connection_test.go:

  • TestGetCommand: Evaluates an 8-case table tracking routing matrices, fallback triggers, error cascades, and state retention rules.
  • TestGetCommand_DetectorReceivesCorrectArgs: Guarantees downstream propagation integrity for filters, wrappers, and context configurations.

All tests use in-process fakes and run in parallel. No real processes are spawned.

Links

Issue(s): #

Changelogs

  • No changelog needed

Before you merge

Check How to branch and merge properly!

@sonarqubecloud

Copy link
Copy Markdown

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