Repository: knative-sandbox/eventing-kafka
Pull request #139 (2020-10-22 22:32:10)

populate newly required env vars in receiver/dispatcher
The recent merge of https://github.com/knative-sandbox/eventing-kafka/pull/133 has broken the distributed kafka channel implementation.  It added new required environment variables to the receiver/dispatcher but failed to populate them in Deployment created by the controller.  This PR provides the missing logic to do so.

> Note - This was not caught by automated testing because we are still in the process of standing up our e2e (integration) tests.  All unit tests were/are passing.

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative-sandbox/eventing-kafka/pull/139#" title="Author self-approved">travis-minke-sap</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative-sandbox%2Feventing-kafka).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/knative-sandbox/eventing-kafka/blob/master/OWNERS)~~ [travis-minke-sap]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139?src=pr&el=h1) Report
> Merging [#139](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139?src=pr&el=desc) into [master](https://codecov.io/gh/knative-sandbox/eventing-kafka/commit/8a6c8ba331bd198cd33a14dc94c441c169534fcd?el=desc) will **decrease** coverage by `0.04%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139/graphs/tree.svg?width=650&height=150&src=pr&token=W765CT93QC)](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #139      +/-   ##
==========================================
- Coverage   74.97%   74.92%   -0.05%     
==========================================
  Files         111      111              
  Lines        3972     3992      +20     
==========================================
+ Hits         2978     2991      +13     
- Misses        811      818       +7     
  Partials      183      183              
```


| [Impacted Files](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [.../distributed/controller/kafkachannel/dispatcher.go](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139/diff?src=pr&el=tree#diff-cGtnL2NoYW5uZWwvZGlzdHJpYnV0ZWQvY29udHJvbGxlci9rYWZrYWNoYW5uZWwvZGlzcGF0Y2hlci5nbw==) | `92.68% <100.00%> (+0.31%)` | :arrow_up: |
| [...nel/distributed/controller/kafkasecret/receiver.go](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139/diff?src=pr&el=tree#diff-cGtnL2NoYW5uZWwvZGlzdHJpYnV0ZWQvY29udHJvbGxlci9rYWZrYXNlY3JldC9yZWNlaXZlci5nbw==) | `93.03% <100.00%> (+0.29%)` | :arrow_up: |
| [...el/distributed/dispatcher/dispatcher/dispatcher.go](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139/diff?src=pr&el=tree#diff-cGtnL2NoYW5uZWwvZGlzdHJpYnV0ZWQvZGlzcGF0Y2hlci9kaXNwYXRjaGVyL2Rpc3BhdGNoZXIuZ28=) | `66.29% <0.00%> (-7.87%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139?src=pr&el=footer). Last update [8a6c8ba...6f090d6](https://codecov.io/gh/knative-sandbox/eventing-kafka/pull/139?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

phamilton: /LGTM

Patch:
diff --git a/pkg/channel/distributed/controller/constants/constants.go b/pkg/channel/distributed/controller/constants/constants.go
index 4b94fffad..7bd498d48 100644
--- a/pkg/channel/distributed/controller/constants/constants.go
+++ b/pkg/channel/distributed/controller/constants/constants.go
@@ -61,6 +61,10 @@ const (
 	// Eventing-Kafka Finalizers Prefix
 	EventingKafkaFinalizerPrefix = "eventing-kafka/"
 
+	// Container Names
+	DispatcherContainerName = "kafkachannel-dispatcher"
+	ReceiverContainerName   = "kafkachannel-receiver"
+
 	// Labels
 	AppLabel                    = "app"
 	KafkaChannelNameLabel       = "kafkachannel-name"
diff --git a/pkg/channel/distributed/controller/kafkachannel/dispatcher.go b/pkg/channel/distributed/controller/kafkachannel/dispatcher.go
index 4df238d36..78b88cfa6 100644
--- a/pkg/channel/distributed/controller/kafkachannel/dispatcher.go
+++ b/pkg/channel/distributed/controller/kafkachannel/dispatcher.go
@@ -328,6 +328,18 @@ func (r *Reconciler) dispatcherDeploymentEnvVars(channel *kafkav1beta1.KafkaChan
 			Name:  system.NamespaceEnvKey,
 			Value: commonconstants.KnativeEventingNamespace,
 		},
+		{
+			Name: commonenv.PodNameEnvVarKey,
+			ValueFrom: &corev1.EnvVarSource{
+				FieldRef: &corev1.ObjectFieldSelector{
+					FieldPath: "metadata.name",
+				},
+			},
+		},
+		{
+			Name:  commonenv.ContainerNameEnvVarKEy,
+			Value: constants.DispatcherContainerName,
+		},
 		{
 			Name:  commonenv.KnativeLoggingConfigMapNameEnvVarKey,
 			Value: logging.ConfigMapName(),
diff --git a/pkg/channel/distributed/controller/kafkasecret/receiver.go b/pkg/channel/distributed/controller/kafkasecret/receiver.go
index 5a17718e2..8ac9f1a78 100644
--- a/pkg/channel/distributed/controller/kafkasecret/receiver.go
+++ b/pkg/channel/distributed/controller/kafkasecret/receiver.go
@@ -194,7 +194,7 @@ func (r *Reconciler) reconcileReceiverDeployment(ctx context.Context, secret *co
 
 			// Then Create The New Receiver Deployment
 			r.logger.Info("Receiver Deployment Not Found - Creating New One")
-			deployment, err := r.newChannelDeployment(secret)
+			deployment, err := r.newReceiverDeployment(secret)
 			if err != nil {
 				r.logger.Error("Failed To Create Receiver Deployment YAML", zap.Error(err))
 				return err
@@ -237,7 +237,7 @@ func (r *Reconciler) getReceiverDeployment(secret *corev1.Secret) (*appsv1.Deplo
 }
 
 // Create Receiver Deployment Model For The Specified Secret
-func (r *Reconciler) newChannelDeployment(secret *corev1.Secret) (*appsv1.Deployment, error) {
+func (r *Reconciler) newReceiverDeployment(secret *corev1.Secret) (*appsv1.Deployment, error) {
 
 	// Get The Receiver Deployment Name (One Receiver Deployment Per Kafka Auth Secret)
 	deploymentName := util.ReceiverDnsSafeName(secret.Name)
@@ -346,6 +346,18 @@ func (r *Reconciler) receiverDeploymentEnvVars(secret *corev1.Secret) ([]corev1.
 			Name:  system.NamespaceEnvKey,
 			Value: commonconstants.KnativeEventingNamespace,
 		},
+		{
+			Name: commonenv.PodNameEnvVarKey,
+			ValueFrom: &corev1.EnvVarSource{
+				FieldRef: &corev1.ObjectFieldSelector{
+					FieldPath: "metadata.name",
+				},
+			},
+		},
+		{
+			Name:  commonenv.ContainerNameEnvVarKEy,
+			Value: constants.ReceiverContainerName,
+		},
 		{
 			Name:  commonenv.KnativeLoggingConfigMapNameEnvVarKey,
 			Value: logging.ConfigMapName(),


Test patch:
diff --git a/pkg/channel/distributed/controller/testing/data.go b/pkg/channel/distributed/controller/testing/data.go
index 38160c6b6..ff2ddf8c4 100644
--- a/pkg/channel/distributed/controller/testing/data.go
+++ b/pkg/channel/distributed/controller/testing/data.go
@@ -557,6 +557,18 @@ func NewKafkaChannelReceiverDeployment() *appsv1.Deployment {
 									Name:  system.NamespaceEnvKey,
 									Value: commonconstants.KnativeEventingNamespace,
 								},
+								{
+									Name: commonenv.PodNameEnvVarKey,
+									ValueFrom: &corev1.EnvVarSource{
+										FieldRef: &corev1.ObjectFieldSelector{
+											FieldPath: "metadata.name",
+										},
+									},
+								},
+								{
+									Name:  commonenv.ContainerNameEnvVarKEy,
+									Value: constants.ReceiverContainerName,
+								},
 								{
 									Name:  commonenv.KnativeLoggingConfigMapNameEnvVarKey,
 									Value: logging.ConfigMapName(),
@@ -738,6 +750,18 @@ func NewKafkaChannelDispatcherDeployment() *appsv1.Deployment {
 									Name:  system.NamespaceEnvKey,
 									Value: commonconstants.KnativeEventingNamespace,
 								},
+								{
+									Name: commonenv.PodNameEnvVarKey,
+									ValueFrom: &corev1.EnvVarSource{
+										FieldRef: &corev1.ObjectFieldSelector{
+											FieldPath: "metadata.name",
+										},
+									},
+								},
+								{
+									Name:  commonenv.ContainerNameEnvVarKEy,
+									Value: constants.DispatcherContainerName,
+								},
 								{
 									Name:  commonenv.KnativeLoggingConfigMapNameEnvVarKey,
 									Value: logging.ConfigMapName(),