Repository: knative-sandbox/eventing-kafka
Pull request #84 (2020-10-07 09:24:25)

Relocation, part x: Move src client
Fixes #

<!-- Please include the 'why' behind your changes if no issue exists -->

## Proposed Changes

- move source client around
-
-

<!--
If this change has user-visible impact, follow the instructions below.
Examples include:

- 🎁 Add new feature
- 🐛 Fix bug
- 🧽 Update or clean up current behavior
- 🗑️ Remove feature or internal logic

Otherwise delete the rest of this template.
-->

**Release Note**

<!--
🗒️ If this change has user-visible impact, write a release note in the block
below. Include the string "action required" if additional action is required of
users switching to the new release, for example in case of a breaking change.

Write as if you are speaking to users, not other Knative contributors. If this
change has no user-visible impact, no release-note is needed.
-->

```release-note

```

**Docs**

<!--
📖 If this change has user-visible impact, link to an issue or PR in
https://github.com/knative/docs.
-->


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/84#" title="Author self-approved">matzew</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)~~ [matzew]

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":[]} -->
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-sandbox-eventing-kafka-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/source/client.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-go-coverage/1313772358737072131/artifacts/line-cov.html#file0) | Do not exist | 62.3% | 

lgtm-com[bot]: This pull request **introduces 1 alert** and **fixes 1** when merging 0ed2f36a9fe6ad568d402fa083fd2309a30bc33b into b1acf1e8c830183c195ac75edb8bbc29525eef2a - [view on LGTM.com](https://lgtm.com/projects/g/knative-sandbox/eventing-kafka/rev/pr-35aa272b1178a63a3758913e2de6ac7a6e6c2e31)

**new alerts:**

* 1 for Disabled TLS certificate check

**fixed alerts:**

* 1 for Disabled TLS certificate check
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-sandbox-eventing-kafka-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/source/client.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-go-coverage/1313776887658450944/artifacts/line-cov.html#file0) | Do not exist | 62.3% | 

knative-prow-robot: @matzew: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-sandbox-eventing-kafka-unit-tests | 62b7fb97ea7cb928289cfcb8e4fd28631cce9ecb | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-unit-tests/1313776887658450947) | `/test pull-knative-sandbox-eventing-kafka-unit-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative-sandbox_eventing-kafka/84). [Your PR dashboard](https://gubernator.knative.dev/pr/matzew).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
lgtm-com[bot]: This pull request **introduces 1 alert** and **fixes 1** when merging 62b7fb97ea7cb928289cfcb8e4fd28631cce9ecb into b1acf1e8c830183c195ac75edb8bbc29525eef2a - [view on LGTM.com](https://lgtm.com/projects/g/knative-sandbox/eventing-kafka/rev/pr-a6441eea6f02643f7629c58d3cc53651eaa980e7)

**new alerts:**

* 1 for Disabled TLS certificate check

**fixed alerts:**

* 1 for Disabled TLS certificate check
knative-prow-robot: @matzew: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-sandbox-eventing-kafka-unit-tests | 62b7fb97ea7cb928289cfcb8e4fd28631cce9ecb | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-unit-tests/1313776887658450947) | `/test pull-knative-sandbox-eventing-kafka-unit-tests`
pull-knative-sandbox-eventing-kafka-build-tests | 62b7fb97ea7cb928289cfcb8e4fd28631cce9ecb | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-build-tests/1313776887658450946) | `/test pull-knative-sandbox-eventing-kafka-build-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative-sandbox_eventing-kafka/84). [Your PR dashboard](https://gubernator.knative.dev/pr/matzew).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-sandbox-eventing-kafka-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/source/client.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-go-coverage/1313790476800757762/artifacts/line-cov.html#file0) | Do not exist | 62.3% | 

knative-prow-robot: @matzew: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-sandbox-eventing-kafka-build-tests | 62b7fb97ea7cb928289cfcb8e4fd28631cce9ecb | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-build-tests/1313776887658450946) | `/test pull-knative-sandbox-eventing-kafka-build-tests`
pull-knative-sandbox-eventing-kafka-unit-tests | 9e1879a2bd83e315c6912296b30cd8ed4b9ac06e | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-unit-tests/1313790476800757765) | `/test pull-knative-sandbox-eventing-kafka-unit-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative-sandbox_eventing-kafka/84). [Your PR dashboard](https://gubernator.knative.dev/pr/matzew).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-prow-robot: @matzew: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-sandbox-eventing-kafka-unit-tests | 9e1879a2bd83e315c6912296b30cd8ed4b9ac06e | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-unit-tests/1313790476800757765) | `/test pull-knative-sandbox-eventing-kafka-unit-tests`
pull-knative-sandbox-eventing-kafka-build-tests | 9e1879a2bd83e315c6912296b30cd8ed4b9ac06e | [link](https://prow.knative.dev/view/gs/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-build-tests/1313790476800757764) | `/test pull-knative-sandbox-eventing-kafka-build-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative-sandbox_eventing-kafka/84). [Your PR dashboard](https://gubernator.knative.dev/pr/matzew).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
lgtm-com[bot]: This pull request **introduces 1 alert** and **fixes 1** when merging 9e1879a2bd83e315c6912296b30cd8ed4b9ac06e into b1acf1e8c830183c195ac75edb8bbc29525eef2a - [view on LGTM.com](https://lgtm.com/projects/g/knative-sandbox/eventing-kafka/rev/pr-e83b142d8e0a4f1344e3a38dd139f48793e1b6c8)

**new alerts:**

* 1 for Disabled TLS certificate check

**fixed alerts:**

* 1 for Disabled TLS certificate check
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-sandbox-eventing-kafka-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/source/client.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative-sandbox_eventing-kafka/84/pull-knative-sandbox-eventing-kafka-go-coverage/1313800543151329281/artifacts/line-cov.html#file1) | Do not exist | 62.3% | 

lgtm-com[bot]: This pull request **introduces 1 alert** and **fixes 1** when merging f080f5b032a2cd1ab1edd248b6fd9e19de83fa61 into b1acf1e8c830183c195ac75edb8bbc29525eef2a - [view on LGTM.com](https://lgtm.com/projects/g/knative-sandbox/eventing-kafka/rev/pr-3a5dc37e5ab0ce7d407c6d2685a280a3ce68adbc)

**new alerts:**

* 1 for Disabled TLS certificate check

**fixed alerts:**

* 1 for Disabled TLS certificate check
slinkydeveloper: /lgtm

Patch:
diff --git a/contrib/kafka/source/PROJECT b/contrib/kafka/source/PROJECT
deleted file mode 100644
index ae98d46d9..000000000
--- a/contrib/kafka/source/PROJECT
+++ /dev/null
@@ -1,3 +0,0 @@
-version: "1"
-domain: eventing.knative.dev
-repo: knative.dev/eventing-kafka
diff --git a/contrib/kafka/source/README.md b/contrib/kafka/source/README.md
deleted file mode 100644
index d0e927efd..000000000
--- a/contrib/kafka/source/README.md
+++ /dev/null
@@ -1,55 +0,0 @@
-# Apache Kafka - Source
-
-The Apache Kafka Event source enables Knative Eventing integration with Apache
-Kafka. When a message is produced to Apache Kafka, the Apache Kafka Event Source
-will consume the produced message and post that message to the corresponding
-event sink.
-
-## Deployment steps
-
-1. Setup [Knative Eventing](../../DEVELOPMENT.md)
-1. If not done already, install an Apache Kafka cluster!
-
-   - For Kubernetes a simple installation is done using the
-     [Strimzi Kafka Operator](http://strimzi.io). Its installation
-     [guides](http://strimzi.io/quickstarts/) provide content for Kubernetes and
-     Openshift.
-
-   > Note: The `KafkaSource` is not limited to Apache Kafka installations on
-   > Kubernetes. It is also possible to use an off-cluster Apache Kafka
-   > installation.
-
-1. Now that Apache Kafka is installed, apply the `KafkaSource` config:
-
-   ```
-   ko apply -f config/
-   ```
-
-1. Create the `KafkaSource` custom objects, by configuring the required
-   `consumerGroup`, `bootstrapServers` and `topics` values on the CR file of
-   your source. Below is an example:
-
-   ```yaml
-   apiVersion: sources.knative.dev/v1alpha1
-   kind: KafkaSource
-   metadata:
-     name: kafka-source
-   spec:
-     consumerGroup: knative-group
-     # Broker URL. Replace this with the URLs for your kafka cluster,
-     # which is in the format of my-cluster-kafka-bootstrap.my-kafka-namespace:9092.
-     bootstrapServers:
-       - REPLACE_WITH_CLUSTER_URL
-     topics:
-       - knative-demo-topic
-     sink:
-       ref:
-         apiVersion: serving.knative.dev/v1alpha1
-         kind: Service
-         name: event-display
-   ```
-
-## Example
-
-A more detailed example of the `KafkaSource` can be found in the
-[Knative documentation](https://knative.dev/docs/eventing/samples/).
diff --git a/pkg/source/adapter/adapter.go b/pkg/source/adapter/adapter.go
index 5fb6f2f3a..492f70e20 100644
--- a/pkg/source/adapter/adapter.go
+++ b/pkg/source/adapter/adapter.go
@@ -21,16 +21,17 @@ import (
 	"net/http"
 	"strings"
 
+	kafkasource "knative.dev/eventing-kafka/pkg/source"
+
 	"go.opencensus.io/trace"
 	"knative.dev/eventing/pkg/adapter/v2"
 	"knative.dev/eventing/pkg/kncloudevents"
-	"knative.dev/pkg/source"
+	pkgsource "knative.dev/pkg/source"
 
 	"context"
 
 	"github.com/Shopify/sarama"
 	"go.uber.org/zap"
-	kafkabinding "knative.dev/eventing-kafka/contrib/kafka"
 	"knative.dev/eventing-kafka/pkg/common/consumer"
 	"knative.dev/pkg/logging"
 )
@@ -55,7 +56,7 @@ func NewEnvConfig() adapter.EnvConfigAccessor {
 type Adapter struct {
 	config            *adapterConfig
 	httpMessageSender *kncloudevents.HttpMessageSender
-	reporter          source.StatsReporter
+	reporter          pkgsource.StatsReporter
 	logger            *zap.SugaredLogger
 	keyTypeMapper     func([]byte) interface{}
 }
@@ -63,7 +64,7 @@ type Adapter struct {
 var _ adapter.MessageAdapter = (*Adapter)(nil)
 var _ adapter.MessageAdapterConstructor = NewAdapter
 
-func NewAdapter(ctx context.Context, processed adapter.EnvConfigAccessor, httpMessageSender *kncloudevents.HttpMessageSender, reporter source.StatsReporter) adapter.MessageAdapter {
+func NewAdapter(ctx context.Context, processed adapter.EnvConfigAccessor, httpMessageSender *kncloudevents.HttpMessageSender, reporter pkgsource.StatsReporter) adapter.MessageAdapter {
 	logger := logging.FromContext(ctx)
 	config := processed.(*adapterConfig)
 
@@ -90,7 +91,7 @@ func (a *Adapter) start(stopCh <-chan struct{}) error {
 	)
 
 	// init consumer group
-	addrs, config, err := kafkabinding.NewConfig(context.Background())
+	addrs, config, err := kafkasource.NewConfig(context.Background())
 	if err != nil {
 		return fmt.Errorf("failed to create the config: %w", err)
 	}
@@ -142,7 +143,7 @@ func (a *Adapter) Handle(ctx context.Context, msg *sarama.ConsumerMessage) (bool
 		return false, fmt.Errorf("%d %s", res.StatusCode, http.StatusText(res.StatusCode))
 	}
 
-	reportArgs := &source.ReportArgs{
+	reportArgs := &pkgsource.ReportArgs{
 		Namespace:     a.config.Namespace,
 		Name:          a.config.Name,
 		ResourceGroup: resourceGroup,
diff --git a/contrib/kafka/client.go b/pkg/source/client.go
similarity index 99%
rename from contrib/kafka/client.go
rename to pkg/source/client.go
index de0815be4..7e8795771 100644
--- a/contrib/kafka/client.go
+++ b/pkg/source/client.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package kafka
+package source
 
 import (
 	"context"


Test patch:
diff --git a/contrib/test/test_images/kafka-publisher/main.go b/contrib/test/test_images/kafka-publisher/main.go
index e8f5fc0da..3de776408 100644
--- a/contrib/test/test_images/kafka-publisher/main.go
+++ b/contrib/test/test_images/kafka-publisher/main.go
@@ -19,9 +19,10 @@ package main
 import (
 	"log"
 
+	"knative.dev/eventing-kafka/pkg/source"
+
 	"github.com/Shopify/sarama"
 	"github.com/kelseyhightower/envconfig"
-	"knative.dev/eventing-kafka/contrib/kafka"
 	"knative.dev/pkg/signals"
 )
 
@@ -44,7 +45,7 @@ func main() {
 	log.Printf("GOT: %v", s)
 
 	// Create a Kafka client from our Binding.
-	client, err := kafka.NewProducer(ctx)
+	client, err := source.NewProducer(ctx)
 	if err != nil {
 		log.Fatal(err.Error())
 	}
diff --git a/contrib/kafka/client_test.go b/pkg/source/client_test.go
similarity index 99%
rename from contrib/kafka/client_test.go
rename to pkg/source/client_test.go
index 96cd0d3bd..296a32359 100644
--- a/contrib/kafka/client_test.go
+++ b/pkg/source/client_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package kafka
+package source
 
 import (
 	"bytes"