Skip to content

Commit b998852

Browse files
add annotations (#8176) (#14948)
Signed-off-by: Modular Magician <[email protected]>
1 parent a76563b commit b998852

6 files changed

+182
-30
lines changed

.changelog/8176.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:enhancement
2+
3+
cloudrunv2: added fields `annotations` and `template.annotations` to resource `google_cloud_run_v2_job`
4+
```

google/resource_cloud_run_v2_job_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ func testAccCloudRunV2Job_cloudrunv2JobFull(context map[string]interface{}) stri
5151
labels = {
5252
label-1 = "value-1"
5353
}
54+
annotations = {
55+
job-annotation-1 = "job-value-1"
56+
}
5457
client = "client-1"
5558
client_version = "client-version-1"
5659
5760
template {
5861
labels = {
5962
label-1 = "value-1"
6063
}
64+
annotations = {
65+
temp-annotation-1 = "temp-value-1"
66+
}
6167
parallelism = 4
6268
task_count = 4
6369
template {
@@ -117,13 +123,19 @@ resource "google_cloud_run_v2_job" "default" {
117123
labels = {
118124
label-1 = "value-update"
119125
}
126+
annotations = {
127+
job-annotation-1 = "job-value-update"
128+
}
120129
client = "client-update"
121130
client_version = "client-version-update"
122131
123132
template {
124133
labels = {
125134
label-1 = "value-update"
126135
}
136+
annotations = {
137+
temp-annotation-1 = "temp-value-update"
138+
}
127139
parallelism = 2
128140
task_count = 8
129141
template {

google/services/cloudrunv2/resource_cloud_run_v2_job.go

+93-8
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,27 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
525525
},
526526
},
527527
},
528+
"annotations": {
529+
Type: schema.TypeMap,
530+
Optional: true,
531+
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.
532+
533+
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.
534+
All system annotations in v1 now have a corresponding field in v2 ExecutionTemplate.
535+
536+
This field follows Kubernetes annotations' namespacing, limits, and rules.`,
537+
Elem: &schema.Schema{Type: schema.TypeString},
538+
},
528539
"labels": {
529-
Type: schema.TypeMap,
530-
Optional: true,
531-
Description: `KRM-style labels for the resource.`,
532-
Elem: &schema.Schema{Type: schema.TypeString},
540+
Type: schema.TypeMap,
541+
Optional: true,
542+
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,
543+
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
544+
https://cloud.google.com/run/docs/configuring/labels.
545+
546+
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.
547+
All system labels in v1 now have a corresponding field in v2 ExecutionTemplate.`,
548+
Elem: &schema.Schema{Type: schema.TypeString},
533549
},
534550
"parallelism": {
535551
Type: schema.TypeInt,
@@ -546,6 +562,17 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
546562
},
547563
},
548564
},
565+
"annotations": {
566+
Type: schema.TypeMap,
567+
Optional: true,
568+
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.
569+
570+
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.
571+
All system annotations in v1 now have a corresponding field in v2 Job.
572+
573+
This field follows Kubernetes annotations' namespacing, limits, and rules.`,
574+
Elem: &schema.Schema{Type: schema.TypeString},
575+
},
549576
"binary_authorization": {
550577
Type: schema.TypeList,
551578
Optional: true,
@@ -577,10 +604,14 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
577604
Description: `Arbitrary version identifier for the API client.`,
578605
},
579606
"labels": {
580-
Type: schema.TypeMap,
581-
Optional: true,
582-
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.`,
583-
Elem: &schema.Schema{Type: schema.TypeString},
607+
Type: schema.TypeMap,
608+
Optional: true,
609+
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,
610+
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.
611+
612+
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.
613+
All system labels in v1 now have a corresponding field in v2 Job.`,
614+
Elem: &schema.Schema{Type: schema.TypeString},
584615
},
585616
"launch_stage": {
586617
Type: schema.TypeString,
@@ -789,6 +820,12 @@ func resourceCloudRunV2JobCreate(d *schema.ResourceData, meta interface{}) error
789820
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
790821
obj["labels"] = labelsProp
791822
}
823+
annotationsProp, err := expandCloudRunV2JobAnnotations(d.Get("annotations"), d, config)
824+
if err != nil {
825+
return err
826+
} else if v, ok := d.GetOkExists("annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
827+
obj["annotations"] = annotationsProp
828+
}
792829
clientProp, err := expandCloudRunV2JobClient(d.Get("client"), d, config)
793830
if err != nil {
794831
return err
@@ -933,6 +970,9 @@ func resourceCloudRunV2JobRead(d *schema.ResourceData, meta interface{}) error {
933970
if err := d.Set("labels", flattenCloudRunV2JobLabels(res["labels"], d, config)); err != nil {
934971
return fmt.Errorf("Error reading Job: %s", err)
935972
}
973+
if err := d.Set("annotations", flattenCloudRunV2JobAnnotations(res["annotations"], d, config)); err != nil {
974+
return fmt.Errorf("Error reading Job: %s", err)
975+
}
936976
if err := d.Set("client", flattenCloudRunV2JobClient(res["client"], d, config)); err != nil {
937977
return fmt.Errorf("Error reading Job: %s", err)
938978
}
@@ -995,6 +1035,12 @@ func resourceCloudRunV2JobUpdate(d *schema.ResourceData, meta interface{}) error
9951035
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
9961036
obj["labels"] = labelsProp
9971037
}
1038+
annotationsProp, err := expandCloudRunV2JobAnnotations(d.Get("annotations"), d, config)
1039+
if err != nil {
1040+
return err
1041+
} else if v, ok := d.GetOkExists("annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
1042+
obj["annotations"] = annotationsProp
1043+
}
9981044
clientProp, err := expandCloudRunV2JobClient(d.Get("client"), d, config)
9991045
if err != nil {
10001046
return err
@@ -1150,6 +1196,10 @@ func flattenCloudRunV2JobLabels(v interface{}, d *schema.ResourceData, config *t
11501196
return v
11511197
}
11521198

1199+
func flattenCloudRunV2JobAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1200+
return v
1201+
}
1202+
11531203
func flattenCloudRunV2JobClient(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
11541204
return v
11551205
}
@@ -1196,6 +1246,8 @@ func flattenCloudRunV2JobTemplate(v interface{}, d *schema.ResourceData, config
11961246
transformed := make(map[string]interface{})
11971247
transformed["labels"] =
11981248
flattenCloudRunV2JobTemplateLabels(original["labels"], d, config)
1249+
transformed["annotations"] =
1250+
flattenCloudRunV2JobTemplateAnnotations(original["annotations"], d, config)
11991251
transformed["parallelism"] =
12001252
flattenCloudRunV2JobTemplateParallelism(original["parallelism"], d, config)
12011253
transformed["task_count"] =
@@ -1208,6 +1260,10 @@ func flattenCloudRunV2JobTemplateLabels(v interface{}, d *schema.ResourceData, c
12081260
return v
12091261
}
12101262

1263+
func flattenCloudRunV2JobTemplateAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1264+
return v
1265+
}
1266+
12111267
func flattenCloudRunV2JobTemplateParallelism(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
12121268
// Handles the string fixed64 format
12131269
if strVal, ok := v.(string); ok {
@@ -2152,6 +2208,17 @@ func expandCloudRunV2JobLabels(v interface{}, d tpgresource.TerraformResourceDat
21522208
return m, nil
21532209
}
21542210

2211+
func expandCloudRunV2JobAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
2212+
if v == nil {
2213+
return map[string]string{}, nil
2214+
}
2215+
m := make(map[string]string)
2216+
for k, val := range v.(map[string]interface{}) {
2217+
m[k] = val.(string)
2218+
}
2219+
return m, nil
2220+
}
2221+
21552222
func expandCloudRunV2JobClient(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
21562223
return v, nil
21572224
}
@@ -2214,6 +2281,13 @@ func expandCloudRunV2JobTemplate(v interface{}, d tpgresource.TerraformResourceD
22142281
transformed["labels"] = transformedLabels
22152282
}
22162283

2284+
transformedAnnotations, err := expandCloudRunV2JobTemplateAnnotations(original["annotations"], d, config)
2285+
if err != nil {
2286+
return nil, err
2287+
} else if val := reflect.ValueOf(transformedAnnotations); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2288+
transformed["annotations"] = transformedAnnotations
2289+
}
2290+
22172291
transformedParallelism, err := expandCloudRunV2JobTemplateParallelism(original["parallelism"], d, config)
22182292
if err != nil {
22192293
return nil, err
@@ -2249,6 +2323,17 @@ func expandCloudRunV2JobTemplateLabels(v interface{}, d tpgresource.TerraformRes
22492323
return m, nil
22502324
}
22512325

2326+
func expandCloudRunV2JobTemplateAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
2327+
if v == nil {
2328+
return map[string]string{}, nil
2329+
}
2330+
m := make(map[string]string)
2331+
for k, val := range v.(map[string]interface{}) {
2332+
m[k] = val.(string)
2333+
}
2334+
return m, nil
2335+
}
2336+
22522337
func expandCloudRunV2JobTemplateParallelism(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
22532338
return v, nil
22542339
}

google/services/cloudrunv2/resource_cloud_run_v2_service.go

+34-16
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ func ResourceCloudRunV2Service() *schema.Resource {
6363
Elem: &schema.Resource{
6464
Schema: map[string]*schema.Schema{
6565
"annotations": {
66-
Type: schema.TypeMap,
67-
Optional: true,
68-
Description: `KRM-style annotations for the resource.`,
69-
Elem: &schema.Schema{Type: schema.TypeString},
66+
Type: schema.TypeMap,
67+
Optional: true,
68+
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.
69+
70+
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.
71+
All system annotations in v1 now have a corresponding field in v2 RevisionTemplate.
72+
73+
This field follows Kubernetes annotations' namespacing, limits, and rules.`,
74+
Elem: &schema.Schema{Type: schema.TypeString},
7075
},
7176
"containers": {
7277
Type: schema.TypeList,
@@ -476,10 +481,14 @@ If not specified, defaults to the same value as container.ports[0].containerPort
476481
Description: `The sandbox environment to host this Revision. Possible values: ["EXECUTION_ENVIRONMENT_GEN1", "EXECUTION_ENVIRONMENT_GEN2"]`,
477482
},
478483
"labels": {
479-
Type: schema.TypeMap,
480-
Optional: true,
481-
Description: `KRM-style labels for the resource.`,
482-
Elem: &schema.Schema{Type: schema.TypeString},
484+
Type: schema.TypeMap,
485+
Optional: true,
486+
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.
487+
For more information, visit https://cloud.google.com/resource-manager/docs/creating-managing-labels or https://cloud.google.com/run/docs/configuring/labels.
488+
489+
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.
490+
All system labels in v1 now have a corresponding field in v2 RevisionTemplate.`,
491+
Elem: &schema.Schema{Type: schema.TypeString},
483492
},
484493
"max_instance_request_concurrency": {
485494
Type: schema.TypeInt,
@@ -633,10 +642,15 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
633642
},
634643
},
635644
"annotations": {
636-
Type: schema.TypeMap,
637-
Optional: true,
638-
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`,
639-
Elem: &schema.Schema{Type: schema.TypeString},
645+
Type: schema.TypeMap,
646+
Optional: true,
647+
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.
648+
649+
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.
650+
All system annotations in v1 now have a corresponding field in v2 Service.
651+
652+
This field follows Kubernetes annotations' namespacing, limits, and rules.`,
653+
Elem: &schema.Schema{Type: schema.TypeString},
640654
},
641655
"binary_authorization": {
642656
Type: schema.TypeList,
@@ -681,10 +695,14 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
681695
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"]`,
682696
},
683697
"labels": {
684-
Type: schema.TypeMap,
685-
Optional: true,
686-
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.`,
687-
Elem: &schema.Schema{Type: schema.TypeString},
698+
Type: schema.TypeMap,
699+
Optional: true,
700+
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,
701+
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.
702+
703+
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.
704+
All system labels in v1 now have a corresponding field in v2 Service.`,
705+
Elem: &schema.Schema{Type: schema.TypeString},
688706
},
689707
"launch_stage": {
690708
Type: schema.TypeString,

website/docs/r/cloud_run_v2_job.html.markdown

+23-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,18 @@ The following arguments are supported:
321321

322322
* `labels` -
323323
(Optional)
324-
KRM-style labels for the resource.
324+
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,
325+
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
326+
https://cloud.google.com/run/docs/configuring/labels.
327+
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.
328+
All system labels in v1 now have a corresponding field in v2 ExecutionTemplate.
329+
330+
* `annotations` -
331+
(Optional)
332+
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.
333+
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.
334+
All system annotations in v1 now have a corresponding field in v2 ExecutionTemplate.
335+
This field follows Kubernetes annotations' namespacing, limits, and rules.
325336

326337
* `parallelism` -
327338
(Optional)
@@ -693,7 +704,17 @@ The following arguments are supported:
693704

694705
* `labels` -
695706
(Optional)
696-
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.
707+
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,
708+
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.
709+
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.
710+
All system labels in v1 now have a corresponding field in v2 Job.
711+
712+
* `annotations` -
713+
(Optional)
714+
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.
715+
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.
716+
All system annotations in v1 now have a corresponding field in v2 Job.
717+
This field follows Kubernetes annotations' namespacing, limits, and rules.
697718

698719
* `client` -
699720
(Optional)

0 commit comments

Comments
 (0)