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

Add annotations support for v2 Cloud Run Job resource #14948

Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .changelog/8176.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement

cloudrunv2: added fields `annotations` and `template.annotations` to resource `google_cloud_run_v2_job`
```
12 changes: 12 additions & 0 deletions google/resource_cloud_run_v2_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ func testAccCloudRunV2Job_cloudrunv2JobFull(context map[string]interface{}) stri
labels = {
label-1 = "value-1"
}
annotations = {
job-annotation-1 = "job-value-1"
}
client = "client-1"
client_version = "client-version-1"

template {
labels = {
label-1 = "value-1"
}
annotations = {
temp-annotation-1 = "temp-value-1"
}
parallelism = 4
task_count = 4
template {
Expand Down Expand Up @@ -117,13 +123,19 @@ resource "google_cloud_run_v2_job" "default" {
labels = {
label-1 = "value-update"
}
annotations = {
job-annotation-1 = "job-value-update"
}
client = "client-update"
client_version = "client-version-update"

template {
labels = {
label-1 = "value-update"
}
annotations = {
temp-annotation-1 = "temp-value-update"
}
parallelism = 2
task_count = 8
template {
Expand Down
101 changes: 93 additions & 8 deletions google/services/cloudrunv2/resource_cloud_run_v2_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,27 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
},
},
},
"annotations": {
Type: schema.TypeMap,
Optional: true,
Description: `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 API v2 does not support annotations with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected.
All system annotations in v1 now have a corresponding field in v2 ExecutionTemplate.

