Skip to content

Commit 7d78274

Browse files
feat: [google-cloud-batch] Add run_as_non_root field to allow user's runnable be executed as non root (googleapis#12221)
- [ ] Regenerate this pull request now. BEGIN_COMMIT_OVERRIDE feat: Add `run_as_non_root` field to allow user's runnable be executed as non root feat: Add `tags` field in Job's AllocationPolicy field in v1 feat: Add Batch Image Streaming support for v1 END_COMMIT_OVERRIDE docs: Polish the field descriptions for enableImageStreaming and CloudLoggingOptions PiperOrigin-RevId: 600866696 Source-Link: googleapis/googleapis@78acac9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/61e7a2704e599217151acb9798ca77f29bc50710 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWJhdGNoLy5Pd2xCb3QueWFtbCIsImgiOiI2MWU3YTI3MDRlNTk5MjE3MTUxYWNiOTc5OGNhNzdmMjliYzUwNzEwIn0= --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 29e65f8 commit 7d78274

3 files changed

Lines changed: 73 additions & 8 deletions

File tree

packages/google-cloud-batch/google/cloud/batch_v1/types/job.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ class LogsPolicy(proto.Message):
150150
path.
151151
cloud_logging_option (google.cloud.batch_v1.types.LogsPolicy.CloudLoggingOption):
152152
Optional. Additional settings for Cloud Logging. It will
153-
only take effect when the destination of LogsPolicy is set
154-
to CLOUD_LOGGING.
153+
only take effect when the destination of ``LogsPolicy`` is
154+
set to ``CLOUD_LOGGING``.
155155
"""
156156

157157
class Destination(proto.Enum):
@@ -170,11 +170,26 @@ class Destination(proto.Enum):
170170
PATH = 2
171171

172172
class CloudLoggingOption(proto.Message):
173-
r"""CloudLoggingOption contains additional settings for cloud
174-
logging generated by Batch job.
173+
r"""``CloudLoggingOption`` contains additional settings for Cloud
174+
Logging logs generated by Batch job.
175175
176+
Attributes:
177+
use_generic_task_monitored_resource (bool):
178+
Optional. Set this flag to true to change the `monitored
179+
resource
180+
type <https://cloud.google.com/monitoring/api/resources>`__
181+
for Cloud Logging logs generated by this Batch job from the
182+
```batch.googleapis.com/Job`` <https://cloud.google.com/monitoring/api/resources#tag_batch.googleapis.com/Job>`__
183+
type to the formerly used
184+
```generic_task`` <https://cloud.google.com/monitoring/api/resources#tag_generic_task>`__
185+
type.
176186
"""
177187

188+
use_generic_task_monitored_resource: bool = proto.Field(
189+
proto.BOOL,
190+
number=1,
191+
)
192+
178193
destination: Destination = proto.Field(
179194
proto.ENUM,
180195
number=1,
@@ -422,11 +437,17 @@ class AllocationPolicy(proto.Message):
422437
The network policy.
423438
424439
If you define an instance template in the
425-
InstancePolicyOrTemplate field, Batch will use
426-
the network settings in the instance template
427-
instead of this field.
440+
``InstancePolicyOrTemplate`` field, Batch will use the
441+
network settings in the instance template instead of this
442+
field.
428443
placement (google.cloud.batch_v1.types.AllocationPolicy.PlacementPolicy):
429444
The placement policy.
445+
tags (MutableSequence[str]):
446+
Optional. Tags applied to the VM instances.
447+
448+
The tags identify valid sources or targets for network
449+
firewalls. Each tag must be 1-63 characters long, and comply
450+
with `RFC1035 <https://www.ietf.org/rfc/rfc1035.txt>`__.
430451
"""
431452

432453
class ProvisioningModel(proto.Enum):
@@ -906,6 +927,10 @@ class PlacementPolicy(proto.Message):
906927
number=10,
907928
message=PlacementPolicy,
908929
)
930+
tags: MutableSequence[str] = proto.RepeatedField(
931+
proto.STRING,
932+
number=11,
933+
)
909934

910935

911936
class TaskGroup(proto.Message):
@@ -961,6 +986,14 @@ class TaskGroup(proto.Message):
961986
When true, Batch will configure SSH to allow
962987
passwordless login between VMs running the Batch
963988
tasks in the same TaskGroup.
989+
run_as_non_root (bool):
990+
Optional. If not set or set to false, Batch
991+
will use root user to execute runnables. If set
992+
to true, Batch will make sure to run the
993+
runnables using non-root user. Currently, the
994+
non-root user Batch used is generated by OS
995+
login. Reference:
996+
https://cloud.google.com/compute/docs/oslogin
964997
"""
965998

966999
class SchedulingPolicy(proto.Enum):
@@ -1022,6 +1055,10 @@ class SchedulingPolicy(proto.Enum):
10221055
proto.BOOL,
10231056
number=12,
10241057
)
1058+
run_as_non_root: bool = proto.Field(
1059+
proto.BOOL,
1060+
number=14,
1061+
)
10251062

