Skip to content

Commit

Permalink
Adds liveness_probe field to google_cloud_run_service resource fo…
Browse files Browse the repository at this point in the history
…r beta (#6677)

* add liveness probe

* fix comment and tests

* Update mmv1/products/cloudrun/api.yaml

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

* Update mmv1/products/cloudrun/api.yaml

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

* allow_empty_object: true

Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
  • Loading branch information
yanweiguo and melinath authored Oct 14, 2022
1 parent 4f1df0a commit e2da1b7
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 5 deletions.
66 changes: 66 additions & 0 deletions mmv1/products/cloudrun/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ objects:
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.
More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
properties:
- !ruby/object:Api::Type::Integer
name: initialDelaySeconds
Expand Down Expand Up @@ -658,6 +660,7 @@ objects:
- template.0.spec.0.containers.0.startup_probe.0.tcp_socket
- template.0.spec.0.containers.0.startup_probe.0.http_get
send_empty_value: true
allow_empty_object: true
properties:
- !ruby/object:Api::Type::Integer
name: port
Expand All @@ -671,6 +674,69 @@ objects:
- template.0.spec.0.containers.0.startup_probe.0.tcp_socket
- template.0.spec.0.containers.0.startup_probe.0.http_get
send_empty_value: true
allow_empty_object: true
properties:
- !ruby/object:Api::Type::String
name: path
description: |-
Path to access on the HTTP server. If set, it should not be empty string.
default_value: "/"
- !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
description: |-
The header field name.
required: true
- !ruby/object:Api::Type::String
name: value
description: |-
The header field value.
default_value: ""
send_empty_value: true
- !ruby/object:Api::Type::NestedObject
name: livenessProbe
min_version: beta
description: |-
Periodic probe of container liveness. Container will be restarted if the probe fails. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
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 3600.
default_value: 0
- !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 period_seconds.
default_value: 1
- !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 3600.
default_value: 10
- !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.
default_value: 3
- !ruby/object:Api::Type::NestedObject
name: httpGet
description: |-
HttpGet specifies the http request to perform.
send_empty_value: true
allow_empty_object: true
properties:
- !ruby/object:Api::Type::String
name: path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ resource "google_cloud_run_service" "<%= ctx[:primary_resource_id] %>" {
port = 8080
}
}
liveness_probe {
http_get {
path = "/"
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func TestAccCloudRunService_probes(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudRunService_cloudRunServiceWithEmptyTCPStartupProbe(name, project),
Config: testAccCloudRunService_cloudRunServiceWithEmptyTCPStartupProbeAndHTTPLivenessProbe(name, project),
},
{
ResourceName: "google_cloud_run_service.default",
Expand All @@ -382,7 +382,7 @@ func TestAccCloudRunService_probes(t *testing.T) {
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "status.0.conditions"},
},
{
Config: testAccCloudRunService_cloudRunServiceUpdateWithTCPStartupProbe(name, project, "2", "1", "5", "2"),
Config: testAccCloudRunService_cloudRunServiceUpdateWithTCPStartupProbeAndHTTPLivenessProbe(name, project, "2", "1", "5", "2"),
},
{
ResourceName: "google_cloud_run_service.default",
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestAccCloudRunService_probes(t *testing.T) {
})
}

func testAccCloudRunService_cloudRunServiceWithEmptyTCPStartupProbe(name, project string) string {
func testAccCloudRunService_cloudRunServiceWithEmptyTCPStartupProbeAndHTTPLivenessProbe(name, project string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
name = "%s"
Expand All @@ -436,6 +436,9 @@ resource "google_cloud_run_service" "default" {
startup_probe {
tcp_socket {}
}
liveness_probe {
http_get {}
}
}
}
}
Expand All @@ -449,7 +452,7 @@ resource "google_cloud_run_service" "default" {
`, name, project)
}

func testAccCloudRunService_cloudRunServiceUpdateWithTCPStartupProbe(name, project, delay, timeout, peroid, failure_threshold string) string {
func testAccCloudRunService_cloudRunServiceUpdateWithTCPStartupProbeAndHTTPLivenessProbe(name, project, delay, timeout, peroid, failure_threshold string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
name = "%s"
Expand Down Expand Up @@ -479,6 +482,22 @@ resource "google_cloud_run_service" "default" {
port = 8080
}
}
liveness_probe {
initial_delay_seconds = %s
period_seconds = %s
timeout_seconds = %s
failure_threshold = %s
http_get {
path = "/some-path"
http_headers {
name = "User-Agent"
value = "magic-modules"
}
http_headers {
name = "Some-Name"
}
}
}
}
}
}
Expand All @@ -489,7 +508,7 @@ resource "google_cloud_run_service" "default" {
]
}
}
`, name, project, delay, peroid, timeout, failure_threshold)
`, name, project, delay, peroid, timeout, failure_threshold, delay, peroid, timeout, failure_threshold)
}

func testAccCloudRunService_cloudRunServiceUpdateWithEmptyHTTPStartupProbe(name, project string) string {
Expand Down

0 comments on commit e2da1b7

Please sign in to comment.