Skip to content

Commit

Permalink
ReadWriteOncePod access mode added to PVs (hashicorp#2488)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: BBBmau <[email protected]>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 654deae commit 4f44a9a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2488.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
`resource/kubernetes_persistent_volume_v1`: support `ReadWriteOncePod` access mode for PVs
```
1 change: 1 addition & 0 deletions kubernetes/data_source_kubernetes_persistent_volume_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func dataSourceKubernetesPersistentVolumeV1() *schema.Resource {
"ReadWriteOnce",
"ReadOnlyMany",
"ReadWriteMany",
"ReadWriteOncePod",
}, false),
},
Set: schema.HashString,
Expand Down
1 change: 1 addition & 0 deletions kubernetes/resource_kubernetes_persistent_volume_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func resourceKubernetesPersistentVolumeV1() *schema.Resource {
"ReadWriteOnce",
"ReadOnlyMany",
"ReadWriteMany",
"ReadWriteOncePod",
}, false),
},
Set: schema.HashString,
Expand Down
45 changes: 45 additions & 0 deletions kubernetes/resource_kubernetes_persistent_volume_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions kubernetes/schema_persistent_volume_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func persistentVolumeClaimSpecFields() map[string]*schema.Schema {
"ReadWriteOnce",
"ReadOnlyMany",
"ReadWriteMany",
"ReadWriteOncePod",
}, false),
},
Set: schema.HashString,
Expand Down

0 comments on commit 4f44a9a

Please sign in to comment.