Repository: tektoncd/operator
Pull request #228 (2021-02-01 16:15:59)

Fix label not getting added on namespace
This will fix the issue of label not getting
added on namespace

# Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

- [x] 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)
- [x] 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

```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 **vdemeester**
You can assign the PR to them by writing `/assign @vdemeester` 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":["vdemeester"]} -->
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/proxy.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/228/pull-tekton-operator-go-coverage/1356275257731715074/artifacts/line-cov.html#file0) | 68.5% | 83.6% | 15.1

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/proxy.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/228/pull-tekton-operator-go-coverage/1356275508953747456/artifacts/line-cov.html#file0) | 68.5% | 83.6% | 15.1

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/proxy.go](https://storage.cloud.google.com/tekton-prow/pr-logs/pull/tektoncd_operator/228/pull-tekton-operator-go-coverage/1356276012379279363/artifacts/line-cov.html#file0) | 68.5% | 83.6% | 15.1

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

This pull-request has been approved by: *<a href="https://github.com/tektoncd/operator/pull/228#pullrequestreview-580559321" title="LGTM">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)~~ [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":[]} -->

Patch:
diff --git a/pkg/reconciler/common/proxy.go b/pkg/reconciler/common/proxy.go
index 8ec3b1ebc..a4de2bf25 100644
--- a/pkg/reconciler/common/proxy.go
+++ b/pkg/reconciler/common/proxy.go
@@ -93,6 +93,7 @@ func InjectLabelOnNamespace() mf.Transformer {
 		if name == "tekton-pipelines" || name == "openshift-pipelines" {
 			labels := u.GetLabels()
 			labels["operator.tekton.dev/disable-proxy"] = "true"
+			u.SetLabels(labels)
 		}
 		return nil
 	}


Test patch:
diff --git a/pkg/reconciler/common/proxy_test.go b/pkg/reconciler/common/proxy_test.go
index bb4cbb149..7751611ad 100644
--- a/pkg/reconciler/common/proxy_test.go
+++ b/pkg/reconciler/common/proxy_test.go
@@ -17,9 +17,11 @@ package common
 
 import (
 	"encoding/json"
+	"path"
 	"sort"
 	"testing"
 
+	mf "github.com/manifestival/manifestival"
 	"gotest.tools/v3/assert"
 	"gotest.tools/v3/env"
 	appsv1 "k8s.io/api/apps/v1"
@@ -182,3 +184,25 @@ func toEnvVar(env map[string]string) []corev1.EnvVar {
 	}
 	return envvar
 }
+
+func TestInjectLabelOnNamespace(t *testing.T) {
+	t.Run("TestInjectLabel", func(t *testing.T) {
+		testData := path.Join("testdata", "test-namespace-inject.yaml")
+
+		manifest, err := mf.ManifestFrom(mf.Recursive(testData))
+		assertNoEror(t, err)
+		newManifest, err := manifest.Transform(InjectLabelOnNamespace())
+		assertNoEror(t, err)
+		for _, resource := range newManifest.Resources() {
+			labels := resource.GetLabels()
+			value, ok := labels["operator.tekton.dev/disable-proxy"]
+			if ok {
+				assert.DeepEqual(t, value, "true")
+			}
+			if !ok {
+				t.Errorf("namespace did not have label")
+
+			}
+		}
+	})
+}
diff --git a/pkg/reconciler/common/testdata/test-namespace-inject.yaml b/pkg/reconciler/common/testdata/test-namespace-inject.yaml
new file mode 100644
index 000000000..d1d2d96c3
--- /dev/null
+++ b/pkg/reconciler/common/testdata/test-namespace-inject.yaml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: tekton-pipelines
+  labels:
+    openshift.io/cluster-monitoring: "true"
+    app.kubernetes.io/instance: default
+    app.kubernetes.io/part-of: tekton-pipelines