Skip to content

Commit

Permalink
Add support for gcsfuse volumes to cloudrun v1 in beta (GoogleCloudPl…
Browse files Browse the repository at this point in the history
…atform#9752)

* Add support for gcsfuse volumes to cloudrun v1 in beta

* Update mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb

Co-authored-by: Stephen Lewis (Burrows) <[email protected]>

* Apply suggestions from code review

Co-authored-by: Stephen Lewis (Burrows) <[email protected]>

* Update docs for gcs csi driver and fix readOnly type.

* fixing yaml format

---------

Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
  • Loading branch information
2 people authored and pengq-google committed May 21, 2024
1 parent 0c90385 commit 9782e68
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
25 changes: 25 additions & 0 deletions mmv1/products/cloudrun/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,31 @@ properties:
name: 'sizeLimit'
description: |-
Limit on the storage usable by this EmptyDir volume. The size limit is also applicable for memory medium. The maximum usage on memory medium EmptyDir would be the minimum value between the SizeLimit specified here and the sum of memory limits of all containers in a pod. This field's values are of the 'Quantity' k8s type: https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/quantity/. The default is nil which means that the limit is undefined. More info: https://kubernetes.io/docs/concepts/storage/volumes/#emptydir.
- !ruby/object:Api::Type::NestedObject
name: csi
description: |-
A filesystem specified by the Container Storage Interface (CSI).
min_version: beta
properties:
- !ruby/object:Api::Type::String
name: 'driver'
required: true
description: |-
Unique name representing the type of file system to be created. Cloud Run supports the following values:
* gcsfuse.run.googleapis.com: Mount a Google Cloud Storage bucket using GCSFuse. This driver requires the
run.googleapis.com/execution-environment annotation to be set to "gen2" and
run.googleapis.com/launch-stage set to "BETA" or "ALPHA".
- !ruby/object:Api::Type::Boolean
name: 'readOnly'
default_from_api: true
description: |-
If true, all mounts created from this volume will be read-only.
- !ruby/object:Api::Type::KeyValuePairs
name: 'volumeAttributes'
description: |-
Driver-specific attributes. The following options are supported for available drivers:
* gcsfuse.run.googleapis.com
* bucketName: The name of the Cloud Storage Bucket that backs this volume. The Cloud Run Service identity must have access to this bucket.
- !ruby/object:Api::Type::Enum
name: servingState
deprecation_message: >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,3 +1013,131 @@ resource "google_cloud_run_service" "default" {
}

<% end -%>

<% unless version == 'ga' -%>

func TestAccCloudRunService_csiVolume(t *testing.T) {
t.Parallel()

project := envvar.GetTestProjectFromEnv()
name := "tftest-cloudrun-" + acctest.RandString(t, 6)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunService_cloudRunServiceWithEmptyDirVolume(name, project),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "status.0.conditions"},
},
{
Config: testAccCloudRunService_cloudRunServiceUpdateWithGcsVolume(name, project,),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "status.0.conditions"},
},
},
})
}


func testAccCloudRunService_cloudRunServiceWithEmptyDirVolume(name, project string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
provider = google-beta
name = "%s"
location = "us-central1"

metadata {
namespace = "%s"
annotations = {
generated-by = "magic-modules"
"run.googleapis.com/launch-stage" = "BETA"
}
}

template {
spec {
containers {
image = "gcr.io/cloudrun/hello"
volume_mounts {
name = "vol1"
mount_path = "/mnt/vol1"
}
}
volumes {
name = "vol1"
empty_dir { size_limit = "256Mi" }
}
}
}

lifecycle {
ignore_changes = [
metadata.0.annotations,
]
}
}
`, name, project)
}

func testAccCloudRunService_cloudRunServiceUpdateWithGcsVolume(name, project string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
provider = google-beta
name = "%s"
location = "us-central1"

metadata {
namespace = "%s"
annotations = {
generated-by = "magic-modules"
"run.googleapis.com/launch-stage" = "BETA"
}
}

template {
metadata {
annotations = {
"run.googleapis.com/execution-environment" = "gen2"
}
}
spec {
containers {
image = "gcr.io/cloudrun/hello"
volume_mounts {
name = "vol1"
mount_path = "/mnt/vol1"
}
}
volumes {
name = "vol1"
csi {
driver = "gcsfuse.run.googleapis.com"
read_only = true
volume_attributes = {
bucketName = "gcp-public-data-landsat"
}
}
}
}
}

lifecycle {
ignore_changes = [
metadata.0.annotations,
]
}
}
`, name, project)
}

<% end -%>

0 comments on commit 9782e68

Please sign in to comment.