403Webshell
Server IP : 35.236.43.222  /  Your IP : 216.73.216.143
Web Server : Apache
System : Linux order-form-vm-001 5.10.0-37-cloud-amd64 #1 SMP Debian 5.10.247-1 (2025-12-11) x86_64
User : deploy ( 1002)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/lib/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/printers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/printers/worker_printer.py
# -*- coding: utf-8 -*- #
# Copyright 2024 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.
"""Worker-specific printer."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from googlecloudsdk.api_lib.run import service
from googlecloudsdk.command_lib.run.printers import instance_split_printer
from googlecloudsdk.command_lib.run.printers import k8s_object_printer_util as k8s_util
from googlecloudsdk.command_lib.run.printers import revision_printer
from googlecloudsdk.core.console import console_attr
from googlecloudsdk.core.resource import custom_printer_base as cp

WORKER_PRINTER_FORMAT = 'worker'


# TODO(b/322180968): Once Worker API is ready, replace Service related
# references and replace _BuildWorkerHeader with the method in k8s_util.
class WorkerPrinter(cp.CustomPrinterBase):
  """Prints the run Worker in a custom human-readable format.

  Format specific to Cloud Run workers. Only available on Cloud Run commands
  that print workers.
  """

  def _BuildWorkerHeader(self, record):
    con = console_attr.GetConsoleAttr()
    status = con.Colorize(*record.ReadySymbolAndColor())
    try:
      place = 'region ' + record.region
    except KeyError:
      place = 'namespace ' + record.namespace
    return con.Emphasize(
        '{} {} {} in {}'.format(status, 'Worker', record.name, place)
    )

  def _GetRevisionHeader(self, record):
    header = ''
    if record.status is None:
      header = 'Unknown revision'
    else:
      header = 'Revision {}'.format(record.status.latestCreatedRevisionName)
    return console_attr.GetConsoleAttr().Emphasize(header)

  def _RevisionPrinters(self, record):
    """Adds printers for the revision."""
    return cp.Lines([
        self._GetRevisionHeader(record),
        k8s_util.GetLabels(record.template.labels),
        revision_printer.RevisionPrinter.TransformSpec(record.template),
    ])

  def _GetWorkerSettings(self, record):
    """Adds worker-level values."""
    labels = [
        cp.Labeled([
            ('Binary Authorization', k8s_util.GetBinAuthzPolicy(record)),
            (
                'Min Instances',
                record.annotations.get(
                    service.SERVICE_MIN_SCALE_ANNOTATION, ''
                ),
            ),
            (
                'Max Instances',
                record.annotations.get(
                    service.SERVICE_MAX_SCALE_ANNOTATION, ''
                ),
            ),
            (
                'Max Surge',
                record.annotations.get(
                    service.SERVICE_MAX_SURGE_ANNOTATION, ''
                ),
            ),
        ])
    ]

    breakglass_value = k8s_util.GetBinAuthzBreakglass(record)
    if breakglass_value is not None:
      # Show breakglass even if empty, but only if set. There's no skip_none
      # option so this the workaround.
      breakglass_label = cp.Labeled([
          ('Breakglass Justification', breakglass_value),
      ])
      breakglass_label.skip_empty = False
      labels.append(breakglass_label)
    description = k8s_util.GetDescription(record)
    if description is not None:
      description_label = cp.Labeled([
          ('Description', description),
      ])
      labels.append(description_label)
    return cp.Section(labels)

  def Transform(self, record):
    """Transform a worker into the output structure of marker classes."""
    worker_settings = self._GetWorkerSettings(record)
    fmt = cp.Lines([
        self._BuildWorkerHeader(record),
        k8s_util.GetLabels(record.labels),
        ' ',
        instance_split_printer.TransformInstanceSplitFields(record),
        ' ',
        worker_settings,
        (' ' if worker_settings.WillPrintOutput() else ''),
        cp.Labeled([(
            k8s_util.LastUpdatedMessage(record),
            self._RevisionPrinters(record),
        )]),
        k8s_util.FormatReadyMessage(record),
    ])
    return fmt

Youez - 2016 - github.com/yon3zu
LinuXploit