跳至內容

SinkBinding 參考

API version v1

本主題提供關於 SinkBinding 物件的可設定參數的參考資訊。

支援的參數

SinkBinding 資源支援下列參數

欄位 描述 必要或選用
apiVersion 指定 API 版本,例如 sources.knative.dev/v1 必要
kind 將此資源物件識別為 SinkBinding 物件。 必要
metadata 指定唯一識別 SinkBinding 物件的中繼資料。例如,name 必要
spec 指定此 SinkBinding 物件的組態資訊。 必要
spec.sink 指向解析為 URI 以作為接收器的物件的參考。 必要
spec.subject 指向「執行階段合約」由 Binding 實作增強的資源的參考。 必要
spec.ceOverrides 定義覆寫以控制傳送至接收器的事件的輸出格式和修改。 選用

Subject 參數

Subject 參數參考「執行階段合約」由 Binding 實作增強的資源。

subject 定義支援下列欄位

欄位 描述 必要或選用
apiVersion 參考對象的 API 版本。 必要
kind 參考對象的種類。 必要
namespace 參考對象的命名空間。如果省略,則預設為包含它的物件。 選用
name 參考對象的名稱。 如果設定 selector,則不要使用。
selector 參考對象的選取器。 如果設定 name,則不要使用。
selector.matchExpressions 標籤選取器需求清單。需求之間會執行 AND 運算。 使用 matchExpressionsmatchLabels 其中之一
selector.matchExpressions.key 選取器套用的標籤鍵。 如果使用 matchExpressions,則為必要
selector.matchExpressions.operator 表示鍵與一組值之間的關係。有效的運算子為 InNotInExistsDoesNotExist 如果使用 matchExpressions,則為必要
selector.matchExpressions.values 字串值陣列。如果 operatorInNotIn,則值陣列不得為空。如果 operatorExistsDoesNotExist,則值陣列必須為空。此陣列會在策略性合併修補期間取代。 如果使用 matchExpressions,則為必要
selector.matchLabels 鍵值組的對應。matchLabels 對應中的每個鍵值組都相當於 matchExpressions 的元素,其中鍵欄位為 matchLabels.<key>operatorIn,且 values 陣列只包含 "matchLabels."。需求之間會執行 AND 運算。 使用 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

合約

這會導致在 subject 上設定 K_CE_OVERRIDES 環境變數,如下所示

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

我們使用分析和 Cookie 來瞭解網站流量。您使用我們網站的相關資訊會與 Google 分享以達到此目的。瞭解詳情。