From 4f44a9a11d4f919c0cea65228649ffe332bf5253 Mon Sep 17 00:00:00 2001 From: Aayush Subramaniam <51130346+aayushsss1@users.noreply.github.com> Date: Thu, 25 Jul 2024 03:13:12 +0530 Subject: [PATCH] ReadWriteOncePod access mode added to PVs (#2488) * ReadWriteOncePod access mode support added to PVs * updated documentation * added changelog * add ReadWriteOncePod in gcloud test * create ReadWriteOncePod test --------- Co-authored-by: Mauricio Alvarez Leon <65101411+BBBmau@users.noreply.github.com> Co-authored-by: BBBmau --- .changelog/2488.txt | 3 ++ ..._source_kubernetes_persistent_volume_v1.go | 1 + ...esource_kubernetes_persistent_volume_v1.go | 1 + ...ce_kubernetes_persistent_volume_v1_test.go | 45 +++++++++++++++++++ kubernetes/schema_persistent_volume_claim.go | 1 + 5 files changed, 51 insertions(+) create mode 100644 .changelog/2488.txt diff --git a/.changelog/2488.txt b/.changelog/2488.txt new file mode 100644 index 0000000000..349e803a94 --- /dev/null +++ b/.changelog/2488.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +`resource/kubernetes_persistent_volume_v1`: support `ReadWriteOncePod` access mode for PVs +``` \ No newline at end of file diff --git a/kubernetes/data_source_kubernetes_persistent_volume_v1.go b/kubernetes/data_source_kubernetes_persistent_volume_v1.go index 055062664d..9fad47b977 100644 --- a/kubernetes/data_source_kubernetes_persistent_volume_v1.go +++ b/kubernetes/data_source_kubernetes_persistent_volume_v1.go @@ -36,6 +36,7 @@ func dataSourceKubernetesPersistentVolumeV1() *schema.Resource { "ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany", + "ReadWriteOncePod", }, false), }, Set: schema.HashString, diff --git a/kubernetes/resource_kubernetes_persistent_volume_v1.go b/kubernetes/resource_kubernetes_persistent_volume_v1.go index 241d96e4f8..ec7ce7abec 100644 --- a/kubernetes/resource_kubernetes_persistent_volume_v1.go +++ b/kubernetes/resource_kubernetes_persistent_volume_v1.go @@ -95,6 +95,7 @@ func resourceKubernetesPersistentVolumeV1() *schema.Resource { "ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany", + "ReadWriteOncePod", }, false), }, Set: schema.HashString, diff --git a/kubernetes/resource_kubernetes_persistent_volume_v1_test.go b/kubernetes/resource_kubernetes_persistent_volume_v1_test.go index 9b9c353a1d..de24291935 100644 --- a/kubernetes/resource_kubernetes_persistent_volume_v1_test.go +++ b/kubernetes/resource_kubernetes_persistent_volume_v1_test.go @@ -734,6 +734,31 @@ func TestAccKubernetesPersistentVolumeV1_hostPath_mountOptions(t *testing.T) { }) } +func TestAccKubernetesPersistentVolumeV1_accessMode_ReadWriteOncePod(t *testing.T) { + var conf api.PersistentVolume + randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) + name := fmt.Sprintf("tf-acc-test-%s", randString) + resourceName := "kubernetes_persistent_volume_v1.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: resourceName, + IDRefreshIgnore: []string{"metadata.0.resource_version"}, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckKubernetesPersistentVolumeV1Destroy, + Steps: []resource.TestStep{ + { + Config: testAccKubernetesPersistentVolumeV1Config_accessMode_ReadWriteOncePod(name), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesPersistentVolumeV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "spec.0.access_modes.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.access_modes.0", "ReadWriteOncePod"), + ), + }, + }, + }) +} + func TestAccKubernetesPersistentVolumeV1_csi_basic(t *testing.T) { var conf api.PersistentVolume name := acctest.RandomWithPrefix("tf-acc-test") @@ -1879,6 +1904,26 @@ func testAccKubernetesPersistentVolumeV1Config_hostPath_mountOptions(name string }`, name) } +func testAccKubernetesPersistentVolumeV1Config_accessMode_ReadWriteOncePod(name string) string { + return fmt.Sprintf(`resource "kubernetes_persistent_volume_v1" "test" { + metadata { + name = "%s" + } + spec { + capacity = { + storage = "1Gi" + } + access_modes = ["ReadWriteOncePod"] + mount_options = ["foo"] + persistent_volume_source { + host_path { + path = "/mnt/local-volume" + } + } + } +}`, name) +} + func testAccKubernetesPersistentVolumeV1Config_hostPath_basic(name string) string { return fmt.Sprintf(`resource "kubernetes_persistent_volume_v1" "test" { metadata { diff --git a/kubernetes/schema_persistent_volume_claim.go b/kubernetes/schema_persistent_volume_claim.go index f885a24269..9f07afecfd 100644 --- a/kubernetes/schema_persistent_volume_claim.go +++ b/kubernetes/schema_persistent_volume_claim.go @@ -37,6 +37,7 @@ func persistentVolumeClaimSpecFields() map[string]*schema.Schema { "ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany", + "ReadWriteOncePod", }, false), }, Set: schema.HashString,