Skip to content

Conversation

@Hazanel
Copy link
Contributor

@Hazanel Hazanel commented Dec 11, 2025

Summary by CodeRabbit

Release Notes

  • New Features
    • HyperV provider support is now available, enabling users to add HyperV infrastructure providers with built-in credential handling and secure secret management.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Walkthrough

The changes add HyperV provider support to the system, including a new provider creation workflow with secret management, input validation of required options, and registration of hyperv as a valid provider type in the CLI validation framework.

Changes

Cohort / File(s) Change Summary
HyperV Provider Implementation
pkg/cmd/create/provider/create.go, pkg/cmd/create/provider/hyperv/hyperv.go, pkg/cmd/create/provider/hyperv/secrets.go
Added complete HyperV provider creation workflow: imported hyperv package with new case in provider switch; implemented CreateProvider orchestrating validation, secret creation/cleanup, provider resource creation, and ownership setup; added helper functions for Kubernetes secret creation and OwnerReference management with error handling.
Provider Type Validation
pkg/util/flags/provider_type.go
Registered "hyperv" as valid static provider type in validation list, error messages, and GetValidValues for CLI auto-completion and inspection.

Sequence Diagram

sequenceDiagram
    participant User
    participant CreateProvider as CreateProvider<br/>(hyperv)
    participant Validate as Validate<br/>Options
    participant SecretMgmt as Secret<br/>Management
    participant K8sClient as Kubernetes<br/>Client
    participant DynClient as Dynamic<br/>Client

    User->>CreateProvider: Call CreateProvider()
    CreateProvider->>Validate: Validate name, namespace,<br/>URL, credentials
    alt Validation fails
        Validate-->>CreateProvider: Error
        CreateProvider-->>User: Return error
    end
    Validate-->>CreateProvider: OK
    CreateProvider->>CreateProvider: Build Provider object<br/>(type: hyperv)
    
    alt No existing secret provided
        CreateProvider->>SecretMgmt: Create new secret
        SecretMgmt->>K8sClient: Create Secret resource<br/>(username, password)
        alt Secret creation fails
            K8sClient-->>SecretMgmt: Error
            SecretMgmt-->>CreateProvider: Error
            CreateProvider-->>User: Return error
        end
        K8sClient-->>SecretMgmt: Secret created
        SecretMgmt->>CreateProvider: Return secret reference
    else Use existing secret
        CreateProvider->>CreateProvider: Wire existing secret<br/>to Provider
    end
    
    CreateProvider->>DynClient: Create Provider resource
    alt Provider creation fails
        DynClient-->>CreateProvider: Error
        alt Secret was created
            CreateProvider->>SecretMgmt: Cleanup secret
            SecretMgmt->>K8sClient: Delete secret
        end
        CreateProvider-->>User: Return error
    end
    DynClient-->>CreateProvider: Provider created
    
    alt Secret was created
        CreateProvider->>SecretMgmt: Set OwnerReference
        SecretMgmt->>K8sClient: Patch secret with<br/>OwnerReference
        K8sClient-->>SecretMgmt: OK
        SecretMgmt-->>CreateProvider: OK
    end
    
    CreateProvider-->>User: Return Provider & Secret
Loading

Estimated Code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Error handling paths: Review secret cleanup logic and cascading error handling when provider creation fails after secret creation
  • Kubernetes API interactions: Verify correct client usage for secret creation, patching, and deletion operations
  • Ownership reference setup: Ensure OwnerReference metadata is correctly applied between secret and provider resources
  • Input validation: Confirm all required provider options are properly validated before workflow execution

Poem

🐰 A hypervisor hops into the fold,
With secrets tucked safe and stories retold,
VMs dance on Windows with grace,
Kubernetes weaves them into place!
Ownership bound, through patches we've sewn,
The provider is here, and now we have grown!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Adding HyperV provider' accurately and concisely describes the main change - introduction of HyperV provider support across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
pkg/cmd/create/provider/hyperv/hyperv.go (1)

19-38: Consider whether InsecureSkipTLS and CACert options are applicable for HyperV.

The validation only requires name, namespace, URL, username, and password. Other providers (like vsphere, generic) also support InsecureSkipTLS and CACert options for TLS configuration. If HyperV connections can involve TLS (e.g., WinRM over HTTPS), consider whether these options should be supported.

If HyperV exclusively uses SMB shares without TLS requirements, this is fine as-is.

pkg/cmd/create/provider/hyperv/secrets.go (1)

67-87: Using MergePatch replaces existing ownerReferences.

MergePatchType will replace the entire ownerReferences array rather than appending to it. This is fine for freshly created secrets (which have no existing ownerReferences), but be aware of this behavior if this function is ever reused for secrets that might have pre-existing owner references.

For future-proofing, StrategicMergePatchType would append to the array, but since this code path only applies to newly created secrets, the current implementation is correct.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9db3619 and 53f6c40.

📒 Files selected for processing (4)
  • pkg/cmd/create/provider/create.go (2 hunks)
  • pkg/cmd/create/provider/hyperv/hyperv.go (1 hunks)
  • pkg/cmd/create/provider/hyperv/secrets.go (1 hunks)
  • pkg/util/flags/provider_type.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
pkg/cmd/create/provider/create.go (2)
pkg/cmd/create/provider/hyperv/hyperv.go (1)
  • CreateProvider (91-151)
pkg/cmd/create/provider/generic/generic.go (1)
  • CreateProvider (146-204)
pkg/cmd/create/provider/hyperv/hyperv.go (3)
pkg/cmd/create/provider/providerutil/options.go (1)
  • ProviderOptions (4-29)
pkg/util/client/client.go (2)
  • GetDynamicClient (108-120)
  • SecretsGVR (86-90)
pkg/cmd/create/provider/create.go (1)
  • Create (22-97)
pkg/cmd/create/provider/hyperv/secrets.go (1)
pkg/util/client/client.go (1)
  • GetKubernetesClientset (123-135)
🔇 Additional comments (5)
pkg/cmd/create/provider/create.go (1)

66-67: LGTM!

The HyperV provider case is correctly integrated into the switch statement, following the same pattern as other providers like vsphere and ova.

pkg/util/flags/provider_type.go (1)

27-28: LGTM!

The addition of "hyperv" to static types is consistent with how "ec2" is handled. The type is correctly added in all three locations: staticTypes validation, error message, and GetValidValues for auto-completion.

pkg/cmd/create/provider/hyperv/hyperv.go (2)

56-88: LGTM!

The createTypedProvider function correctly handles the typed-to-unstructured-to-typed conversion flow with proper error handling.


90-151: LGTM!

The CreateProvider function follows the established pattern from other providers with proper validation, secret handling, error cleanup, and ownership binding.

pkg/cmd/create/provider/hyperv/secrets.go (1)

18-49: LGTM!

The createSecret function correctly creates an opaque Secret with proper labels and uses GenerateName for unique naming.

@yaacov yaacov merged commit b2339d6 into yaacov:main Dec 11, 2025
2 checks passed
@yaacov
Copy link
Owner

yaacov commented Dec 12, 2025

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.

2 participants