Skip to content

feat(virtualmachine): Add eviction strategy, grace period, and OS type#159

Open
jniedergang wants to merge 5 commits intoharvester:masterfrom
jniedergang:upstream-vm-runtime
Open

feat(virtualmachine): Add eviction strategy, grace period, and OS type#159
jniedergang wants to merge 5 commits intoharvester:masterfrom
jniedergang:upstream-vm-runtime

Conversation

@jniedergang
Copy link

@jniedergang jniedergang commented Feb 9, 2026

Summary

  • Make eviction strategy configurable (was hardcoded to LiveMigrateIfPossible)
  • Add termination_grace_period_seconds for graceful shutdown control
  • Add os_type annotation for KVM guest optimizations

related to harvester/harvester#10035

Test plan

  • Unit tests pass: go test ./pkg/importer/ -run TestVMRuntimeImport
  • golangci-lint clean (only pre-existing gosec warnings in bootstrap/http.go)
  • go fmt clean
  • go generate (tfplugindocs) clean
  • Functional test on Harvester v1.7.1:
    • Created VM with eviction_strategy=None, termination_grace_period_seconds=60 — verified via kubectl get vm
    • os_type computed field reads correctly (empty when no annotation set)
    • Idempotence: terraform plan shows 0 changes
    • terraform destroy — VM cleaned up

@jniedergang jniedergang force-pushed the upstream-vm-runtime branch 2 times, most recently from 81fe719 to 34d1a75 Compare February 10, 2026 21:10
@brandboat brandboat self-requested a review February 12, 2026 07:57
@mergify
Copy link

mergify bot commented Feb 13, 2026

This pull request is now in conflict. Could you fix it @jniedergang? 🙏

@mergify
Copy link

mergify bot commented Feb 13, 2026

This pull request is now in conflict. Could you fix it @jniedergang? 🙏

Copy link

Copilot AI left a comment

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 extends the harvester_virtualmachine Terraform resource to expose additional KubeVirt runtime options (eviction strategy, termination grace period, and OS type annotation) instead of relying on hardcoded defaults, improving configurability and import/read behavior.

Changes:

  • Added eviction_strategy, termination_grace_period_seconds, and os_type fields to the VM schema and constants.
  • Implemented constructor support to write these fields into the KubeVirt VM spec/annotations.
  • Extended importer/state getter plus unit + acceptance tests to cover the new runtime options.

Reviewed changes

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

Show a summary per file
File Description
pkg/importer/resource_virtualmachine_importer.go Import/read support for eviction strategy, termination grace period, and OS type.
pkg/importer/resource_virtualmachine_importer_test.go Unit test coverage for new importer accessors and defaults.
pkg/constants/constants_virtualmachine.go Adds new Terraform field keys and the Harvester OS annotation key constant.
internal/provider/virtualmachine/schema_virtualmachine.go Exposes new runtime options in the Terraform resource schema.
internal/provider/virtualmachine/resource_virtualmachine_constructor.go Writes the new runtime options into the VM spec/annotations during create/update.
internal/tests/resource_virtualmachine_test.go Adds acceptance test for the new runtime options and updates the test config builder.

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

@jniedergang jniedergang force-pushed the upstream-vm-runtime branch 3 times, most recently from ac268a7 to 732cd80 Compare March 5, 2026 15:00
@mergify
Copy link

mergify bot commented Mar 6, 2026

This pull request is now in conflict. Could you fix it @jniedergang? 🙏

Terraform Provider Developer added 4 commits March 6, 2026 17:28
Make eviction strategy configurable (was hardcoded to LiveMigrateIfPossible).
Add termination_grace_period_seconds for graceful shutdown control.
Add os_type annotation for KVM guest optimizations.

Signed-off-by: Terraform Provider Developer <terraform@harvester.local>
…nds and update docs

Add ValidateFunc: validation.IntAtLeast(0) to reject negative values
for termination_grace_period_seconds. Add missing field documentation
for eviction_strategy, termination_grace_period_seconds, and os_type.

Signed-off-by: Terraform Provider Developer <terraform@harvester.local>
- Extract hardcoded defaults into shared constants
  (DefaultEvictionStrategy, DefaultTerminationGracePeriodSeconds)
- Use constants in schema, importer, and tests to avoid drift
- Remove Required:true from os_type processor to not override
  server-provided values when field is unset
- Fix test builder to use *int for terminationGracePeriodSeconds,
  allowing testing of value 0

Signed-off-by: Terraform Provider Developer <terraform@harvester.local>
Fix staticcheck QF1012 lint findings in test builder.

Signed-off-by: Terraform Provider Developer <terraform@harvester.local>
@jniedergang jniedergang force-pushed the upstream-vm-runtime branch from 381cef6 to 759ba5d Compare March 6, 2026 16:29
Prevents InternalValidate error on schedule_backup data source.

Signed-off-by: Terraform Provider Developer <terraform@harvester.local>
@jniedergang
Copy link
Author

Ran functional tests on Harvester v1.7.1:

  • Created VM with eviction_strategy=None, termination_grace_period_seconds=60
  • Verified via kubectl: terminationGracePeriodSeconds: 60, evictionStrategy: None
  • os_type computed field reads correctly (empty string when no harvesterhci.io/os annotation)
  • Idempotence: terraform plan shows 0 changes
  • terraform destroy succeeded

Updated test plan in PR description accordingly.

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