10261063

10271064
class ServiceAccount(proto.Message):

packages/google-cloud-batch/google/cloud/batch_v1/types/task.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,27 @@ class Container(proto.Message):
325325
Optional password for logging in to a docker registry. If
326326
password matches ``projects/*/secrets/*/versions/*`` then
327327
Batch will read the password from the Secret Manager;
328+
enable_image_streaming (bool):
329+
Optional. If set to true, this container runnable uses Image
330+
streaming.
331+
332+
Use Image streaming to allow the runnable to initialize
333+
without waiting for the entire container image to download,
334+
which can significantly reduce startup time for large
335+
container images.
336+
337+
When ``enableImageStreaming`` is set to true, the container
338+
runtime is `containerd <https://containerd.io/>`__ instead
339+
of Docker. Additionally, this container runnable only
340+
supports the following ``container`` subfields:
341+
``imageUri``, ``commands[]``, ``entrypoint``, and
342+
``volumes[]``; any other ``container`` subfields are
343+
ignored.
344+
345+
For more information about the requirements and limitations
346+
for using Image streaming with Batch, see the
347+
```image-streaming`` sample on
348+
GitHub <https://github.com/GoogleCloudPlatform/batch-samples/tree/main/api-samples/image-streaming>`__.
328349
"""
329350

330351
image_uri: str = proto.Field(
@@ -359,6 +380,10 @@ class Container(proto.Message):
359380
proto.STRING,
360381
number=11,
361382
)
383+
enable_image_streaming: bool = proto.Field(
384+
proto.BOOL,
385+
number=12,
386+
)
362387

363388
class Script(proto.Message):
364389
r"""Script runnable.

packages/google-cloud-batch/tests/unit/gapic/batch_v1/test_batch_service.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,7 @@ def test_create_job_rest(request_type):
25382538
"block_external_network": True,
25392539
"username": "username_value",
25402540
"password": "password_value",
2541+
"enable_image_streaming": True,
25412542
},
25422543
"script": {"path": "path_value", "text": "text_value"},
25432544
"barrier": {"name": "name_value"},
@@ -2592,6 +2593,7 @@ def test_create_job_rest(request_type):
25922593
"task_count_per_node": 2022,
25932594
"require_hosts_file": True,
25942595
"permissive_ssh": True,
2596+
"run_as_non_root": True,
25952597
}
25962598
],
25972599
"allocation_policy": {
@@ -2650,6 +2652,7 @@ def test_create_job_rest(request_type):
26502652
]
26512653
},
26522654
"placement": {"collocation": "collocation_value", "max_distance": 1264},
2655+
"tags": ["tags_value1", "tags_value2"],
26532656
},
26542657
"labels": {},
26552658
"status": {
@@ -2671,7 +2674,7 @@ def test_create_job_rest(request_type):
26712674
"logs_policy": {
26722675
"destination": 1,
26732676
"logs_path": "logs_path_value",
2674-
"cloud_logging_option": {},
2677+
"cloud_logging_option": {"use_generic_task_monitored_resource": True},
26752678
},
26762679
"notifications": [
26772680
{

0 commit comments

Comments
 (0)