Skip to content

Commit ea8ebb7

Browse files
author
SharonRaphael.c
committed
Adding fs_group_policy field for kubernetes_csi_driver
1 parent db9abdf commit ea8ebb7

File tree

10 files changed

+65
-1
lines changed

10 files changed

+65
-1
lines changed

docs/resources/csi_driver.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Required:
5050

5151
Optional:
5252

53+
- `fs_group_policy` (String) Defines if the underlying volume supports changing ownership and permission of the volume before being mounted. Defaults to `ReadWriteOnceWithFSType`. Valid options are `File`, `None`, and `ReadWriteOnceWithFSType`.
5354
- `pod_info_on_mount` (Boolean) Indicates that the CSI volume driver requires additional pod information (like podName, podUID, etc.) during mount operations
5455
- `volume_lifecycle_modes` (List of String) Defines what kind of volumes this CSI volume driver supports
5556

@@ -68,6 +69,7 @@ resource "kubernetes_csi_driver" "example" {
6869
attach_required = true
6970
pod_info_on_mount = true
7071
volume_lifecycle_modes = ["Ephemeral"]
72+
fs_group_policy = "File"
7173
}
7274
}
7375
```

docs/resources/csi_driver_v1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Required:
5050

5151
Optional:
5252

53+
- `fs_group_policy` (String) Defines if the underlying volume supports changing ownership and permission of the volume before being mounted. Defaults to `ReadWriteOnceWithFSType`. Valid options are `File`, `None`, and `ReadWriteOnceWithFSType`.
5354
- `pod_info_on_mount` (Boolean) Indicates that the CSI volume driver requires additional pod information (like podName, podUID, etc.) during mount operations
5455
- `volume_lifecycle_modes` (List of String) Defines what kind of volumes this CSI volume driver supports
5556

@@ -68,6 +69,7 @@ resource "kubernetes_csi_driver_v1" "example" {
6869
attach_required = true
6970
pod_info_on_mount = true
7071
volume_lifecycle_modes = ["Ephemeral"]
72+
fs_group_policy = "File"
7173
}
7274
}
7375
```

examples/resources/csi_driver/example_1.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ resource "kubernetes_csi_driver" "example" {
77
attach_required = true
88
pod_info_on_mount = true
99
volume_lifecycle_modes = ["Ephemeral"]
10+
fs_group_policy = "File"
1011
}
1112
}

examples/resources/csi_driver_v1/example_1.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ resource "kubernetes_csi_driver_v1" "example" {
77
attach_required = true
88
pod_info_on_mount = true
99
volume_lifecycle_modes = ["Ephemeral"]
10+
fs_group_policy = "File"
1011
}
1112
}

kubernetes/resource_kubernetes_csi_driver_v1.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ func resourceKubernetesCSIDriverV1() *schema.Resource {
6464
}, false),
6565
},
6666
},
67+
"fs_group_policy": {
68+
Type: schema.TypeString,
69+
Description: "Defines if the underlying volume supports changing ownership and permission of the volume before being mounted. Defaults to `ReadWriteOnceWithFSType`. Valid options are `File`, `None`, and `ReadWriteOnceWithFSType`.",
70+
Optional: true,
71+
Default: "ReadWriteOnceWithFSType",
72+
ValidateFunc: validation.StringInSlice([]string{
73+
string(storage.ReadWriteOnceWithFSTypeFSGroupPolicy),
74+
string(storage.NoneFSGroupPolicy),
75+
string(storage.FileFSGroupPolicy),
76+
}, false),
77+
},
6778
},
6879
},
6980
},

