Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds startup_probe field to google_cloud_run_service resource for beta #6532

Merged
merged 22 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions mmv1/products/cloudrun/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,68 @@ objects:
required: true
description: |-
This must match the Name of a Volume.
- !ruby/object:Api::Type::NestedObject
name: startupProbe
min_version: beta
description: |-
Startup probe of application within the container.
All other probes are disabled if a startup probe is provided, until it
succeeds. Container will not be added to service endpoints if the probe fails.
properties:
- !ruby/object:Api::Type::Integer
name: initialDelaySeconds
description: |-
Number of seconds after the container has started before the probe is
initiated.
Defaults to 0 seconds. Minimum value is 0. Maximum value is 240.
rileykarson marked this conversation as resolved.
Show resolved Hide resolved
- !ruby/object:Api::Type::Integer
name: timeoutSeconds
description: |-
Number of seconds after which the probe times out.
Defaults to 1 second. Minimum value is 1. Maximum value is 3600.
Must be smaller than periodSeconds.
- !ruby/object:Api::Type::Integer
name: periodSeconds
description: |-
How often (in seconds) to perform the probe.
Default to 10 seconds. Minimum value is 1. Maximum value is 240.
- !ruby/object:Api::Type::Integer
name: failureThreshold
description: |-
Minimum consecutive failures for the probe to be considered failed after
having succeeded. Defaults to 3. Minimum value is 1.
- !ruby/object:Api::Type::NestedObject
name: tcpSocket
description: |-
TcpSocket speficies an action involving a TCP port.
yanweiguo marked this conversation as resolved.
Show resolved Hide resolved
properties:
- !ruby/object:Api::Type::Integer
name: port
rileykarson marked this conversation as resolved.
Show resolved Hide resolved
description: |-
Port number to access on the container. Number must be in the range 1 to 65535.
- !ruby/object:Api::Type::NestedObject
name: httpGet
description: |-
HttpGet specifies the http request to perform..
properties:
- !ruby/object:Api::Type::String
name: path
yanweiguo marked this conversation as resolved.
Show resolved Hide resolved
description: |-
Path to access on the HTTP server.
- !ruby/object:Api::Type::Array
name: httpHeaders
description: |-
Custom headers to set in the request. HTTP allows repeated headers.
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: name
yanweiguo marked this conversation as resolved.
Show resolved Hide resolved
description: |-
The header field name.
- !ruby/object:Api::Type::String
name: value
description: |-
The header field value.

- !ruby/object:Api::Type::Integer
name: containerConcurrency
Expand Down
14 changes: 14 additions & 0 deletions mmv1/products/cloudrun/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,20 @@ overrides: !ruby/object:Overrides::ResourceOverrides
default_from_api: true
spec.template.spec.containers.resources.limits: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
spec.template.spec.containers.startupProbe: !ruby/object:Overrides::Terraform::PropertyOverride
yanweiguo marked this conversation as resolved.
Show resolved Hide resolved
default_from_api: true
spec.template.spec.containers.startupProbe.initialDelaySeconds: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
spec.template.spec.containers.startupProbe.timeoutSeconds: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
spec.template.spec.containers.startupProbe.periodSeconds: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
spec.template.spec.containers.startupProbe.failureThreshold: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
spec.template.spec.containers.startupProbe.tcpSocket.port: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
yanweiguo marked this conversation as resolved.
Show resolved Hide resolved
spec.template.spec.containers.startupProbe.httpGet.path: !ruby/object:Overrides::Terraform::PropertyOverride
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates that the server will pick a non-fixed default for path when not provided. Is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules are:

  • Not specified -> "/"
  • Empty string -> "/"
  • Other string -> keep the input

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, should we consider a client-side default_value or "/"? That means that if a user doesn't specify anything, they'll get "/" which is the same behaviour as the API.

default_from_api preserves values when the field is unset rather than resets to default, so it's generally undesirable if the default value is fixed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried default_value = "/".

If I don't specify path, the test passed.

If I specify path="", the test failed due to

~ http_get {
        - path = "/" -> null

          # (3 unchanged blocks hidden)
      }

I think Terraform treats "" as an input, not unset.

default_from_api: true
# Terraform autofills the only required field in metadata
metadata: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
Expand Down
35 changes: 35 additions & 0 deletions mmv1/templates/terraform/examples/cloud_run_service_probes.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
data "google_project" "project" {
yanweiguo marked this conversation as resolved.
Show resolved Hide resolved
provider = google-beta
}

resource "google_cloud_run_service" "<%= ctx[:primary_resource_id] %>" {
yanweiguo marked this conversation as resolved.
Show resolved Hide resolved
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
location = "us-central1"
metadata {
annotations = {
"run.googleapis.com/launch-stage" = "BETA"
}
}

template {
spec {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
startup_probe {
initial_delay_seconds = 0
timeout_seconds = 1
period_seconds = 3
failure_threshold = 1
tcpSocket {
port = 8080
}
}
}
}
}

traffic {
percent = 100
latest_revision = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,132 @@ resource "google_cloud_run_service" "default" {
}
`, secretName1, secretName2, name, secretRef, project)
}

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

// this test checks that Terraform does not fail with a 409 recreating the same service
yanweiguo marked this conversation as resolved.
Show resolved Hide resolved
func TestAccCloudRunService_probes(t *testing.T) {
t.Parallel()

project := getTestProjectFromEnv()
name := "tftest-cloudrun-" + randString(t, 6)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudRunService_cloudRunServiceUpdateWithTCPStartupProbe(name, project, "0", "5", "10", "1"),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "status.0.conditions"},
},
{
Config: testAccCloudRunService_cloudRunServiceUpdateWithTCPStartupProbe(name, project, "2", "1", "5", "2"),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "status.0.conditions"},
},
{
Config: testAccCloudRunService_cloudRunServiceUpdateWithHTTPStartupProbe(name, project, `"/"`),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "status.0.conditions"},
},
},
})
}

func testAccCloudRunService_cloudRunServiceUpdateWithTCPStartupProbe(name, project, delay, timeout, peroid, failure_threshold string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
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"
ports {
container_port = 8080
}
startup_probe {
initial_delay_seconds = %s
period_seconds = %s
timeout_seconds = %s
failure_threshold = %s
tcp_socket {
port = 8080
}
}
}
}
}

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

func testAccCloudRunService_cloudRunServiceUpdateWithHTTPStartupProbe(name, project, path string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
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"
startup_probe {
http_get {
path = %s
http_headers {
name = "User-Agent"
value = "magic-modules"
}
}
}
}
}
}

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

<% end -%>