Repository: tektoncd/operator
Pull request #600 (2022-01-28 10:56:38)

Updates tektonPipeline to make it independent of tektonConfig
# Changes

  - With the addition of operator version config map `operators-info`
    getting created in tektonConfig, the targetNamespace was getting
    created in tektonConfig reconciler, but if `tektonConfig` is not installed
    and `tektonPipeline` is supposed to installed alone then it won't
    be installed as it would miss the targetNamespace. 

 - So this patch checks for the targetNamespace in `tektonPipeline`
   reconciler, if it is not present then it creates the targetNamespace
   and also the operator version config map i.e. makes tektonPipeline
   independent of tektonConfig

Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>

<!-- 🎉🎉🎉 Thank you for the PR!!! 🎉🎉🎉 -->

<!-- Describe your changes here- ideally you can get that description straight from
your descriptive commit message(s)! -->

# Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

- [ ] Includes [tests](https://github.com/tektoncd/community/blob/master/standards.md#principles) (if functionality changed/added)
- [ ] Includes [docs](https://github.com/tektoncd/community/blob/master/standards.md#principles) (if user facing)
- [ ] Commit messages follow [commit message best practices](https://github.com/tektoncd/community/blob/master/standards.md#commit-messages)

_See [the contribution guide](https://github.com/tektoncd/operator/blob/master/CONTRIBUTING.md) for more details._

# Release Notes

<!--
Describe any user facing changes here, or delete this block.

Examples of user facing changes:
- API changes
- Bug fixes
- Any changes in behavior
- Changes requiring upgrade notices or deprecation warnings

For pull requests with a release note:

```release-note
Your release note here
```

For pull requests that require additional action from users switching to the new release, include the string "action required" (case insensitive) in the release note:

```release-note
action required: your release note here
```

For pull requests that don't need to be mentioned at release time, use the `/release-note-none` Prow command to add the `release-note-none` label to the PR. You can also write the string "NONE" as a release note in your PR description:

```release-note
NONE
```
-->


tekton-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **sm43**
You can assign the PR to them by writing `/assign @sm43` in a comment when ready.

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

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

- **[OWNERS](https://github.com/tektoncd/operator/blob/main/OWNERS)**

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

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/transformers.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1487016830936551426/artifacts/line-cov.html#file0) | 73.8% | 71.4% | -2.4

tekton-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/tektoncd/operator/pull/600#pullrequestreview-868992184" title="Approved">savitaashture</a>*

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

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/tektoncd/operator/blob/main/OWNERS)~~ [savitaashture]

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":[]} -->
savitaashture: @nikhil-thomas i have verified this PR resolve TargetNamespace issue 
Its good to merge
Thank you @PuneetPunamiya :+1: 
nikhil-thomas: > @nikhil-thomas I have verified this PR resolve TargetNamespace issue Its good to merge Thank you @PuneetPunamiya 👍

Thanks @savitaashture 👍 

@PuneetPunamiya Functionally this patch looks great. I have a few comments regarding code organization. We shall merge this once those are addressed. 🧑‍💻 
tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1488742450829725696/artifacts/line-cov.html#file0) | Do not exist | 0.0% | 

tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1488749120465145859/artifacts/line-cov.html#file0) | Do not exist | 0.0% | 

tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1488749247208624128/artifacts/line-cov.html#file0) | Do not exist | 0.0% | 

savitaashture: > The following is the coverage report on the affected files. Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report
> 
> File	Old Coverage	New Coverage	Delta
> [pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1488749247208624128/artifacts/line-cov.html#file0)	Do not exist	0.0%

Can you add UT for this
tekton-robot: @PuneetPunamiya: PR needs rebase.

<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.
</details>
PuneetPunamiya: /hold

tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1490656188470136836/artifacts/line-cov.html#file0) | Do not exist | 0.0% | 

tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1491363724840144896/artifacts/line-cov.html#file0) | Do not exist | 64.7% | 

tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-build-tests | 81068612af686d32d51c9d38ec85bd612e8cc2ed | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-build-tests/1491363724835950592/) | `/test pull-tekton-operator-build-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-build-tests | 81068612af686d32d51c9d38ec85bd612e8cc2ed | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-build-tests/1491363724835950592/) | `/test pull-tekton-operator-build-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1491368129484296192/artifacts/line-cov.html#file0) | Do not exist | 64.7% | 

tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-build-tests | 5fcd90b11e6d029a6d838f6c1d464761c1ef2de4 | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-build-tests/1491368129484296193/) | `/test pull-tekton-operator-build-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-build-tests | 5fcd90b11e6d029a6d838f6c1d464761c1ef2de4 | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-build-tests/1491368129484296193/) | `/test pull-tekton-operator-build-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1491375427959132161/artifacts/line-cov.html#file0) | Do not exist | 64.7% | 

tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-build-tests | 6cc6938b8a89bf564f6891c44c425843fb0123fc | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-build-tests/1491375427959132160/) | `/test pull-tekton-operator-build-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1491384109677678594/artifacts/line-cov.html#file0) | Do not exist | 64.7% | 

tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1495627317014171650/artifacts/line-cov.html#file0) | Do not exist | 66.7% | 

tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-integration-tests | 4b3602284d48dfa300a2b56144c7d9d543ce1a9c | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-integration-tests/1495627317009977344/) | `/test pull-tekton-operator-integration-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-integration-tests | 4b3602284d48dfa300a2b56144c7d9d543ce1a9c | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-integration-tests/1495627317009977344/) | `/test pull-tekton-operator-integration-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1495639144381026307/artifacts/line-cov.html#file0) | Do not exist | 64.7% | 

tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-integration-tests | cd2b281778dfa2af5001d5b05a13f96568564050 | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-integration-tests/1495639144381026306/) | `/test pull-tekton-operator-integration-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-integration-tests | cd2b281778dfa2af5001d5b05a13f96568564050 | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-integration-tests/1495639144381026306/) | `/test pull-tekton-operator-integration-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
PuneetPunamiya: /test pull-tekton-operator-integration-tests
tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1495667079099977731/artifacts/line-cov.html#file0) | Do not exist | 66.7% | 

tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1496012605863497729/artifacts/line-cov.html#file0) | Do not exist | 66.7% | 

PuneetPunamiya: /hold cancel
tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1496346934590312451/artifacts/line-cov.html#file0) | Do not exist | 66.7% | 

tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-build-tests | 0051cdd56e25eb0387ca8f389e2085fb62e6c4e0 | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-build-tests/1496346934590312449/) | `/test pull-tekton-operator-build-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-build-tests | 0051cdd56e25eb0387ca8f389e2085fb62e6c4e0 | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-build-tests/1496346934590312449/) | `/test pull-tekton-operator-build-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1496358636476174336/artifacts/line-cov.html#file0) | Do not exist | 66.7% | 

tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-integration-tests | 617022bdf05d4bc4cc492a0178c72c2fdeb62894 | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-integration-tests/1496358636476174337/) | `/test pull-tekton-operator-integration-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
tekton-robot: @PuneetPunamiya: The following test **failed**, say `/retest` to rerun them all:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-tekton-operator-integration-tests | 617022bdf05d4bc4cc492a0178c72c2fdeb62894 | [link](https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-integration-tests/1496358636476174337/) | `/test pull-tekton-operator-integration-tests`

