Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add support for vSAN unmap #1745

Merged
merged 3 commits into from
Sep 9, 2022
Merged

Conversation

SlimYang
Copy link
Collaborator

@SlimYang SlimYang commented Sep 7, 2022

Description

This change adds the feature to support the vSAN unmap feature. In this code change, the vsan_unmap_enabled field is introduced, which maps to the vSAN enable state. By enabling the feature, vSAN can recognize the Trim/Unmap command from GuestOS and reclaim the storage space that is mapped to a deleted vSAN object. The introduction for the unmap feature is recorded here: https://core.vmware.com/resource/vsan-space-efficiency-technologies.

Acceptance tests

  • Have you added an acceptance test for the functionality being added?
  • Have you run the acceptance tests on this branch?

Output from acceptance testing:

$ make testacc TESTARGS="-run=TestAccResourceVSphereComputeCluster_vsanUnmapEnabledwithVsanEnabled"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccResourceVSphereComputeCluster_vsanUnmapEnabledwithVsanEnabled -timeout 240m
?   	github.com/hashicorp/terraform-provider-vsphere	[no test files]
=== RUN   TestAccResourceVSphereComputeCluster_vsanUnmapEnabledwithVsanEnabled
--- PASS: TestAccResourceVSphereComputeCluster_vsanUnmapEnabledwithVsanEnabled (246.46s)
PASS
ok  	github.com/hashicorp/terraform-provider-vsphere/vsphere	246.483s
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/administrationroles	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/clustercomputeresource	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/computeresource	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/customattribute	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/datacenter	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/datastore	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/dvportgroup	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/envbrowse	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/folder	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/hostsystem	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/network	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/nsx	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/ovfdeploy	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/provider	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/resourcepool	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/spbm	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/storagepod	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/structure	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/testhelper	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/utils	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vappcontainer	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/viapi	0.031s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/virtualdisk	0.023s [no tests to run]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/virtualmachine	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vsanclient	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vsansystem	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/virtualdevice	0.010s [no tests to run]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/vmworkflow	[no test files]


$ make testacc TESTARGS="-run=TestAccResourceVSphereComputeCluster_vsanUnmapDisabledwithVsanDisabled" 
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccResourceVSphereComputeCluster_vsanUnmapDisabledwithVsanDisabled -timeout 240m
?   	github.com/hashicorp/terraform-provider-vsphere	[no test files]
=== RUN   TestAccResourceVSphereComputeCluster_vsanUnmapDisabledwithVsanDisabled
--- PASS: TestAccResourceVSphereComputeCluster_vsanUnmapDisabledwithVsanDisabled (90.33s)
PASS
ok  	github.com/hashicorp/terraform-provider-vsphere/vsphere	90.355s
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/administrationroles	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/clustercomputeresource	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/computeresource	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/customattribute	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/datacenter	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/datastore	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/dvportgroup	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/envbrowse	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/folder	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/hostsystem	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/network	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/nsx	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/ovfdeploy	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/provider	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/resourcepool	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/spbm	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/storagepod	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/structure	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/testhelper	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/utils	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vappcontainer	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/viapi	0.033s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/virtualdisk	0.010s [no tests to run]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/virtualmachine	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vsanclient	[no test files]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vsansystem	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/virtualdevice	0.011s [no tests to run]
?   	github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/vmworkflow	[no test files]

Release Note

Release note for CHANGELOG:

resource/compute_cluster: Add support for vSAN unmap

References

#1744

This change adds the feature to supporte the vSAN unmap feature. In
this code change, the vsan_unmap_enabled field is introduced, which
maps to the vSAN enable state. By enabling the feature, vSAN can
recognize the Trim/Unmap command from guestOS and relaim the storage
space that is mapped to a deleted vSAN object.
@github-actions github-actions bot added documentation Type: Documentation provider Type: Provider size/l Relative Sizing: Large labels Sep 7, 2022
@SlimYang SlimYang mentioned this pull request Sep 7, 2022
4 tasks
@tenthirtyam tenthirtyam changed the title feat: add support for toggling vSAN unmap feature. feat: add support for vSAN unmap. Sep 7, 2022
@tenthirtyam tenthirtyam added this to the v2.3.0 milestone Sep 7, 2022
@tenthirtyam tenthirtyam linked an issue Sep 7, 2022 that may be closed by this pull request
4 tasks
@tenthirtyam tenthirtyam self-requested a review September 7, 2022 08:06
@tenthirtyam tenthirtyam added needs-review Status: Pull Request Needs Review area/storage Area: Storage area/clustering Area: Clustering labels Sep 8, 2022
@tenthirtyam tenthirtyam changed the title feat: add support for vSAN unmap. feat: add support for vSAN unmap Sep 8, 2022
Copy link
Collaborator

