Skip to content

Commit

Permalink
implement update feature and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shuyama1 committed Nov 22, 2022
1 parent 11b569c commit cab0a18
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 41 deletions.
96 changes: 61 additions & 35 deletions mmv1/products/cloudrunv2/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ apis_required:
objects:
- !ruby/object:Api::Resource
name: "Job"
input: true
base_url: projects/{{project}}/locations/{{location}}/jobs
self_link: projects/{{project}}/locations/{{location}}/jobs/{{name}}
create_url: projects/{{project}}/locations/{{location}}/jobs?jobId={{name}}
create_verb: :POST
# update_verb: :PATCH
update_verb: :PATCH
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
'https://cloud.google.com/run/docs/'
api: "https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.jobs"
description: |
A Cloud Run Job resource that references a container image which is run to completion.
Expand Down Expand Up @@ -83,10 +84,11 @@ objects:
name: "labels"
description: |-
KRM-style labels for the resource. User-provided labels are shared with Google's billing system, so they can be used to filter, or break down billing charges by team, component, environment, state, etc. For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels Cloud Run will populate some labels with 'run.googleapis.com' or 'serving.knative.dev' namespaces. Those labels are read-only, and user changes will not be preserved.
- !ruby/object:Api::Type::KeyValuePairs
name: "annotations"
description: |-
KRM-style annotations for the resource. Unstructured key value map that may be set by external tools to store and arbitrary metadata. They are not queryable and should be preserved when modifying objects. Cloud Run will populate some annotations using 'run.googleapis.com' or 'serving.knative.dev' namespaces. This field follows Kubernetes annotations' namespacing, limits, and rules. More info: https://kubernetes.io/docs/user-guide/annotations
# blocked on b/244872932
# - !ruby/object:Api::Type::KeyValuePairs
# name: "annotations"
# description: |-
# KRM-style annotations for the resource. Unstructured key value map that may be set by external tools to store and arbitrary metadata. They are not queryable and should be preserved when modifying objects. Cloud Run will populate some annotations using 'run.googleapis.com' or 'serving.knative.dev' namespaces. This field follows Kubernetes annotations' namespacing, limits, and rules. More info: https://kubernetes.io/docs/user-guide/annotations
- !ruby/object:Api::Type::String
name: "client"
description: |
Expand Down Expand Up @@ -130,10 +132,11 @@ objects:
name: "labels"
description: |-
KRM-style labels for the resource.
- !ruby/object:Api::Type::KeyValuePairs
name: "annotations"
description: |-
KRM-style annotations for the resource.
# blocked on b/244872932
# - !ruby/object:Api::Type::KeyValuePairs
# name: "annotations"
# description: |-
# KRM-style annotations for the resource.
- !ruby/object:Api::Type::Integer
name: "parallelism"
description: |-
Expand Down Expand Up @@ -188,16 +191,16 @@ objects:
name: "value"
description: |-
Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the container and any route environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "", and the maximum length is 32768 bytes
exactly_one_of:
- templete.0.templete.0.containers.0.env.0.value
- templete.0.templete.0.containers.0.env.0.valueSource
# exactly_one_of:
# - template.0.template.0.containers.0.env.0.value
# - template.0.template.0.containers.0.env.0.valueSource
- !ruby/object:Api::Type::NestedObject
name: "valueSource"
description: |-
Source for the environment variable's value.
exactly_one_of:
- templete.0.templete.0.containers.0.env.0.value
- templete.0.templete.0.containers.0.env.0.valueSource
# exactly_one_of:
# - template.0.template.0.containers.0.env.0.value
# - template.0.template.0.containers.0.env.0.valueSource
properties:
- !ruby/object:Api::Type::NestedObject
name: "secretKeyRef"
Expand All @@ -222,10 +225,13 @@ objects:
name: "limits"
description: |-
Only memory and CPU are supported. Note: The only supported values for CPU are '1', '2', '4', and '8'. Setting 4 CPU requires at least 2Gi of memory. The values of the map is string form of the 'quantity' k8s type: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go
- !ruby/object:Api::Type::Boolean
name: "cpuIdle"
description: |-
Determines whether CPU should be throttled or not outside of requests.
# API always returns `false` for Job,
# discuss with the service team to fail validation if `true` is specified
# omit the field until it's unblocked
# - !ruby/object:Api::Type::Boolean
# name: "cpuIdle"
# description: |-
# Determines whether CPU should be throttled or not outside of requests.
- !ruby/object:Api::Type::Array
name: "ports"
description: |-
Expand Down Expand Up @@ -271,25 +277,31 @@ objects:
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 for liveness probe is 3600. Maximum value for startup probe is 240. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
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 periodSeconds. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
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 for liveness probe is 3600. Maximum value for startup probe is 240. Must be greater or equal than timeoutSeconds
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. Exactly one of HTTPGet or TCPSocket must be specified.
exactly_one_of:
- templete.0.templete.0.containers.0.livenessProbe.0.httpGet
- templete.0.templete.0.containers.0.livenessProbe.0.tcpSocket
send_empty_value: true
allow_empty_object: true
# exactly_one_of:
# - template.0.template.0.containers.0.livenessProbe.0.httpGet
# - template.0.template.0.containers.0.livenessProbe.0.tcpSocket
properties:
- !ruby/object:Api::Type::String
name: "path"
Expand All @@ -311,13 +323,17 @@ objects:
name: value
description: |-
The header field value
default_value: ""
send_empty_value: true
- !ruby/object:Api::Type::NestedObject
name: "tcpSocket"
description: |-
TCPSocket specifies an action involving a TCP port. Exactly one of HTTPGet or TCPSocket must be specified.
exactly_one_of:
- templete.0.templete.0.containers.0.livenessProbe.0.httpGet
- templete.0.templete.0.containers.0.livenessProbe.0.tcpSocket
send_empty_value: true
allow_empty_object: true
# exactly_one_of:
# - template.0.template.0.containers.0.livenessProbe.0.httpGet
# - template.0.template.0.containers.0.livenessProbe.0.tcpSocket
properties:
- !ruby/object:Api::Type::Integer
name: port
Expand All @@ -332,33 +348,39 @@ objects:
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 for liveness probe is 3600. Maximum value for startup probe is 240. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
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 periodSeconds. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
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 for liveness probe is 3600. Maximum value for startup probe is 240. Must be greater or equal than timeoutSeconds
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. Exactly one of HTTPGet or TCPSocket must be specified.
exactly_one_of:
- templete.0.templete.0.containers.startupProbe.0.httpGet
- templete.0.templete.0.containers.startupProbe.0.tcpSocket
send_empty_value: true
allow_empty_object: true
# exactly_one_of:
# - template.0.template.0.containers.startupProbe.0.httpGet
# - template.0.template.0.containers.startupProbe.0.tcpSocket
properties:
- !ruby/object:Api::Type::String
name: "path"
default_value: "/"
description: |-
Path to access on the HTTP server. Defaults to '/'.
- !ruby/object:Api::Type::Array
name: httpHeaders
name: "httpHeaders"
description: |-
Custom headers to set in the request. HTTP allows repeated headers.
item_type: !ruby/object:Api::Type::NestedObject
Expand All @@ -372,13 +394,17 @@ objects:
name: value
description: |-
The header field value
default_value: ""
send_empty_value: true
- !ruby/object:Api::Type::NestedObject
name: "tcpSocket"
description: |-
TCPSocket specifies an action involving a TCP port. Exactly one of HTTPGet or TCPSocket must be specified.
exactly_one_of:
- templete.0.templete.0.containers.startupProbe.0.httpGet
- templete.0.templete.0.containers.startupProbe.0.tcpSocket
send_empty_value: true
allow_empty_object: true
# exactly_one_of:
# - template.0.template.0.containers.startupProbe.0.httpGet
# - template.0.template.0.containers.startupProbe.0.tcpSocket
properties:
- !ruby/object:Api::Type::Integer
name: port
Expand Down Expand Up @@ -503,7 +529,7 @@ objects:
description: |-
type is used to communicate the status of the reconciliation process. See also: https://github.com/knative/serving/blob/main/docs/spec/errors.md#error-conditions-and-reporting Types common to all resources include: * "Ready": True when the Resource is ready.
- !ruby/object:Api::Type::String
name: "status"
name: "state"
output: true
description: |-
State of the condition.
Expand Down
26 changes: 20 additions & 6 deletions mmv1/products/cloudrunv2/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
overrides: !ruby/object:Overrides::ResourceOverrides
Job: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: 'projects/{{project}}/locations/{{location}}/jobs/{{name}}'
base_url: projects/{{project}}/locations/{{location}}/jobs
import_format: ["projects/{{project}}/locations/{{location}}/jobs/{{name}}"]
autogen_async: true
examples:
Expand All @@ -25,8 +24,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_job_name: "cloudrun-job"
test_env_vars:
project: :PROJECT_NAME
- !ruby/object:Provider::Terraform::Examples
name: "cloudrunv2_job_sql"
primary_resource_id: "default"
Expand All @@ -40,14 +37,27 @@ overrides: !ruby/object:Overrides::ResourceOverrides
deletion_protection: "false"
oics_vars_overrides:
deletion_protection: "false"
test_env_vars:
project: :PROJECT_NAME
- !ruby/object:Provider::Terraform::Examples
name: "cloudrunv2_job_vpcaccess"
primary_resource_id: "default"
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_job_name: "cloudrun-job"
vpc_access_connector_name: "run-vpc"
vpc_compute_subnetwork_name: "run-subnetwork"
compute_network_name: "run-network"
- !ruby/object:Provider::Terraform::Examples
name: "cloudrunv2_job_probes"
primary_resource_id: "default"
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-srv%s\", context[\"random_suffix\"])"
vars:
cloud_run_job_name: "cloudrun-job"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'compareSelfLinkOrResourceName'
custom_expand: templates/terraform/custom_expand/resource_from_self_link.go.erb
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
template.parallelism: !ruby/object:Overrides::Terraform::PropertyOverride
launchStage: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.parallelism: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
Expand All @@ -68,4 +78,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
template.template.containers.resources.cpuIdle: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.containers.resources.limits: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.containers.startupProbe: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
template.template.containers.startupProbe.tcpSocket.port: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
27 changes: 27 additions & 0 deletions mmv1/templates/terraform/examples/cloudrunv2_job_probes.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "google_cloud_run_v2_job" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['cloud_run_job_name'] %>"
location = "us-central1"
launch_stage = "BETA"

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

0 comments on commit cab0a18

Please sign in to comment.