Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to provide reserved_memory annotation field in virtual machine #72

Merged
merged 3 commits into from
Feb 13, 2023

Conversation

TachunLin
Copy link
Contributor

@TachunLin TachunLin commented Feb 1, 2023

image

Related issues

harvester/harvester#3402

Test plan

  • Setup test env by https://github.com/harvester/terraform-provider-harvester/wiki/PR-Test-Env-Setup for Reviwer

  • Setup test env by https://github.com/harvester/terraform-provider-harvester/wiki/Use-the-master-head-docker-image-for-testing for Tester

  • Create a test config file in the test container

    resource "harvester_image" "ubuntu20" {
      name      = "ubuntu20"
      namespace = "harvester-public"
    
      display_name = "ubuntu-20.04-server-cloudimg-amd64.img"
      source_type  = "download"
      url          = "http://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img"
    }
    
    resource "harvester_virtualmachine" "ubuntu20" {
      name                 = "ubuntu20"
      namespace            = "default"
      restart_after_update = true
    
      description = "test ubuntu20 raw image"
      tags = {
        ssh-user = "ubuntu"
      }
    
      cpu    = 2
      memory = "2Gi"
    
      efi         = true
      secure_boot = true
    
      run_strategy    = "RerunOnFailure"
      hostname        = "ubuntu20"
      reserved_memory = "100Mi"
      machine_type    = "q35"
    
      network_interface {
        name           = "nic-1"
        wait_for_lease = true
      }
    
      disk {
        name       = "rootdisk"
        type       = "disk"
        size       = "10Gi"
        bus        = "virti
    
    
  • Apply the resource

    terraform apply -auto-approve
    
  • Check the reserved memory filed value can be added in VM config page

…ation page.

(Advanced Options -> Reserved Memory)
@futuretea futuretea self-requested a review February 3, 2023 08:11
@TachunLin
Copy link
Contributor Author

Tested the scenarios to change reserved memory to empty and delete can work as expected
image

Terraform will perform the following actions:

  # harvester_virtualmachine.ubuntu20 will be updated in-place
  ~ resource "harvester_virtualmachine" "ubuntu20" {
        id                   = "default/ubuntu20"
        name                 = "ubuntu20"
      - reserved_memory      = "300Mi" -> null
        tags                 = {
            "ssh-user" = "ubuntu"
        }
        # (13 unchanged attributes hidden)



        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
harvester_virtualmachine.ubuntu20: Modifying... [id=default/ubuntu20]
harvester_virtualmachine.ubuntu20: Still modifying... [id=default/ubuntu20, 10s elapsed]
harvester_virtualmachine.ubuntu20: Modifications complete after 13s [id=default/ubuntu20]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
Terraform will perform the following actions:

  # harvester_virtualmachine.ubuntu20 will be updated in-place
  ~ resource "harvester_virtualmachine" "ubuntu20" {
        id                   = "default/ubuntu20"
        name                 = "ubuntu20"
      - reserved_memory      = "300Mi" -> null
        tags                 = {
            "ssh-user" = "ubuntu"
        }
        # (13 unchanged attributes hidden)



        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
harvester_virtualmachine.ubuntu20: Modifying... [id=default/ubuntu20]
harvester_virtualmachine.ubuntu20: Still modifying... [id=default/ubuntu20, 10s elapsed]
harvester_virtualmachine.ubuntu20: Modifications complete after 19s [id=default/ubuntu20]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

@TachunLin TachunLin requested review from futuretea and removed request for futuretea February 8, 2023 14:57
@futuretea futuretea self-requested a review February 8, 2023 15:19
resource_virtualmachine_constructor.go
Copy link
Contributor

@futuretea futuretea left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

Copy link
Member

@FrankYang0529 FrankYang0529 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

Test create with empty reserved_memory, create and update with non-empty reserved_memory.

@FrankYang0529 FrankYang0529 merged commit 617a7d4 into harvester:master Feb 13, 2023
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.

3 participants