This field follows Kubernetes annotations' namespacing, limits, and rules.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `KRM-style labels for the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Unstructured key value map that can be used to organize and categorize objects. 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 API v2 does not support labels with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected.
All system labels in v1 now have a corresponding field in v2 ExecutionTemplate.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"parallelism": {
Type: schema.TypeInt,
Expand All @@ -546,6 +562,17 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
},
},
},
"annotations": {
Type: schema.TypeMap,
Optional: true,
Description: `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 API v2 does not support annotations with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected on new resources.
All system annotations in v1 now have a corresponding field in v2 Job.

This field follows Kubernetes annotations' namespacing, limits, and rules.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"binary_authorization": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -577,10 +604,14 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
Description: `Arbitrary version identifier for the API client.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
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.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Unstructured key value map that can be used to organize and categorize objects. 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 API v2 does not support labels with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected.
All system labels in v1 now have a corresponding field in v2 Job.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"launch_stage": {
Type: schema.TypeString,
Expand Down Expand Up @@ -789,6 +820,12 @@ func resourceCloudRunV2JobCreate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
annotationsProp, err := expandCloudRunV2JobAnnotations(d.Get("annotations"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
obj["annotations"] = annotationsProp
}
clientProp, err := expandCloudRunV2JobClient(d.Get("client"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -933,6 +970,9 @@ func resourceCloudRunV2JobRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("labels", flattenCloudRunV2JobLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Job: %s", err)
}
if err := d.Set("annotations", flattenCloudRunV2JobAnnotations(res["annotations"], d, config)); err != nil {
return fmt.Errorf("Error reading Job: %s", err)
}
if err := d.Set("client", flattenCloudRunV2JobClient(res["client"], d, config)); err != nil {
return fmt.Errorf("Error reading Job: %s", err)
}
Expand Down Expand Up @@ -995,6 +1035,12 @@ func resourceCloudRunV2JobUpdate(d *schema.ResourceData, meta interface{}) error
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
annotationsProp, err := expandCloudRunV2JobAnnotations(d.Get("annotations"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
obj["annotations"] = annotationsProp
}
clientProp, err := expandCloudRunV2JobClient(d.Get("client"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1150,6 +1196,10 @@ func flattenCloudRunV2JobLabels(v interface{}, d *schema.ResourceData, config *t
return v
}

func flattenCloudRunV2JobAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCloudRunV2JobClient(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -1196,6 +1246,8 @@ func flattenCloudRunV2JobTemplate(v interface{}, d *schema.ResourceData, config
transformed := make(map[string]interface{})
transformed["labels"] =
flattenCloudRunV2JobTemplateLabels(original["labels"], d, config)
transformed["annotations"] =
flattenCloudRunV2JobTemplateAnnotations(original["annotations"], d, config)
transformed["parallelism"] =
flattenCloudRunV2JobTemplateParallelism(original["parallelism"], d, config)
transformed["task_count"] =
Expand All @@ -1208,6 +1260,10 @@ func flattenCloudRunV2JobTemplateLabels(v interface{}, d *schema.ResourceData, c
return v
}

func flattenCloudRunV2JobTemplateAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCloudRunV2JobTemplateParallelism(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
Expand Down Expand Up @@ -2152,6 +2208,17 @@ func expandCloudRunV2JobLabels(v interface{}, d tpgresource.TerraformResourceDat
return m, nil
}

func expandCloudRunV2JobAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandCloudRunV2JobClient(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -2214,6 +2281,13 @@ func expandCloudRunV2JobTemplate(v interface{}, d tpgresource.TerraformResourceD
transformed["labels"] = transformedLabels
}

transformedAnnotations, err := expandCloudRunV2JobTemplateAnnotations(original["annotations"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAnnotations); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["annotations"] = transformedAnnotations
}

transformedParallelism, err := expandCloudRunV2JobTemplateParallelism(original["parallelism"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2249,6 +2323,17 @@ func expandCloudRunV2JobTemplateLabels(v interface{}, d tpgresource.TerraformRes
return m, nil
}

func expandCloudRunV2JobTemplateAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandCloudRunV2JobTemplateParallelism(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
50 changes: 34 additions & 16 deletions google/services/cloudrunv2/resource_cloud_run_v2_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ func ResourceCloudRunV2Service() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"annotations": {
Type: schema.TypeMap,
Optional: true,
Description: `KRM-style annotations for the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `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 API v2 does not support annotations with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected.
All system annotations in v1 now have a corresponding field in v2 RevisionTemplate.

This field follows Kubernetes annotations' namespacing, limits, and rules.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"containers": {
Type: schema.TypeList,
Expand Down Expand Up @@ -476,10 +481,14 @@ If not specified, defaults to the same value as container.ports[0].containerPort
Description: `The sandbox environment to host this Revision. Possible values: ["EXECUTION_ENVIRONMENT_GEN1", "EXECUTION_ENVIRONMENT_GEN2"]`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `KRM-style labels for the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Unstructured key value map that can be used to organize and categorize objects. 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 API v2 does not support labels with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected.
All system labels in v1 now have a corresponding field in v2 RevisionTemplate.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"max_instance_request_concurrency": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -633,10 +642,15 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
},
},
"annotations": {
Type: schema.TypeMap,
Optional: true,
Description: `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/concepts/overview/working-with-objects/annotations`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `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 API v2 does not support annotations with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected in new resources.
All system annotations in v1 now have a corresponding field in v2 Service.

This field follows Kubernetes annotations' namespacing, limits, and rules.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"binary_authorization": {
Type: schema.TypeList,
Expand Down Expand Up @@ -681,10 +695,14 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
Description: `Provides the ingress settings for this Service. On output, returns the currently observed ingress settings, or INGRESS_TRAFFIC_UNSPECIFIED if no revision is active. Possible values: ["INGRESS_TRAFFIC_ALL", "INGRESS_TRAFFIC_INTERNAL_ONLY", "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER"]`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Map of string keys and values that can be used to organize and categorize objects. 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.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Unstructured key value map that can be used to organize and categorize objects. 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 API v2 does not support labels with 'run.googleapis.com', 'cloud.googleapis.com', 'serving.knative.dev', or 'autoscaling.knative.dev' namespaces, and they will be rejected.
All system labels in v1 now have a corresponding field in v2 Service.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"launch_stage": {
Type: schema.TypeString,
Expand Down
25 changes: 23 additions & 2 deletions website/docs/r/cloud_run_v2_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,18 @@ The following arguments are supported:

* `labels` -
(Optional)
KRM-style labels for the resource.
Unstructured key value map that can be used to organize and categorize objects. 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 API v2 does not support labels with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected.
All system labels in v1 now have a corresponding field in v2 ExecutionTemplate.

* `annotations` -
(Optional)
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 API v2 does not support annotations with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected.
All system annotations in v1 now have a corresponding field in v2 ExecutionTemplate.
This field follows Kubernetes annotations' namespacing, limits, and rules.

* `parallelism` -
(Optional)
Expand Down Expand Up @@ -693,7 +704,17 @@ The following arguments are supported:

* `labels` -
(Optional)
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.
Unstructured key value map that can be used to organize and categorize objects. 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 API v2 does not support labels with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected.
All system labels in v1 now have a corresponding field in v2 Job.

* `annotations` -
(Optional)
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 API v2 does not support annotations with `run.googleapis.com`, `cloud.googleapis.com`, `serving.knative.dev`, or `autoscaling.knative.dev` namespaces, and they will be rejected on new resources.
All system annotations in v1 now have a corresponding field in v2 Job.
This field follows Kubernetes annotations' namespacing, limits, and rules.

* `client` -
(Optional)
Expand Down
Loading