knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/apis/duck/README.md (about)

     1  # Duck Types
     2  
     3  Knative leverages duck-typing to interact with resources inside of Kubernetes
     4  without explicit knowledge of the full resource shape. `knative/pkg` defines
     5  three duck types that are used throughout Knative: `Addressable`, `Binding`, and
     6  `Source`.
     7  
     8  For APIs leveraging `ObjectReference`, the context of the resource in question
     9  identifies the duck-type. To enable the case where no `ObjectReference` is used,
    10  we have labeled the Custom Resource Definition with the duck-type. Those labels
    11  are as follows:
    12  
    13  | Label                               | Duck-Type                                                                     |
    14  | ----------------------------------- | ----------------------------------------------------------------------------- |
    15  | `duck.knative.dev/addressable=true` | [Addressable](https://godoc.org/knative.dev/pkg/apis/duck/v1#AddressableType) |
    16  | `duck.knative.dev/binding=true`     | [Binding](https://godoc.org/knative.dev/pkg/apis/duck/v1alpha1#Binding)       |
    17  | `duck.knative.dev/source=true`      | [Source](https://godoc.org/knative.dev/pkg/apis/duck/v1#Source)               |
    18  
    19  ## Addressable Shape
    20  
    21  Addressable is expected to be the following shape:
    22  
    23  ```yaml
    24  apiVersion: group/version
    25  kind: Kind
    26  status:
    27    address:
    28      url: http://host/path?query
    29  ```
    30  
    31  ## Binding Shape
    32  
    33  Binding is expected to be in the following shape:
    34  
    35  (with direct subject)
    36  
    37  ```yaml
    38  apiVersion: group/version
    39  kind: Kind
    40  spec:
    41    subject:
    42      apiVersion: group/version
    43      kind: SomeKind
    44      namespace: the-namespace
    45      name: a-name
    46  ```
    47  
    48  (with indirect subject)
    49  
    50  ```yaml
    51  apiVersion: group/version
    52  kind: Kind
    53  spec:
    54    subject:
    55      apiVersion: group/version
    56      kind: SomeKind
    57      namespace: the-namespace
    58      selector:
    59        matchLabels:
    60          key: value
    61  ```
    62  
    63  ## Source Shape
    64  
    65  Source is expected to be in the following shape:
    66  
    67  (with ref sink)
    68  
    69  ```yaml
    70  apiVersion: group/version
    71  kind: Kind
    72  spec:
    73    sink:
    74      ref:
    75        apiVersion: group/version
    76        kind: AnAddressableKind
    77        name: a-name
    78    ceOverrides:
    79      extensions:
    80        key: value
    81  status:
    82    observedGeneration: 1
    83    conditions:
    84      - type: Ready
    85        status: "True"
    86    sinkUri: http://host
    87  ```
    88  
    89  (with uri sink)
    90  
    91  ```yaml
    92  apiVersion: group/version
    93  kind: Kind
    94  spec:
    95    sink:
    96      uri: http://host/path?query
    97    ceOverrides:
    98      extensions:
    99        key: value
   100  status:
   101    observedGeneration: 1
   102    conditions:
   103      - type: Ready
   104        status: "True"
   105    sinkUri: http://host/path?query
   106  ```
   107  
   108  (with ref and uri sink)
   109  
   110  ```yaml
   111  apiVersion: group/version
   112  kind: Kind
   113  spec:
   114    sink:
   115      ref:
   116        apiVersion: group/version
   117        kind: AnAddressableKind
   118        name: a-name
   119      uri: /path?query
   120    ceOverrides:
   121      extensions:
   122        key: value
   123  status:
   124    observedGeneration: 1
   125    conditions:
   126      - type: Ready
   127        status: "True"
   128    sinkUri: http://host/path?query
   129  ```