Skip to content

Commit

Permalink
Add Cloud Run v1 Multi-Container Example with New Fields (GoogleCloud…
Browse files Browse the repository at this point in the history
…Platform#7971)

* cloudrun: Add container name field for Services

Adds the template.spec.containers.name field for specifying container
names in Cloud Run v1 Services.

* cloudrun: Update the description of the Service containers field

Updates the description of the Cloud Run v1 Service field
template.spec.containers to reflect that the field is repeated and to
remove other obsolete information.

* cloudrun: Add empty dir volume type for Services

Adds the beta template.spec.volumes.empty_dir field for configuring
ephemeral volumes in Cloud Run v1 Services.

* cloudrun: Add multi-container Service example

Adds an example google_cloud_run_service resource with multiple
containers and a shared empty dir volume. Container dependencies are
specified as a json encoded annotation.
  • Loading branch information
ian-mi authored and Shourya Singh committed May 25, 2023
1 parent 59a4e80 commit a873975
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
31 changes: 27 additions & 4 deletions mmv1/products/cloudrun/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ examples:
cloud_run_service_name: 'cloudrun-srv'
test_env_vars:
project: :PROJECT_NAME
- !ruby/object:Provider::Terraform::Examples
name: 'cloud_run_service_multicontainer'
min_version: beta
primary_resource_id: 'default'
vars:
cloud_run_service_name: 'cloudrun-srv'
test_env_vars:
project: :PROJECT_NAME
virtual_fields:
- !ruby/object:Api::Type::Boolean
name: 'autogenerate_revision_name'
Expand Down Expand Up @@ -342,12 +350,14 @@ properties:
update_verb: :PUT
required: true
description: |-
Container defines the unit of execution for this Revision.
In the context of a Revision, we disallow a number of the fields of
this Container, including: name, ports, and volumeMounts.
Containers defines the unit of execution for this Revision.
default_from_api: true
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: name
description: Name of the container
default_from_api: true
- !ruby/object:Api::Type::String
deprecation_message:
'Not supported by Cloud Run fully managed'
Expand Down Expand Up @@ -773,7 +783,6 @@ properties:
Volume's name.
- !ruby/object:Api::Type::NestedObject
name: secret
required: true
description: |-
The secret's value will be presented as the content of a file whose
name is defined in the item path. If no items are defined, the name of
Expand Down Expand Up @@ -830,6 +839,20 @@ properties:
not specified, the volume defaultMode will be used. This might be in
conflict with other options that affect the file mode, like fsGroup, and
the result can be other mode bits set.
- !ruby/object:Api::Type::NestedObject
name: emptyDir
description: |-
Ephemeral storage which can be backed by real disks (HD, SSD), network storage or memory (i.e. tmpfs). For now only in memory (tmpfs) is supported. It is ephemeral in the sense that when the sandbox is taken down, the data is destroyed with it (it does not persist across sandbox runs).
min_version: beta
properties:
- !ruby/object:Api::Type::String
name: 'medium'
description: |-
The medium on which the data is stored. The default is "" which means to use the node's default medium. Must be an empty string (default) or Memory.
- !ruby/object:Api::Type::String
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: http://kubernetes.io/docs/user-guide/volumes#emptydir.
- !ruby/object:Api::Type::Enum
name: servingState
deprecation_message: 'Not supported by Cloud Run fully managed'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
resource "google_cloud_run_service" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
provider = google-beta

metadata {
annotations = {
"run.googleapis.com/launch-stage" = "BETA"
}
}
template {
metadata {
annotations = {
"run.googleapis.com/container-dependencies" = jsonencode({hello-1 = ["hello-2"]})
}
}
spec {
containers {
name = "hello-1"
ports {
container_port = 8080
}
image = "us-docker.pkg.dev/cloudrun/container/hello"
volume_mounts {
name = "shared-volume"
mount_path = "/mnt/shared"
}
}
containers {
name = "hello-2"
image = "us-docker.pkg.dev/cloudrun/container/hello"
env {
name = "PORT"
value = "8081"
}
startup_probe {
http_get {
port = 8081
}
}
volume_mounts {
name = "shared-volume"
mount_path = "/mnt/shared"
}
}
volumes {
name = "shared-volume"
empty_dir {
medium = "Memory"
size_limit = "128Mi"
}
}
}
}

lifecycle {
ignore_changes = [
metadata[0].annotations["run.googleapis.com/launch-stage"],
]
}
}

0 comments on commit a873975

Please sign in to comment.