github.com/argoproj/argo-events@v1.9.1/docs/eventsources/setup/resource.md (about)

     1  # Resource
     2  
     3  Resource event-source watches change notifications for K8s object and helps sensor trigger the workloads.
     4  
     5  ## Event Structure
     6  
     7  The structure of an event dispatched by the event-source over the eventbus looks like following,
     8  
     9          {
    10              "context": {
    11                "type": "type_of_event_source",
    12                "specversion": "cloud_events_version",
    13                "source": "name_of_the_event_source",
    14                "id": "unique_event_id",
    15                "time": "event_time",
    16                "datacontenttype": "type_of_data",
    17                "subject": "name_of_the_configuration_within_event_source"
    18              },
    19              "data": {
    20                "type": "type_of_the_event", // ADD, UPDATE or DELETE
    21                "body": "resource_body", // JSON format
    22                "group": "resource_group_name",
    23                "version": "resource_version_name",
    24                "resource": "resource_name"
    25              }
    26          }
    27  
    28  ## Specification
    29  
    30  Resource event-source specification is available [here](https://github.com/argoproj/argo-events/blob/master/api/event-source.md#resourceeventsource).
    31  
    32  ## Setup
    33  
    34  1. Create the event source by running the following command.
    35  
    36          kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/resource.yaml
    37  
    38  1. Create the sensor by running the following command.
    39  
    40          kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/resource.yaml
    41  
    42  1. The event source we created in step 1 contains configuration which makes the event-source listen to Argo workflows marked with label `app: my-workflow`.
    43  
    44  1. Lets create a workflow called `my-workflow` with label `app: my-workflow`.
    45  
    46          apiVersion: argoproj.io/v1alpha1
    47          kind: Workflow
    48          metadata:
    49            name: my-workflow
    50            labels:
    51              app: my-workflow
    52          spec:
    53            entrypoint: whalesay
    54            templates:
    55            - name: whalesay
    56              container:
    57                image: docker/whalesay:latest
    58                command: [cowsay]
    59                args: ["hello world"]
    60  
    61  1. Once the `my-workflow` is created, the sensor will trigger the workflow. Run `argo list` to list the triggered workflow.
    62  
    63  ## List Options
    64  
    65  The Resource Event-Source allows to configure the list options through `labels` and `field` selectors for setting up a watch on objects.
    66  
    67  In the example above, we had set up the list option as follows,
    68  
    69          filter:
    70          # labels and filters are meant to provide K8s API options to filter the object list that are being watched.
    71          # Please read https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api for more details.
    72          
    73              # labels provide listing options to K8s API to watch objects
    74              labels:
    75                - key: app
    76                  # Supported operations like ==, !=, etc.
    77                  # Defaults to ==.
    78                  # Refer https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors for more info.
    79                  # optional.
    80                  operation: "=="
    81                  value: my-workflow
    82  
    83  The `key-operation-value` items under the `filter -> labels` are used by the event-source to filter the objects
    84  that are eligible for the watch. So, in the present case, the event-source will set up a watch for those
    85  objects who have label "app: my-workflow". You can add more `key-operation-value` items to the list as per your use-case.
    86  
    87  Similarly, you can pass `field` selectors to the watch list options, e.g.,
    88  
    89        filter:
    90          # labels and filters are meant to provide K8s API options to filter the object list that are being watched.
    91          # Please read https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api for more details.
    92  
    93          # fields provide listing options to K8s API to watch objects
    94          fields:
    95            - key: metadata.name
    96              # Supported operations like ==, !=, <=, >= etc.
    97              # Defaults to ==.
    98              # Refer https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/ for more info.
    99              # optional.
   100              operation: ==
   101              value: my-workflow
   102  
   103  **Note:** The `label` and `fields` under `filter` are used at the time of setting up the watch by the event-source. If you want to filter the objects
   104  based on the `annotations` or some other fields, use the `Data Filters` available in the sensor.
   105  
   106  ## Troubleshoot
   107  
   108  Please read the [FAQ](https://argoproj.github.io/argo-events/FAQ/).