跳至内容

SinkBinding 引用

API version v1

本主题提供了有关 SinkBinding 对象可配置参数的参考信息。

支持的参数

SinkBinding 资源支持以下参数

字段 描述 必填或可选
apiVersion 指定 API 版本,例如 sources.knative.dev/v1 必填
kind 将此资源对象标识为 SinkBinding 对象。 必填
metadata 指定唯一标识 SinkBinding 对象的元数据。例如,name 必填
spec 指定此 SinkBinding 对象的配置信息。 必填
spec.sink 对解析为 URI 的对象的引用,该 URI 用作接收器。 必填
spec.subject 对资源的引用,这些资源的“运行时契约”由 Binding 实现增强。 必填
spec.ceOverrides 定义覆盖,以控制发送到接收器的事件的输出格式和修改。 可选

Subject 参数

Subject 参数引用 Binding 实现增强其“运行时契约”的资源。

subject 定义支持以下字段

字段 描述 必填或可选
apiVersion 引用的 API 版本。 必填
kind 引用的类型。 必填
namespace 引用的命名空间。如果省略,则默认为包含它的对象。 可选
name 引用的名称。 如果您配置 selector,请勿使用。
selector 引用的选择器。 如果您配置 name,请勿使用。
selector.matchExpressions 标签选择器要求的列表。这些要求是 ANDed 的。 使用 matchExpressionsmatchLabels 之一
selector.matchExpressions.key 选择器应用到的标签键。 如果使用 matchExpressions,则必填
selector.matchExpressions.operator 表示键与一组值的关系。有效的运算符是 InNotInExistsDoesNotExist 如果使用 matchExpressions,则必填
selector.matchExpressions.values 字符串值的数组。如果 operatorInNotIn,则 values 数组必须非空。如果 operatorExistsDoesNotExist,则 values 数组必须为空。此数组在策略性合并修补期间被替换。 如果使用 matchExpressions,则必填
selector.matchLabels 键值对的映射。matchLabels 映射中的每个键值对等效于 matchExpressions 的一个元素,其中键字段为 matchLabels.<key>,运算符为 In,而 values 数组仅包含“matchLabels。”。这些要求是 ANDed 的。 使用 matchExpressionsmatchLabels 之一

Subject 参数示例

鉴于以下 YAML,选择 default 命名空间中名为 mysubjectDeployment

apiVersion: sources.knative.dev/v1
kind: SinkBinding
metadata:
  name: bind-heartbeat
spec:
  subject:
    apiVersion: apps/v1
    kind: Deployment
    namespace: default
    name: mysubject
  ...

鉴于以下 YAML,选择 default 命名空间中具有 working=example 标签的任何 Job

apiVersion: sources.knative.dev/v1
kind: SinkBinding
metadata:
  name: bind-heartbeat
spec:
  subject:
    apiVersion: batch/v1
    kind: Job
    namespace: default
    selector:
      matchLabels:
        working: example
  ...

鉴于以下 YAML,选择 default 命名空间中具有 working=exampleworking=sample 标签的任何 Pod

apiVersion: sources.knative.dev/v1
kind: SinkBinding
metadata:
  name: bind-heartbeat
spec:
  subject:
    apiVersion: v1
    kind: Pod
    namespace: default
    selector:
      - matchExpression:
        key: working
        operator: In
        values:
          - example
          - sample
  ...

CloudEvent 覆盖

CloudEvent 覆盖定义覆盖,以控制发送到接收器的事件的输出格式和修改。

ceOverrides 定义支持以下字段

字段 描述 必填或可选
extensions 指定在出站事件上添加或覆盖哪些属性。每个 extensions 键值对都在事件上独立设置,作为属性扩展。 可选

注意

仅允许有效的 CloudEvent 属性名称 作为扩展名。您不能从扩展覆盖配置中设置规范定义的属性。例如,您不能修改 type 属性。

CloudEvent 覆盖示例

apiVersion: sources.knative.dev/v1
kind: SinkBinding
metadata:
  name: bind-heartbeat
spec:
  ...
  ceOverrides:
    extensions:
      extra: this is an extra attribute
      additional: 42

契约

这将导致 K_CE_OVERRIDES 环境变量在 subject 上设置如下

{ "extensions": { "extra": "this is an extra attribute", "additional": "42" } }

我们使用分析和 Cookie 来了解网站流量。有关您使用我们网站的信息将与 Google 共享,用于该目的。 了解更多。