From facdea073490ecf719f275c7df844a33080585d1 Mon Sep 17 00:00:00 2001 From: Benjamin Kaplan <58792807+bskaplan@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:08:24 -0800 Subject: [PATCH] Add support for gcsfuse volumes to cloudrun v1 in beta (#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) * Apply suggestions from code review Co-authored-by: Stephen Lewis (Burrows) * Update docs for gcs csi driver and fix readOnly type. * fixing yaml format --------- Co-authored-by: Stephen Lewis (Burrows) --- mmv1/products/cloudrun/Service.yaml | 25 ++++ .../resource_cloud_run_service_test.go.erb | 128 ++++++++++++++++++ 2 files changed, 153 insertions(+) diff --git a/mmv1/products/cloudrun/Service.yaml b/mmv1/products/cloudrun/Service.yaml index 99dd210064f2..255447328bd4 100644 --- a/mmv1/products/cloudrun/Service.yaml +++ b/mmv1/products/cloudrun/Service.yaml @@ -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: >- diff --git a/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb b/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb index 7dcd04a4a01c..9ebe3e58fae5 100644 --- a/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb +++ b/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb @@ -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 -%>