Skip to content

refactor(hetzner): decouple provider from viper global config - #879

Merged
cdalar merged 1 commit into
mainfrom
worktree-phase1-hetzner-decouple
Jun 4, 2026
Merged

cdalar merged 1 commit into
mainfrom
worktree-phase1-hetzner-decouple

Conversation

@cdalar

@cdalar cdalar commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add HetznerConfig struct with five fields: Location, VMType, Image, Username, SSHPrivateKey
  • Add Config HetznerConfig field to ProviderHetzner; replace all viper.GetString(...) calls inside the provider with struct field reads
  • Remove viper import from hetzner.go entirely
  • Wire viper → HetznerConfig once in cmd/root.go at provider construction time

Motivation

ProviderHetzner previously called viper.GetString() inline at call sites, coupling it to the global config singleton. This makes the provider unsafe for concurrent use in library contexts (e.g. the planned onctl-platform SaaS backend, where multiple requests construct providers independently). Config is now injected at construction, so the provider is stateless with respect to global state.

Test plan

  • go build ./... — clean
  • go test ./internal/cloud/... — passes
  • Manual: go run . ls with Hetzner config produces same output as before

Add HetznerConfig struct to ProviderHetzner so the provider can be
constructed without the viper global singleton. All five config values
(location, vm type, image, username, ssh key) are now passed in at
construction time from cmd/root.go, making the provider safe for
concurrent use in library contexts.
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.01%. Comparing base (249bde0) to head (b552455).

Files with missing lines Patch % Lines
cmd/root.go 0.00% 7 Missing ⚠️
internal/cloud/hetzner.go 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #879      +/-   ##
==========================================
- Coverage   14.04%   14.01%   -0.03%     
==========================================
  Files          38       38              
  Lines        3411     3418       +7     
==========================================
  Hits          479      479              
- Misses       2881     2888       +7     
  Partials       51       51              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cdalar
cdalar merged commit 0f7fe8b into main Jun 4, 2026
15 checks passed
@cdalar
cdalar deleted the worktree-phase1-hetzner-decouple branch August 19, 2026 13:54
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

⌂ 换网址