[Full PR test history](https://tekton-releases.appspot.com/pr/tektoncd_operator/600). [Your PR dashboard](https://prow.tekton.dev/pr/PuneetPunamiya).

<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 -->
PuneetPunamiya: /test pull-tekton-operator-integration-tests

tekton-robot: The following is the coverage report on the affected files.
Say `/test pull-tekton-operator-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1496401921315966976/artifacts/line-cov.html#file0) | Do not exist | 66.7% | 

tekton-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/tektoncd/operator/pull/600#pullrequestreview-868992184" title="Approved">savitaashture</a>*, *<a href="https://github.com/tektoncd/operator/pull/600#pullrequestreview-892291640" title="Approved">vdemeester</a>*

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

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/tektoncd/operator/blob/main/OWNERS)~~ [savitaashture,vdemeester]

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

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/reconciler/common/targetnamespace.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/600/pull-tekton-operator-go-coverage/1497052834540032002/artifacts/line-cov.html#file0) | Do not exist | 66.7% | 


Patch:
diff --git a/pkg/reconciler/common/targetnamespace.go b/pkg/reconciler/common/targetnamespace.go
new file mode 100644
index 000000000..58c63288f
--- /dev/null
+++ b/pkg/reconciler/common/targetnamespace.go
@@ -0,0 +1,77 @@
+/*
+Copyright 2022 The Tekton Authors
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package common
+
+import (
+	"context"
+	"os"
+	"path/filepath"
+
+	mf "github.com/manifestival/manifestival"
+	"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
+	corev1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/client-go/kubernetes"
+)
+
+func CreateTargetNamespace(ctx context.Context, labels map[string]string, obj v1alpha1.TektonComponent, kubeClientSet kubernetes.Interface) error {
+	ownerRef := *metav1.NewControllerRef(obj, obj.GroupVersionKind())
+	namespace := &corev1.Namespace{
+		ObjectMeta: metav1.ObjectMeta{
+			Name: obj.GetSpec().GetTargetNamespace(),
+			Labels: map[string]string{
+				"operator.tekton.dev/targetNamespace": "true",
+			},
+			OwnerReferences: []metav1.OwnerReference{ownerRef},
+		},
+	}
+
+	if len(labels) > 0 {
+		for key, value := range labels {
+			namespace.Labels[key] = value
+		}
+	}
+
+	if _, err := kubeClientSet.CoreV1().Namespaces().Create(ctx, namespace, metav1.CreateOptions{}); err != nil {
+		return err
+	}
+	return nil
+}
+
+func CreateOperatorVersionConfigMap(manifest mf.Manifest, obj v1alpha1.TektonComponent) error {
+	koDataDir := os.Getenv(KoEnvKey)
+	operatorDir := filepath.Join(koDataDir, "info")
+
+	if err := AppendManifest(&manifest, operatorDir); err != nil {
+		return err
+	}
+
+	manifest, err := manifest.Transform(
+		mf.InjectNamespace(obj.GetSpec().GetTargetNamespace()),
+		mf.InjectOwner(obj),
+	)
+
+	if err != nil {
+		return err
+	}
+
+	if err = manifest.Apply(); err != nil {
+		return err
+	}
+
+	return nil
+}
diff --git a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go
index 92192fa9f..98b7e4486 100644
--- a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go
+++ b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go
@@ -379,8 +379,15 @@ func (r *Reconciler) targetNamespaceCheck(ctx context.Context, tp *v1alpha1.Tekt
 	ns, err := r.kubeClientSet.CoreV1().Namespaces().Get(ctx, tp.GetSpec().GetTargetNamespace(), metav1.GetOptions{})
 	if err != nil {
 		if apierrors.IsNotFound(err) {
-			return err
+			if err := common.CreateTargetNamespace(ctx, labels, tp, r.kubeClientSet); err != nil {
+				return err
+			}
+			if err := common.CreateOperatorVersionConfigMap(r.manifest, tp); err != nil {
+				return err
+			}
+			return nil
 		}
+		return err
 	}
 	for key, value := range labels {
 		ns.Labels[key] = value
diff --git a/pkg/reconciler/shared/tektonconfig/tektonconfig.go b/pkg/reconciler/shared/tektonconfig/tektonconfig.go
index 970c877c5..ef6576a0c 100644
--- a/pkg/reconciler/shared/tektonconfig/tektonconfig.go
+++ b/pkg/reconciler/shared/tektonconfig/tektonconfig.go
@@ -19,13 +19,8 @@ package tektonconfig
 import (
 	"context"
 	"fmt"
-	"os"
-	"path/filepath"
 	"time"
 
-	corev1 "k8s.io/api/core/v1"
-	"k8s.io/apimachinery/pkg/api/errors"
-
 	mf "github.com/manifestival/manifestival"
 	"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
 	clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned"
@@ -33,6 +28,7 @@ import (
 	"github.com/tektoncd/operator/pkg/reconciler/common"
 	"github.com/tektoncd/operator/pkg/reconciler/shared/tektonconfig/pipeline"
 	"github.com/tektoncd/operator/pkg/reconciler/shared/tektonconfig/trigger"
+	"k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/client-go/kubernetes"
@@ -108,7 +104,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi
 		return err
 	}
 
-	if err := r.createOperatorVersionConfigMap(tc); err != nil {
+	if err := common.CreateOperatorVersionConfigMap(r.manifest, tc); err != nil {
 		return err
 	}
 
@@ -172,29 +168,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi
 	return nil
 }
 
-func (r *Reconciler) createOperatorVersionConfigMap(tc *v1alpha1.TektonConfig) error {
-	koDataDir := os.Getenv(common.KoEnvKey)
-	operatorDir := filepath.Join(koDataDir, "info")
-
-	if err := common.AppendManifest(&r.manifest, operatorDir); err != nil {
-		return err
-	}
-
-	manifest, err := r.manifest.Transform(
-		mf.InjectNamespace(tc.GetSpec().GetTargetNamespace()),
-		mf.InjectOwner(tc),
-	)
-	if err != nil {
-		return err
-	}
-
-	if err = manifest.Apply(); err != nil {
-		return err
-	}
-
-	return nil
-}
-
 func (r *Reconciler) ensureTargetNamespaceExists(ctx context.Context, tc *v1alpha1.TektonConfig) error {
 
 	ns, err := r.kubeClientSet.CoreV1().Namespaces().List(ctx, metav1.ListOptions{
@@ -219,15 +192,7 @@ func (r *Reconciler) ensureTargetNamespaceExists(ctx context.Context, tc *v1alph
 			}
 		}
 	} else {
-		ns := &corev1.Namespace{
-			ObjectMeta: metav1.ObjectMeta{
-				Name: tc.GetSpec().GetTargetNamespace(),
-				Labels: map[string]string{
-					"operator.tekton.dev/targetNamespace": "true",
-				},
-			},
-		}
-		if _, err = r.kubeClientSet.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{}); err != nil {
+		if err := common.CreateTargetNamespace(ctx, nil, tc, r.kubeClientSet); err != nil {
 			if errors.IsAlreadyExists(err) {
 				return r.addTargetNamespaceLabel(ctx, tc.GetSpec().GetTargetNamespace())
 			}


Test patch:
diff --git a/pkg/reconciler/common/targetnamespace_test.go b/pkg/reconciler/common/targetnamespace_test.go
new file mode 100644
index 000000000..82ea893fb
--- /dev/null
+++ b/pkg/reconciler/common/targetnamespace_test.go
@@ -0,0 +1,142 @@
+/*
+Copyright 2022 The Tekton Authors
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package common
+
+import (
+	"context"
+	"fmt"
+	"os"
+	"testing"
+
+	"github.com/google/go-cmp/cmp"
+	mf "github.com/manifestival/manifestival"
+	"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
+	"gotest.tools/v3/assert"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"k8s.io/client-go/kubernetes/fake"
+)
+
+type fakeClient struct {
+	err            error
+	getErr         error
+	createErr      error
+	resourcesExist bool
+	creates        []unstructured.Unstructured
+	deletes        []unstructured.Unstructured
+}
+
+var configMap = namespacedResource("v1", "ConfigMap", "test-ns", "operators-info")
+
+func (f *fakeClient) Get(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) {
+	var resource *unstructured.Unstructured
+	if f.resourcesExist {
+		resource = &unstructured.Unstructured{}
+	}
+	return resource, f.getErr
+}
+
+func (f *fakeClient) Create(obj *unstructured.Unstructured, options ...mf.ApplyOption) error {
+	obj.SetAnnotations(nil) // Deleting the extra annotation. Irrelevant for the test.
+	f.creates = append(f.creates, *obj)
+	return f.createErr
+}
+
+func (f *fakeClient) Delete(obj *unstructured.Unstructured, options ...mf.DeleteOption) error {
+	f.deletes = append(f.deletes, *obj)
+	return f.err
+}
+
+func (f *fakeClient) Update(obj *unstructured.Unstructured, options ...mf.ApplyOption) error {
+	return f.err
+}
+
+func TestCreateTargetNamespace(t *testing.T) {
+	targetNamespace := "test-ns"
+	component := &v1alpha1.TektonPipeline{
+		ObjectMeta: metav1.ObjectMeta{
+			Name: "test-name",
+		},
+		Spec: v1alpha1.TektonPipelineSpec{
+			CommonSpec: v1alpha1.CommonSpec{
+				TargetNamespace: targetNamespace,
+			},
+		},
+	}
+	fakeClientset := fake.NewSimpleClientset()
+
+	err := CreateTargetNamespace(context.Background(), nil, component, fakeClientset)
+	assert.Equal(t, err, nil)
+
+	ns, err := fakeClientset.CoreV1().Namespaces().Get(context.Background(), targetNamespace, metav1.GetOptions{})
+	assert.Equal(t, err, nil)
+	assert.Equal(t, ns.ObjectMeta.Name, targetNamespace)
+}
+
+func TestTargetNamespaceNotFound(t *testing.T) {
+	component := &v1alpha1.TektonPipeline{
+		ObjectMeta: metav1.ObjectMeta{
+			Name: "test-name",
+		},
+		Spec: v1alpha1.TektonPipelineSpec{
+			CommonSpec: v1alpha1.CommonSpec{},
+		},
+	}
+	fakeClientset := fake.NewSimpleClientset()
+
+	err := CreateTargetNamespace(context.Background(), nil, component, fakeClientset)
+	assert.Equal(t, err, nil)
+
+	_, err = fakeClientset.CoreV1().Namespaces().Get(context.Background(), "foo", metav1.GetOptions{})
+	assert.Equal(t, err.Error(), `namespaces "foo" not found`)
+}
+
+func TestOperatorVersionCreateConfigMap(t *testing.T) {
+	os.Setenv(KoEnvKey, "testdata/kodata")
+	defer os.Unsetenv(KoEnvKey)
+
+	targetNamespace := "test-ns"
+	component := &v1alpha1.TektonPipeline{
+		ObjectMeta: metav1.ObjectMeta{
+			Name: "test-name",
+		},
+		Spec: v1alpha1.TektonPipelineSpec{
+			CommonSpec: v1alpha1.CommonSpec{
+				TargetNamespace: targetNamespace,
+			},
+		},
+	}
+	fakeClientset := fake.NewSimpleClientset()
+
+	err := CreateTargetNamespace(context.Background(), nil, component, fakeClientset)
+	assert.Equal(t, err, nil)
+
+	var manifest mf.Manifest
+
+	client := &fakeClient{}
+	manifest, err = mf.ManifestFrom(mf.Slice(manifest.Resources()), mf.UseClient(client))
+	assert.Equal(t, err, nil)
+
+	err = CreateOperatorVersionConfigMap(manifest, component)
+	assert.Equal(t, err, nil)
+
+	want := []unstructured.Unstructured{configMap}
+
+	if len(want) != len(client.creates) {
+		t.Fatalf("Unexpected creates: %s", fmt.Sprintf("(-got, +want): %s", cmp.Diff(client.creates, want)))
+	}
+}
diff --git a/pkg/reconciler/common/testdata/kodata/info/test-create-operator-version-config-map.yaml b/pkg/reconciler/common/testdata/kodata/info/test-create-operator-version-config-map.yaml
new file mode 100644
index 000000000..324b648b5
--- /dev/null
+++ b/pkg/reconciler/common/testdata/kodata/info/test-create-operator-version-config-map.yaml
@@ -0,0 +1,24 @@
+# Copyright 2022 The Tekton Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: operators-info
+  labels:
+    app.kubernetes.io/instance: default
+data:
+  # Contains operator version which can be queried by external
+  # tools such as CLI.
+  version: 'devel'