kubernetes/resource_kubernetes_csi_driver_v1_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestAccKubernetesCSIDriverV1_basic(t *testing.T) {
3838
resource.TestCheckResourceAttr(resourceName, "spec.0.attach_required", "true"),
3939
resource.TestCheckResourceAttr(resourceName, "spec.0.pod_info_on_mount", "true"),
4040
resource.TestCheckResourceAttr(resourceName, "spec.0.volume_lifecycle_modes.0", "Ephemeral"),
41+
resource.TestCheckResourceAttr(resourceName, "spec.0.fs_group_policy", "File"),
4142
),
4243
},
4344
{
@@ -107,6 +108,7 @@ func testAccKubernetesCSIDriverV1BasicConfig(name string, attached bool) string
107108
attach_required = %[2]t
108109
pod_info_on_mount = %[2]t
109110
volume_lifecycle_modes = ["Ephemeral"]
111+
fs_group_policy = "File"
110112
}
111113
}
112114
`, name, attached)

kubernetes/resource_kubernetes_csi_driver_v1beta1.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import (
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
16-
storage "k8s.io/api/storage/v1beta1"
16+
1717
"k8s.io/apimachinery/pkg/api/errors"
18+
19+
storage "k8s.io/api/storage/v1beta1"
1820
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1921
pkgApi "k8s.io/apimachinery/pkg/types"
2022
)
@@ -60,6 +62,17 @@ func resourceKubernetesCSIDriverV1Beta1() *schema.Resource {
6062
}, false),
6163
},
6264
},
65+
"fs_group_policy": {
66+
Type: schema.TypeString,
67+
Description: "Defines if the underlying volume supports changing ownership and permission of the volume before being mounted. Defaults to `ReadWriteOnceWithFSType`. Valid options are `File`, `None`, and `ReadWriteOnceWithFSType`.",
68+
Optional: true,
69+
Default: "ReadWriteOnceWithFSType",
70+
ValidateFunc: validation.StringInSlice([]string{
71+
string(storage.ReadWriteOnceWithFSTypeFSGroupPolicy),
72+
string(storage.NoneFSGroupPolicy),
73+
string(storage.FileFSGroupPolicy),
74+
}, false),
75+
},
6376
},
6477
},
6578
},

kubernetes/resource_kubernetes_csi_driver_v1beta1_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestAccKubernetesCSIDriverV1Beta1_basic(t *testing.T) {
3737
resource.TestCheckResourceAttr(resourceName, "spec.0.attach_required", "true"),
3838
resource.TestCheckResourceAttr(resourceName, "spec.0.pod_info_on_mount", "true"),
3939
resource.TestCheckResourceAttr(resourceName, "spec.0.volume_lifecycle_modes.0", "Ephemeral"),
40+
resource.TestCheckResourceAttr(resourceName, "spec.0.fs_group_policy", "File"),
4041
),
4142
},
4243
{
@@ -107,6 +108,7 @@ func testAccKubernetesCSIDriverBasicV1Beta1Config(name string, attached bool) st
107108
attach_required = %[2]t
108109
pod_info_on_mount = %[2]t
109110
volume_lifecycle_modes = ["Ephemeral"]
111+
fs_group_policy = "File"
110112
}
111113
}
112114
`, name, attached)

kubernetes/structure_csi_driver.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func expandCSIDriverSpec(l []interface{}) storage.CSIDriverSpec {
2828
obj.VolumeLifecycleModes = expandCSIDriverVolumeLifecycleModes(v)
2929
}
3030

31+
if v, ok := in["fs_group_policy"].(string); ok && v != "" {
32+
obj.FSGroupPolicy = ptr.To(storage.FSGroupPolicy(v))
33+
}
34+
3135
return obj
3236
}
3337

@@ -52,6 +56,10 @@ func flattenCSIDriverSpec(in storage.CSIDriverSpec) []interface{} {
5256
att["volume_lifecycle_modes"] = in.VolumeLifecycleModes
5357
}
5458

59+
if in.FSGroupPolicy != nil {
60+
att["fs_group_policy"] = in.FSGroupPolicy
61+
}
62+
5563
return []interface{}{att}
5664
}
5765

@@ -78,5 +86,12 @@ func patchCSIDriverSpec(keyPrefix, pathPrefix string, d *schema.ResourceData) *P
7886
})
7987
}
8088

89+
if d.HasChange(keyPrefix + "fs_group_policy") {
90+
ops = append(ops, &ReplaceOperation{
91+
Path: pathPrefix + "/fsGroupPolicy",
92+
Value: d.Get(keyPrefix + "fs_group_policy").(string),
93+
})
94+
}
95+
8196
return &ops
8297
}

kubernetes/structure_csi_driver_v1.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func expandCSIDriverV1Spec(l []interface{}) storage.CSIDriverSpec {
2828
obj.VolumeLifecycleModes = expandCSIDriverV1VolumeLifecycleModes(v)
2929
}
3030

31+
if v, ok := in["fs_group_policy"].(string); ok && v != "" {
32+
obj.FSGroupPolicy = ptr.To(storage.FSGroupPolicy(v))
33+
}
34+
3135
return obj
3236
}
3337

@@ -52,6 +56,10 @@ func flattenCSIDriverV1Spec(in storage.CSIDriverSpec) []interface{} {
5256
att["volume_lifecycle_modes"] = in.VolumeLifecycleModes
5357
}
5458

59+
if in.FSGroupPolicy != nil {
60+
att["fs_group_policy"] = in.FSGroupPolicy
61+
}
62+
5563
return []interface{}{att}
5664
}
5765

@@ -78,5 +86,12 @@ func patchCSIDriverV1Spec(keyPrefix, pathPrefix string, d *schema.ResourceData)
7886
})
7987
}
8088

89+
if d.HasChange(keyPrefix + "fs_group_policy") {
90+
ops = append(ops, &ReplaceOperation{
91+
Path: pathPrefix + "/fsGroupPolicy",
92+
Value: d.Get(keyPrefix + "fs_group_policy").(string),
93+
})
94+
}
95+
8196
return &ops
8297
}

0 commit comments

Comments
 (0)