feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The gcloud run worker-pools revisions group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import flags
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Revisions(base.Group):
"""View and manage your Cloud Run WorkerPools revisions.
This set of commands can be used to view and manage your existing Cloud Run
WorkerPools revisions.
"""
detailed_help = {
'EXAMPLES': """
To list your existing worker pools revisions, run:
$ {command} list
""",
}

View File

@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for deleting a worker pool revision."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import exceptions
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import pretty_print
from googlecloudsdk.command_lib.run import resource_args
from googlecloudsdk.command_lib.run.v2 import deletion
from googlecloudsdk.command_lib.run.v2 import worker_pools_operations
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Delete(base.Command):
"""Delete a worker pool revision."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To delete a revision `rev1` of a worker pool `worker1` in us-central1:
$ {command} rev1 --region=us-central1 --workerpool=worker1
""",
}
@staticmethod
def CommonArgs(parser):
revision_presentation = presentation_specs.ResourcePresentationSpec(
'WORKER_POOL_REVISION',
resource_args.GetV2WorkerPoolRevisionResourceSpec(prompt=True),
'Worker pool revision to delete.',
required=True,
prefixes=False,
)
concept_parsers.ConceptParser([revision_presentation]).AddToParser(parser)
# TODO(b/366115709): Add WorkerPoolRevision printer.
flags.AddAsyncFlag(parser)
@staticmethod
def Args(parser):
Delete.CommonArgs(parser)
def Run(self, args):
"""Delete a worker pool revision."""
def DeriveRegionalEndpoint(endpoint):
region = args.CONCEPTS.worker_pool_revision.Parse().locationsId
return region + '-' + endpoint
worker_pool_revision_ref = args.CONCEPTS.worker_pool_revision.Parse()
flags.ValidateResource(worker_pool_revision_ref)
console_io.PromptContinue(
message='Revision [{revision}] will be deleted.'.format(
revision=worker_pool_revision_ref.revisionsId
),
throw_if_unattended=True,
cancel_on_no=True,
)
run_client = apis.GetGapicClientInstance(
'run', 'v2', address_override_func=DeriveRegionalEndpoint
)
worker_pools_client = worker_pools_operations.WorkerPoolsOperations(
run_client
)
def DeleteWithExistenceCheck(worker_pool_revision_ref):
response = worker_pools_client.DeleteRevision(worker_pool_revision_ref)
if not response:
raise exceptions.ArgumentError(
'Cannot find revision [{revision}] under worker pool'
' [{worker_pool}] in region [{region}]'.format(
revision=worker_pool_revision_ref.revisionsId,
worker_pool=worker_pool_revision_ref.workerPoolsId,
region=worker_pool_revision_ref.locationsId,
)
)
# TODO: b/390067647 - Use response.result() once the issue is fixed
deletion.Delete(
worker_pool_revision_ref,
worker_pools_client.GetRevision,
DeleteWithExistenceCheck,
args.async_,
)
if args.async_:
pretty_print.Success(
'Revision [{}] is being deleted.'.format(
worker_pool_revision_ref.revisionsId
)
)
else:
log.DeletedResource(worker_pool_revision_ref.revisionsId, 'revision')

View File

