Example #1
0
    def ListRevisions(self, namespace_ref, service_name):
        """List all revisions for the given service.

    Revision list gets sorted by service name and creation timestamp.

    Args:
      namespace_ref: Resource, namespace to list revisions in
      service_name: str, The service for which to list revisions.

    Returns:
      A list of revisions for the given service.
    """
        messages = self._messages_module
        request = messages.RunNamespacesRevisionsListRequest(
            parent=namespace_ref.RelativeName(), )
        if service_name is not None:
            # For now, same as the service name, and keeping compatible with
            # 'service-less' operation.
            request.labelSelector = 'serving.knative.dev/service = {}'.format(
                service_name)
        with metrics.RecordDuration(metric_names.LIST_REVISIONS):
            response = self._client.namespaces_revisions.List(request)

        # Server does not sort the response so we'll need to sort client-side
        revisions = [
            revision.Revision(item, messages) for item in response.items
        ]
        # Newest first
        revisions.sort(key=lambda r: r.creation_timestamp, reverse=True)
        revisions.sort(key=lambda r: r.service_name)
        return revisions
Example #2
0
 def GetRevisionsByNonce(self, namespace_ref, nonce):
     """Return all revisions with the given nonce."""
     messages = self._messages_module
     request = messages.RunNamespacesRevisionsListRequest(
         parent=namespace_ref.RelativeName(),
         labelSelector='{} = {}'.format(NONCE_LABEL, nonce))
     response = self._client.namespaces_revisions.List(request)
     return [revision.Revision(item, messages) for item in response.items]
 def GetRevisionsByNonce(self, namespace_ref, nonce):
   """Return all revisions with the given nonce."""
   messages = self.messages_module
   request = messages.RunNamespacesRevisionsListRequest(
       parent=namespace_ref.RelativeName(),
       labelSelector='{} = {}'.format(revision.NONCE_LABEL, nonce))
   try:
     response = self._client.namespaces_revisions.List(request)
     return [revision.Revision(item, messages) for item in response.items]
   except api_exceptions.InvalidDataFromServerError as e:
     serverless_exceptions.MaybeRaiseCustomFieldMismatch(e)
Example #4
0
    def GetRevision(self, revision_ref):
        """Get the revision.

    Args:
      revision_ref: Resource, revision to get.

    Returns:
      A revision.Revision object.
    """
        messages = self._messages_module
        revision_name = revision_ref.RelativeName()
        request = messages.RunNamespacesRevisionsGetRequest(name=revision_name)
        try:
            with metrics.RecordDuration(metric_names.GET_REVISION):
                response = self._client.namespaces_revisions.Get(request)
            return revision.Revision(response, messages)
        except api_exceptions.HttpNotFoundError:
            return None
Example #5
0
    def ListRevisions(self, namespace_ref, service_name):
        """List all revisions for the given service.

    Args:
      namespace_ref: Resource, namespace to list revisions in
      service_name: str, The service for which to list revisions.

    Returns:
      A list of revisions for the given service.
    """
        messages = self._messages_module
        request = messages.RunNamespacesRevisionsListRequest(
            parent=namespace_ref.RelativeName(), )
        if service_name is not None:
            # For now, same as the service name, and keeping compatible with
            # 'service-less' operation.
            request.labelSelector = 'serving.knative.dev/service = {}'.format(
                service_name)
        with metrics.RecordDuration(metric_names.LIST_REVISIONS):
            response = self._client.namespaces_revisions.List(request)
        return [revision.Revision(item, messages) for item in response.items]
  def GetRevision(self, revision_ref):
    """Get the revision.

    Args:
      revision_ref: Resource, revision to get.

    Returns:
      A revision.Revision object.
    """
    messages = self.messages_module
    revision_name = revision_ref.RelativeName()
    request = messages.RunNamespacesRevisionsGetRequest(
        name=revision_name)
    try:
      with metrics.RecordDuration(metric_names.GET_REVISION):
        response = self._client.namespaces_revisions.Get(request)
      return revision.Revision(response, messages)
    except api_exceptions.InvalidDataFromServerError as e:
      serverless_exceptions.MaybeRaiseCustomFieldMismatch(e)
    except api_exceptions.HttpNotFoundError:
      return None
Example #7
0
    def ListRevisions(self,
                      namespace_ref,
                      service_name,
                      limit=None,
                      page_size=100):
        """List all revisions for the given service.

    Revision list gets sorted by service name and creation timestamp.

    Args:
      namespace_ref: Resource, namespace to list revisions in
      service_name: str, The service for which to list revisions.
      limit: Optional[int], max number of revisions to list.
      page_size: Optional[int], number of revisions to fetch at a time

    Yields:
      Revisions for the given surface
    """
        messages = self.messages_module
        # NB: This is a hack to compensate for apitools not generating this line.
        #     It's necessary to make the URL parameter be "continue".
        encoding.AddCustomJsonFieldMapping(
            messages.RunNamespacesRevisionsListRequest, 'continue_',
            'continue')
        request = messages.RunNamespacesRevisionsListRequest(
            parent=namespace_ref.RelativeName(), )
        if service_name is not None:
            # For now, same as the service name, and keeping compatible with
            # 'service-less' operation.
            request.labelSelector = 'serving.knative.dev/service = {}'.format(
                service_name)
        for result in list_pager.YieldFromList(
                service=self._client.namespaces_revisions,
                request=request,
                limit=limit,
                batch_size=page_size,
                current_token_attribute='continue_',
                next_token_attribute=('metadata', 'continue_'),
                batch_size_attribute='limit'):
            yield revision.Revision(result, messages)
def Revision(msg_module, metadata=None, spec=None, status=None):
    rev_msg = run_v1_messages.Revision()
    rev_msg.metadata = metadata
    rev_msg.spec = spec
    rev_msg.status = status
    return revision.Revision(rev_msg, msg_module)