<p>I am trying to set up a Knative eventing pipeline, where exists a container that accepts external gRPC requests and fires events into a broker for further processing.</p>
<p>In my toy example, I am failing to use SinkBinding to inject <code>K_SINK</code> environment variable. This is the relevant section of my configuration:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Namespace
metadata:
  name: bora-namespace
  labels:
    eventing.knative.dev/injection: enabled

---

apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
  name: my-broker
  namespace: bora-namespace

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ease-pipeline-server
  namespace: bora-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ease-pipeline-server
  template:
    metadata:
      labels:
        app: ease-pipeline-server
    spec:
      containers:
        - name: ease-pipeline-server
          image: docker.io/boramalper/ease-pipeline-server:latest
          imagePullPolicy: Always

---

apiVersion: sources.knative.dev/v1
kind: SinkBinding
metadata:
  name: bind-ease-pipeline-server
  namespace: bora-namespace
spec:
  subject:
    apiVersion: apps/v1
    kind: Deployment
    selector:
      matchLabels:
        app: ease-pipeline-server
  sink:
    ref:
      apiVersion: eventing.knative.dev/v1
      kind: Broker
      name: my-broker

---

kind: Service
apiVersion: v1
metadata:
  name: ease-pipeline-server
  namespace: bora-namespace
spec:
  type: NodePort
  selector:
    app: ease-pipeline-server
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
      nodePort: 30002
</code></pre>
<p>My container gets stuck in an infinite crash loop due to missing environment variable.</p>
<p>The SinkBinding object seems to have no issues:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl --namespace bora-namespace get sinkbinding
NAME                        SINK                                                                                AGE   READY   REASON
bind-ease-pipeline-server   http://broker-ingress.knative-eventing.svc.cluster.local/bora-namespace/my-broker   22m   True    
</code></pre>
<p>System information:</p>
<pre class="lang-sh prettyprint-override"><code>$ kn version
Version:      v20210526-local-0c6ef82
Build Date:   2021-05-26 06:34:50
Git Revision: 0c6ef82
Supported APIs:
* Serving
  - serving.knative.dev/v1 (knative-serving v0.23.0)
* Eventing
  - sources.knative.dev/v1 (knative-eventing v0.23.0)
  - eventing.knative.dev/v1 (knative-eventing v0.23.0)

$ kubectl version
Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;20&quot;, GitVersion:&quot;v1.20.6&quot;, GitCommit:&quot;8a62859e515889f07e3e3be6a1080413f17cf2c3&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-04-15T03:28:42Z&quot;, GoVersion:&quot;go1.15.10&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;20&quot;, GitVersion:&quot;v1.20.7&quot;, GitCommit:&quot;132a687512d7fb058d0f5890f07d4121b3f0a2e2&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-05-12T12:32:49Z&quot;, GoVersion:&quot;go1.15.12&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:    18.04
Codename:   bionic

$ uname -a
Linux REDACTED 4.15.0-137-generic #141-Ubuntu SMP Fri Feb 19 13:46:27 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
</code></pre>

<p>The <code>SinkBinding</code> object has a subject configured using a label selector:</p>
<pre class="lang-yaml prettyprint-override"><code>subject:
  apiVersion: apps/v1
  kind: Deployment
  selector:
    matchLabels:
      app: ease-pipeline-server
</code></pre>
<p>However, there is no such label set on the <code>Deployment</code> object:</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  name: ease-pipeline-server
  # no labels
</code></pre>
<p>The solution here would be to either:</p>
<ul>
<li><p>add the corresponding label(s) to the Deployment's <code>metadata</code></p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  name: ease-pipeline-server
  labels:
    app: ease-pipeline-server
</code></pre>
</li>
<li><p>use a subject matching on the Deployment's <code>name</code> (<a href="https://knative.dev/docs/reference/api/eventing/#sources.knative.dev/v1.SinkBinding" rel="nofollow noreferrer">API documentation</a>)</p>
<pre class="lang-yaml prettyprint-override"><code>subject:
  apiVersion: apps/v1
  kind: Deployment
  name: ease-pipeline-server
</code></pre>
</li>
</ul>