@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for obtaining details about a given worker pool revision."""
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import connection_context
from googlecloudsdk.command_lib.run import exceptions
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import resource_args
from googlecloudsdk.command_lib.run import serverless_operations
from googlecloudsdk.command_lib.run.printers import export_printer
from googlecloudsdk.command_lib.run.printers import worker_pool_revision_printer
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
from googlecloudsdk.core.resource import resource_printer
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Describe(base.DescribeCommand):
"""Obtain details about a given worker pool revision."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To describe a revision `rev.1` of a worker pool `worker1` in us-central1:
$ {command} rev.1 --region=us-central1 --workerpool=worker1
""",
}
@staticmethod
def CommonArgs(parser):
flags.AddRegionArg(parser)
revision_presentation = presentation_specs.ResourcePresentationSpec(
'WORKER_POOL_REVISION',
resource_args.GetRevisionResourceSpec(is_worker_pool_revision=True),
'Worker pool revision to describe.',
required=True,
prefixes=False,
)
concept_parsers.ConceptParser([revision_presentation]).AddToParser(parser)
resource_printer.RegisterFormatter(
worker_pool_revision_printer.REVISION_PRINTER_FORMAT,
worker_pool_revision_printer.WorkerPoolRevisionPrinter,
)
parser.display_info.AddFormat(
worker_pool_revision_printer.REVISION_PRINTER_FORMAT
)
resource_printer.RegisterFormatter(
export_printer.EXPORT_PRINTER_FORMAT,
export_printer.ExportPrinter,
)
@staticmethod
def Args(parser):
Describe.CommonArgs(parser)
def Run(self, args):
"""Show details about a revision."""
conn_context = connection_context.GetConnectionContext(
args, flags.Product.RUN, self.ReleaseTrack()
)
revision_ref = args.CONCEPTS.worker_pool_revision.Parse()
with serverless_operations.Connect(conn_context) as client:
wrapped_revision = client.GetRevision(revision_ref)
# If the revision is not a worker pool revision, we should not show it.
if not wrapped_revision or wrapped_revision.worker_pool_name is None:
raise exceptions.ArgumentError(
'Cannot find revision [{}]'.format(revision_ref.revisionsId)
)
return wrapped_revision

View File

@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for listing available worker pool revisions."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.run import commands
from googlecloudsdk.command_lib.run import connection_context
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import platforms
from googlecloudsdk.command_lib.run import pretty_print
from googlecloudsdk.command_lib.run import resource_args
from googlecloudsdk.command_lib.run import serverless_operations
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
from googlecloudsdk.core import log
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class List(commands.List):
"""List available worker pool revisions."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To list all revisions in a worker pool `foo`:
$ {command} --worker-pool=foo
""",
}
@classmethod
def CommonArgs(cls, parser):
worker_pool_presentation = presentation_specs.ResourcePresentationSpec(
'--namespace',
resource_args.GetNamespaceResourceSpec(),
'Namespace to list revisions in.',
required=True,
prefixes=False,
hidden=True,
)
concept_parsers.ConceptParser([worker_pool_presentation]).AddToParser(
parser
)
flags.AddWorkerPoolFlag(parser)
flags.AddRegionArg(parser)
parser.display_info.AddFormat(
'table('
'{ready_column},'
'name:label=REVISION,'
'active.yesno(yes="yes", no=""),'
'worker_pool_name:label=WORKER_POOL:sort=1,'
'creation_timestamp.date("%Y-%m-%d %H:%M:%S %Z"):'
'label=DEPLOYED:sort=2:reverse,'
'author:label="DEPLOYED BY"):({alias})'.format(
ready_column=pretty_print.READY_COLUMN,
alias=commands.SATISFIES_PZS_ALIAS,
)
)
@classmethod
def Args(cls, parser):
cls.CommonArgs(parser)
def _FilterServiceRevisions(self, revisions):
"""Filters out revisions that are service revisions.
Per discussion with jmahood@, we want to make sure that all resources are
self-contained, so none of the describe/list commands should mix the
resource type.
Args:
revisions: List of revisions to filter.
Returns:
List of revisions that are worker pool revisions.
"""
return list(filter(lambda rev: rev.worker_pool_name is not None, revisions))
def Run(self, args):
"""List available revisions."""
label_selector = None
worker_pool_name = args.worker_pool
conn_context = connection_context.GetConnectionContext(
args, flags.Product.RUN, self.ReleaseTrack()
)
namespace_ref = args.CONCEPTS.namespace.Parse()
with serverless_operations.Connect(conn_context) as client:
self.SetCompleteApiEndpoint(conn_context.endpoint)
if platforms.GetPlatform() != platforms.PLATFORM_MANAGED:
location_msg = ' in [{}]'.format(conn_context.cluster_location)
log.status.Print(
'For cluster [{cluster}]{zone}:'.format(
cluster=conn_context.cluster_name,
zone=location_msg if conn_context.cluster_location else '',
)
)
if worker_pool_name is not None:
label_selector = 'run.googleapis.com/workerPool = {}'.format(
worker_pool_name
)
for rev in self._FilterServiceRevisions(
client.ListRevisions(
namespace_ref, label_selector, args.limit, args.page_size
)
):
yield rev

View File

@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Group definition for worker pools revisions logs."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Logs(base.Group):
"""Read logs for Cloud Run worker pools revisions."""
detailed_help = {
'EXAMPLES': """
To tail logs for a worker pool revision, run:
$ {command} tail my-worker-pool-revision
To read logs for a worker pool revision, run:
$ {command} read my-worker-pool-revision
""",
}

View File

@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to read logs for a worker pool revision."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from googlecloudsdk.api_lib.logging import common
from googlecloudsdk.api_lib.logging.formatter import FormatLog
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.logs import read as read_logs_lib
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.core import log
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Read(base.Command):
"""Read logs for a Cloud Run worker pool revision."""
detailed_help = {
'DESCRIPTION': """\
{command} reads log entries. Log entries matching *--log-filter* are
returned in order of decreasing timestamps, most-recent entries first.
If the log entries come from multiple logs, then entries from
different logs might be intermingled in the results.
""",
'EXAMPLES': """\
To read log entries from for a Cloud Run worker pool revision, run:
$ {command} my-revision
To read log entries with severity ERROR or higher, run:
$ {command} my-revision --log-filter="severity>=ERROR"
To read log entries written in a specific time window, run:
$ {command} my-revision --log-filter='timestamp<="2015-05-31T23:59:59Z" AND timestamp>="2015-05-31T00:00:00Z"'
To read up to 10 log entries in your revision payloads that include
the word `SearchText` and format the output in `JSON` format, run:
$ {command} my-revision --log-filter="textPayload:SearchText" --limit=10 --format=json
Detailed information about filters can be found at:
[](https://cloud.google.com/logging/docs/view/advanced_filters)
""",
}
@staticmethod
def Args(parser):
read_logs_lib.LogFilterArgs(parser)
read_logs_lib.LoggingReadArgs(parser)
parser.add_argument(
'revision', help='Name for a Cloud Run worker pool revision.'
)
def Run(self, args):
filters = [args.log_filter] if args.IsSpecified('log_filter') else []
filters.append('resource.labels.revision_name = %s' % args.revision)
filters.append('resource.type = %s \n' % 'cloud_run_worker_pool')
filters.append(
'resource.labels.location = %s \n' % flags.GetRegion(args, prompt=True)
)
filters.append('severity >= DEFAULT \n')
filters += read_logs_lib.MakeTimestampFilters(args)
lines = []
logs = common.FetchLogs(
read_logs_lib.JoinFilters(filters),
order_by=args.order,
limit=args.limit,
)
for log_line in logs:
output_log = FormatLog(log_line)
if output_log:
lines.append(output_log)
for line in reversed(lines):
log.out.Print(line)

View File

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to tail logs for a worker pool revision."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.logs import read as read_logs_lib
from googlecloudsdk.command_lib.run import flags
from googlecloudsdk.command_lib.run import streaming
from googlecloudsdk.core import properties
from googlecloudsdk.core.credentials import store
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Tail(base.BinaryBackedCommand):
"""Tail logs for a Cloud Run worker pool revision."""
detailed_help = {
'DESCRIPTION': """\
{command} tails log-entries for a particular
Cloud Run worker pool revision in real time. The log entries are formatted for
consumption in a terminal.
""",
'EXAMPLES': """\
To tail log entries for a Cloud Run worker pool revision, run:
$ {command} my-revision
To tail log entries with severity ERROR or higher, run:
$ {command} my-revision --log-filter="severity>=ERROR"
Detailed information about filters can be found at:
[](https://cloud.google.com/logging/docs/view/advanced_filters)
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'revision', help='Name for a Cloud Run worker pool revision.'
)
read_logs_lib.LogFilterArgs(parser)
def Run(self, args):
filters = []
if args.IsSpecified('log_filter'):
filters.append(args.log_filter)
filters.append('resource.type=%s' % 'cloud_run_worker_pool')
filters.append('resource.labels.revision_name=%s' % args.revision)
filters.append(
'resource.labels.location=%s' % flags.GetRegion(args, prompt=True)
)
filters.append('severity>=DEFAULT')
project_id = properties.VALUES.core.project.Get(required=True)
filter_str = ' '.join(filters)
command_executor = streaming.LogStreamingWrapper()
response = command_executor(
project_id=project_id,
log_format='run',
log_filter=filter_str,
token=store.GetFreshAccessTokenIfEnabled(),
)
return self._DefaultOperationResponseHandler(response)