Skip to content

Commit bf34199

Browse files
authored
Merge pull request #4451 from PayalJakhar/namespace
namespace for gke-modules
2 parents 4889560 + d53ebf4 commit bf34199

14 files changed

Lines changed: 62 additions & 9 deletions

modules/file-system/gke-persistent-volume/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ No modules.
143143
|------|------|
144144
| [kubectl_manifest.pv](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource |
145145
| [kubectl_manifest.pvc](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource |
146+
| [kubectl_manifest.pvc_namespace](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource |
146147
| [local_file.debug_file](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
147148
| [google_client_config.default](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config) | data source |
148149
| [google_container_cluster.gke_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/container_cluster) | data source |
@@ -156,6 +157,7 @@ No modules.
156157
| <a name="input_filestore_id"></a> [filestore\_id](#input\_filestore\_id) | An identifier for a filestore with the format `projects/{{project}}/locations/{{location}}/instances/{{name}}`. | `string` | `null` | no |
157158
| <a name="input_gcs_bucket_name"></a> [gcs\_bucket\_name](#input\_gcs\_bucket\_name) | The gcs bucket to be used with the persistent volume. | `string` | `null` | no |
158159
| <a name="input_labels"></a> [labels](#input\_labels) | GCE resource labels to be applied to resources. Key-value pairs. | `map(string)` | n/a | yes |
160+
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Kubernetes namespace to deploy the storage PVC/PV | `string` | `"default"` | no |
159161
| <a name="input_network_storage"></a> [network\_storage](#input\_network\_storage) | Network attached storage mount to be configured. | <pre>object({<br/> server_ip = string,<br/> remote_mount = string,<br/> local_mount = string,<br/> fs_type = string,<br/> mount_options = string,<br/> client_install_runner = map(string)<br/> mount_runner = map(string)<br/> })</pre> | n/a | yes |
160162

161163
## Outputs

modules/file-system/gke-persistent-volume/main.tf

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ locals {
5353
filestore_pvc_contents = templatefile(
5454
"${path.module}/templates/filestore-pvc.yaml.tftpl",
5555
{
56-
pv_name = local.pv_name
57-
capacity = "${var.capacity_gb}Gi"
58-
pvc_name = local.pvc_name
59-
labels = local.labels
56+
pv_name = local.pv_name
57+
capacity = "${var.capacity_gb}Gi"
58+
pvc_name = local.pvc_name
59+
labels = local.labels
60+
namespace = var.namespace
6061
}
6162
)
6263

@@ -74,10 +75,11 @@ locals {
7475
gcs_pvc_contents = templatefile(
7576
"${path.module}/templates/gcs-pvc.yaml.tftpl",
7677
{
77-
pv_name = local.pv_name
78-
pvc_name = local.pvc_name
79-
labels = local.labels
80-
capacity = "${var.capacity_gb}Gi"
78+
pv_name = local.pv_name
79+
pvc_name = local.pvc_name
80+
labels = local.labels
81+
capacity = "${var.capacity_gb}Gi"
82+
namespace = var.namespace
8183
}
8284
)
8385

@@ -107,6 +109,14 @@ provider "kubectl" {
107109
load_config_file = false
108110
}
109111

112+
resource "kubectl_manifest" "pvc_namespace" {
113+
count = var.namespace != "default" ? 1 : 0
114+
115+
yaml_body = templatefile("${path.module}/templates/namespace.yaml.tftpl", {
116+
namespace = var.namespace
117+
})
118+
}
119+
110120
resource "kubectl_manifest" "pv" {
111121
yaml_body = local.is_gcs ? local.gcs_pv_contents : local.filestore_pv_contents
112122

@@ -120,5 +130,5 @@ resource "kubectl_manifest" "pv" {
120130

121131
resource "kubectl_manifest" "pvc" {
122132
yaml_body = local.is_gcs ? local.gcs_pvc_contents : local.filestore_pvc_contents
123-
depends_on = [kubectl_manifest.pv]
133+
depends_on = [kubectl_manifest.pv, kubectl_manifest.pvc_namespace]
124134
}

modules/file-system/gke-persistent-volume/templates/filestore-pvc.yaml.tftpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ kind: PersistentVolumeClaim
33
apiVersion: v1
44
metadata:
55
name: ${pvc_name}
6+
namespace: ${namespace}
67
labels:
78
%{~ for key, val in labels ~}
89
${key}: ${val}

modules/file-system/gke-persistent-volume/templates/gcs-pvc.yaml.tftpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
kind: PersistentVolumeClaim
44
metadata:
55
name: ${pvc_name}
6+
namespace: ${namespace}
67
labels:
78
%{~ for key, val in labels ~}
89
${key}: ${val}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: ${namespace}

modules/file-system/gke-persistent-volume/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ variable "labels" {
6060
description = "GCE resource labels to be applied to resources. Key-value pairs."
6161
type = map(string)
6262
}
63+
64+
variable "namespace" {
65+
description = "Kubernetes namespace to deploy the storage PVC/PV"
66+
type = string
67+
default = "default"
68+
}

modules/file-system/gke-storage/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ No resources.
116116
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | An identifier for the GKE cluster in the format `projects/{{project}}/locations/{{location}}/clusters/{{cluster}}` | `string` | n/a | yes |
117117
| <a name="input_labels"></a> [labels](#input\_labels) | GCE resource labels to be applied to resources. Key-value pairs. | `map(string)` | n/a | yes |
118118
| <a name="input_mount_options"></a> [mount\_options](#input\_mount\_options) | Controls the mountOptions for dynamically provisioned PersistentVolumes of this storage class. | `string` | `null` | no |
119+
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Kubernetes namespace to deploy the storage PVC/PV | `string` | `"default"` | no |
119120
| <a name="input_private_vpc_connection_peering"></a> [private\_vpc\_connection\_peering](#input\_private\_vpc\_connection\_peering) | The name of the VPC Network peering connection.<br/>If using new VPC, please use community/modules/network/private-service-access to create private-service-access and<br/>If using existing VPC with private-service-access enabled, set this manually follow [user guide](https://cloud.google.com/parallelstore/docs/vpc). | `string` | `null` | no |
120121
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The project ID to host the cluster in. | `string` | n/a | yes |
121122
| <a name="input_pv_mount_path"></a> [pv\_mount\_path](#input\_pv\_mount\_path) | Path within the container at which the volume should be mounted. Must not contain ':'. | `string` | `"/data"` | no |

modules/file-system/gke-storage/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ module "kubectl_apply" {
5757
topology_zones = var.sc_topology_zones
5858
})
5959
},
60+
var.namespace != "default" ? [{
61+
content = templatefile(
62+
"${path.module}/persistent-volume-claim/namespace.yaml.tftpl",
63+
{
64+
namespace = var.namespace
65+
})
66+
}] : [],
6067
# create PersistentVolumeClaim in the cluster
6168
flatten([
6269
for idx in range(var.pvc_count) : [
@@ -69,6 +76,7 @@ module "kubectl_apply" {
6976
capacity = "${var.capacity_gb}Gi"
7077
access_mode = var.access_mode
7178
storage_class_name = local.storage_class_name
79+
namespace = var.namespace
7280
}
7381
)
7482
}

modules/file-system/gke-storage/persistent-volume-claim/hyperdisk-balanced-pvc.yaml.tftpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
---
12
apiVersion: v1
23
kind: PersistentVolumeClaim
34
metadata:
45
name: ${pvc_name}
6+
namespace: ${namespace}
57
labels:
68
%{~ for key, val in labels ~}
79
${key}: ${val}

modules/file-system/gke-storage/persistent-volume-claim/hyperdisk-extreme-pvc.yaml.tftpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
---
12
apiVersion: v1
23
kind: PersistentVolumeClaim
34
metadata:
45
name: ${pvc_name}
6+
namespace: ${namespace}
57
labels:
68
%{~ for key, val in labels ~}
79
${key}: ${val}

0 commit comments

Comments
 (0)