@tenthirtyam tenthirtyam left a comment

Choose a reason for hiding this comment

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

Great work, @SlimYang - just one comment that needs clarification in TestAccResourceVSphereComputeCluster_vsanUnmapDisabledwithVsanDisabled for:

...
			{
 				Config: testAccResourceVSphereComputeClusterConfigVSANUnmapDisabledwithVsanDisabled(),
 				Check: resource.ComposeTestCheckFunc(
 					testAccResourceVSphereComputeClusterCheckExists(true),
 					testAccResourceVSphereComputeClusterCheckVsanEnabled(false),
 					testAccResourceVSphereComputeClusterCheckUnmapEnabled(true),
			}
...

Ryan Johnson
Senior Staff Solutions Architect | Product Engineering @ VMware, Inc.

vsphere/resource_vsphere_compute_cluster_test.go Outdated Show resolved Hide resolved
@tenthirtyam tenthirtyam added waiting-response Status: Waiting on a Response and removed needs-review Status: Pull Request Needs Review labels Sep 8, 2022
Updates `TestAccResourceVSphereComputeCluster_vsanUnmapDisabledwithVsanDisabled` tests to use correct values.
Copy link
Collaborator

@tenthirtyam tenthirtyam left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

Terraform Configuration:
terraform {
  required_providers {
    vsphere = {
      source  = "local/hashicorp/vsphere"
      version = "2.3.0"
    }
  }
  required_version = ">= 1.2.5"
}

variable "vsphere_server" {
  default = "10.168.185.142"
}

variable "vsphere_user" {
  default = "administrator@vsphere.local"
}

variable "vsphere_password" {
  default = "************"
}

provider "vsphere" {
  user                 = var.vsphere_user
  password             = var.vsphere_password
  vsphere_server       = var.vsphere_server
  allow_unverified_ssl = true
}

variable "hosts" {
  default = [
    "10.168.184.233",
    "10.168.186.71",
    "10.168.188.241",
    "10.168.182.119",
    "10.168.180.107",
    "10.168.178.213"
  ]
}

data "vsphere_datacenter" "datacenter" {
  name = "vsan-dc"
}

data "vsphere_host" "hosts" {
  count         = length(var.hosts)
  name          = var.hosts[count.index]
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

resource "vsphere_compute_cluster" "cluster" {
  name                                 = "vsan-cluster"
  datacenter_id                        = data.vsphere_datacenter.datacenter.id
  host_system_ids                      = data.vsphere_host.hosts.*.id
  drs_enabled                          = "true"
  drs_automation_level                 = "fullyAutomated"
  ha_enabled                           = false
  vsan_enabled                         = true
  vsan_unmap_enabled                   = true
  vsan_dedup_enabled                   = true
  vsan_compression_enabled             = true
  vsan_performance_enabled             = false
  vsan_network_diagnostic_mode_enabled = false
  vsan_verbose_mode_enabled            = false
}
Results:
terraform apply --auto-approve
data.vsphere_datacenter.datacenter: Reading...
data.vsphere_datacenter.datacenter: Read complete after 0s [id=datacenter-28]
data.vsphere_host.hosts[1]: Reading...
data.vsphere_host.hosts[5]: Reading...
data.vsphere_host.hosts[0]: Reading...
data.vsphere_host.hosts[4]: Reading...
data.vsphere_host.hosts[2]: Reading...
data.vsphere_host.hosts[3]: Reading...
data.vsphere_host.hosts[5]: Read complete after 1s [id=host-37]
data.vsphere_host.hosts[1]: Read complete after 1s [id=host-39]
data.vsphere_host.hosts[3]: Read complete after 1s [id=host-46]
data.vsphere_host.hosts[0]: Read complete after 1s [id=host-41]
data.vsphere_host.hosts[2]: Read complete after 1s [id=host-34]
data.vsphere_host.hosts[4]: Read complete after 1s [id=host-49]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # vsphere_compute_cluster.cluster will be created
  + resource "vsphere_compute_cluster" "cluster" {
      + datacenter_id                                         = "datacenter-28"
      + dpm_automation_level                                  = "manual"
      + dpm_enabled                                           = false
      + dpm_threshold                                         = 3
      + drs_automation_level                                  = "fullyAutomated"
      + drs_enable_vm_overrides                               = true
      + drs_enabled                                           = true
      + drs_migration_threshold                               = 3
      + drs_scale_descendants_shares                          = "disabled"
      + ha_admission_control_host_failure_tolerance           = 1
      + ha_admission_control_performance_tolerance            = 100
      + ha_admission_control_policy                           = "resourcePercentage"
      + ha_admission_control_resource_percentage_auto_compute = true
      + ha_admission_control_resource_percentage_cpu          = 100
      + ha_admission_control_resource_percentage_memory       = 100
      + ha_admission_control_slot_policy_explicit_cpu         = 32
      + ha_admission_control_slot_policy_explicit_memory      = 100
      + ha_datastore_apd_recovery_action                      = "none"
      + ha_datastore_apd_response                             = "disabled"
      + ha_datastore_apd_response_delay                       = 180
      + ha_datastore_pdl_response                             = "disabled"
      + ha_enabled                                            = false
      + ha_heartbeat_datastore_policy                         = "allFeasibleDsWithUserPreference"
      + ha_host_isolation_response                            = "none"
      + ha_host_monitoring                                    = "enabled"
      + ha_vm_component_protection                            = "enabled"
      + ha_vm_dependency_restart_condition                    = "none"
      + ha_vm_failure_interval                                = 30
      + ha_vm_maximum_failure_window                          = -1
      + ha_vm_maximum_resets                                  = 3
      + ha_vm_minimum_uptime                                  = 120
      + ha_vm_monitoring                                      = "vmMonitoringDisabled"
      + ha_vm_restart_priority                                = "medium"
      + ha_vm_restart_timeout                                 = 600
      + host_cluster_exit_timeout                             = 3600
      + host_system_ids                                       = [
          + "host-34",
          + "host-37",
          + "host-39",
          + "host-41",
          + "host-46",
          + "host-49",
        ]
      + id                                                    = (known after apply)
      + name                                                  = "vsan-cluster"
      + proactive_ha_automation_level                         = "Manual"
      + proactive_ha_moderate_remediation                     = "QuarantineMode"
      + proactive_ha_severe_remediation                       = "QuarantineMode"
      + resource_pool_id                                      = (known after apply)
      + vsan_compression_enabled                              = false
      + vsan_dedup_enabled                                    = false
      + vsan_enabled                                          = true
      + vsan_network_diagnostic_mode_enabled                  = false
      + vsan_performance_enabled                              = false
      + vsan_unmap_enabled                                    = true
      + vsan_verbose_mode_enabled                             = false

      + vsan_disk_group {
          + cache   = (known after apply)
          + storage = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
vsphere_compute_cluster.cluster: Creating...
vsphere_compute_cluster.cluster: Still creating... [10s elapsed]
vsphere_compute_cluster.cluster: Still creating... [20s elapsed]
vsphere_compute_cluster.cluster: Still creating... [30s elapsed]
vsphere_compute_cluster.cluster: Still creating... [40s elapsed]
vsphere_compute_cluster.cluster: Still creating... [50s elapsed]
vsphere_compute_cluster.cluster: Still creating... [1m0s elapsed]
vsphere_compute_cluster.cluster: Still creating... [1m10s elapsed]
vsphere_compute_cluster.cluster: Still creating... [1m20s elapsed]
vsphere_compute_cluster.cluster: Still creating... [1m30s elapsed]
vsphere_compute_cluster.cluster: Still creating... [1m40s elapsed]
vsphere_compute_cluster.cluster: Still creating... [1m50s elapsed]
vsphere_compute_cluster.cluster: Still creating... [2m0s elapsed]
vsphere_compute_cluster.cluster: Still creating... [2m10s elapsed]
vsphere_compute_cluster.cluster: Still creating... [2m20s elapsed]
vsphere_compute_cluster.cluster: Still creating... [2m30s elapsed]
vsphere_compute_cluster.cluster: Creation complete after 2m39s [id=domain-c53]

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

Desktop/untitled folder/vsan via 💠 default took 2m44s 

@tenthirtyam
Copy link
Collaborator

Will merge once the final CI checks complete once more - CodeQL is still in progress. ¯_(ツ)_/¯

Ryan

@github-actions github-actions bot removed the waiting-response Status: Waiting on a Response label Sep 9, 2022
@tenthirtyam
Copy link
Collaborator

Had to make an empty commit to "kick" CodeQL from a stuck state. Checks have now passed.

@tenthirtyam tenthirtyam merged commit 9e43935 into hashicorp:main Sep 9, 2022
tenthirtyam pushed a commit that referenced this pull request Sep 9, 2022
Updates `CHANGELOG.md` to include the feature provided in #1745.

Signed-off-by: Ryan Johnson <johnsonryan@vmware.com>
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
area/clustering Area: Clustering area/storage Area: Storage documentation Type: Documentation provider Type: Provider size/l Relative Sizing: Large
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for vSAN Unmap feature
2 participants