Exemple #1
0
    def CreateTriggerAndSource(self, trigger_obj, trigger_ref, namespace_ref,
                               source_obj, event_type, parameters, broker,
                               target_service, tracker):
        """Create a linked trigger and source pair.

    Trigger and source are linked via a dependency annotation on the trigger
    as well as the opaque knsourcetrigger field in the trigger filter and the
    source override.

    If the passed trigger_obj is not None, then a new trigger is not created,
    only a source.

    Args:
      trigger_obj: trigger.Trigger, the existing trigger or None if no trigger
        already exists.
      trigger_ref: googlecloudsdk.core.resources.Resource, trigger resource.
      namespace_ref: googlecloudsdk.core.resources.Resource, namespace resource.
      source_obj: source.Source. The source object being created.
      event_type: custom_resource_definition.EventTypeDefinition, the event
        type the source will filter by.
      parameters: dict, additional parameters to set on the source spec.
      broker: str, name of the broker to act as a sink for the source.
      target_service: str, name of the Cloud Run service to subscribe to the
        trigger.
      tracker: progress_tracker.StagedProgressTracker to update as the trigger
        is created and becomes ready.
    """
        # Create trigger if it doesn't already exist
        if trigger_obj is None:
            trigger_obj = self.CreateTrigger(trigger_ref, source_obj,
                                             event_type, target_service,
                                             broker)

        # Create source
        self.CreateSource(source_obj, event_type.crd, trigger_obj,
                          namespace_ref, broker, parameters)

        # Wait for source to be Ready == True
        source_ref = util.GetSourceRef(source_obj.name, source_obj.namespace,
                                       event_type.crd)
        source_getter = functools.partial(self.GetSource, source_ref,
                                          event_type.crd)
        poller = UnfailingConditionPoller(source_getter, tracker,
                                          stages.TriggerSourceDependencies())
        util.WaitForCondition(poller, exceptions.SourceCreationError)
        # Manually complete the stage indicating source readiness because we can't
        # track a terminal (Ready) condition in the ConditionPoller.
        tracker.CompleteStage(stages.SOURCE_READY)

        # Wait for trigger to be Ready == True
        trigger_getter = functools.partial(self.GetTrigger, trigger_ref)
        poller = UnfailingConditionPoller(trigger_getter, tracker,
                                          stages.TriggerSourceDependencies())
        util.WaitForCondition(poller, exceptions.TriggerCreationError)
Exemple #2
0
 def PollSource(self, source_obj, event_type, tracker):
     """Wait for source to be Ready == True."""
     source_ref = util.GetSourceRef(source_obj.name, source_obj.namespace,
                                    event_type.crd, True)
     source_getter = functools.partial(self.GetSource, source_ref,
                                       event_type.crd)
     poller = SourceConditionPoller(source_getter, tracker,
                                    stages.TriggerSourceDependencies())
     util.WaitForCondition(poller, exceptions.SourceCreationError)
     # Manually complete the stage indicating source readiness because we can't
     # track the Ready condition in the ConditionPoller.
     tracker.CompleteStage(stages.SOURCE_READY)
Exemple #3
0
    def PollSource(self, source_obj, event_type_obj, tracker):
        """Wait for source to be Ready == True."""
        source_ref = util.GetSourceRef(source_obj.name, source_obj.namespace,
                                       event_type_obj.crd, True)
        source_getter = functools.partial(self.GetSource, source_ref,
                                          event_type_obj.crd)

        # b/179156386 Increase grace period from default of 15 to 45 seconds for
        # sources, because asia-southeast1 and asia-east1's sources are unable to
        # resolve within the default grace period.
        sources_grace_period = datetime.timedelta(seconds=45)
        poller = SourceConditionPoller(
            source_getter,
            tracker,
            dependencies=stages.TriggerSourceDependencies(),
            grace_period=sources_grace_period)
        util.WaitForCondition(poller, exceptions.SourceCreationError)
        # Manually complete the stage indicating source readiness because we can't
        # track the Ready condition in the ConditionPoller.
        tracker.CompleteStage(stages.SOURCE_READY)
Exemple #4
0
 def PollTrigger(self, trigger_ref, tracker):
     """Wait for trigger to be Ready == True."""
     trigger_getter = functools.partial(self.GetTrigger, trigger_ref)
     poller = TriggerConditionPoller(trigger_getter, tracker,
                                     stages.TriggerSourceDependencies())
     util.WaitForCondition(poller, exceptions.TriggerCreationError)