Repository: knative/pkg
Pull request #1381 (2020-06-05 04:09:51)

Remove the trailing \n
Due to the parser difference we had 2 different values in WH and in the hash gen

Fixes: https://github.com/knative/serving/issues/8211

/assign @markusthoemmes 

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

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1381#" title="Author self-approved">vagababov</a>*

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

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:

- ~~[configmap/OWNERS](https://github.com/knative/pkg/blob/master/configmap/OWNERS)~~ [vagababov]

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":[]} -->
vagababov: It is important to cut only trailing spaces.
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-pkg-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[configmap/hash-gen/main.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1381/pull-knative-pkg-go-coverage/1268756960551899136/artifacts/line-cov.html#file0) | Do not exist | 65.2% | 

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

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-pkg-unit-tests | 89a90662321daf460f6664edcf29be130e70b8c4 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_pkg/1381/pull-knative-pkg-unit-tests/1268756960556093441) | `/test pull-knative-pkg-unit-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_pkg/1381). [Your PR dashboard](https://gubernator.knative.dev/pr/vagababov).

<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-pkg-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[configmap/hash-gen/main.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1381/pull-knative-pkg-go-coverage/1268777972949585920/artifacts/line-cov.html#file0) | Do not exist | 65.2% | 

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

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-pkg-unit-tests | e4f0e3e750791ce89ef08912f16b88ae8718438d | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_pkg/1381/pull-knative-pkg-unit-tests/1268948092061749251) | `/test pull-knative-pkg-unit-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_pkg/1381). [Your PR dashboard](https://gubernator.knative.dev/pr/vagababov).

<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 -->

Patch:
diff --git a/configmap/example.go b/configmap/example.go
index 78f8e4a57..1bbf3dc7e 100644
--- a/configmap/example.go
+++ b/configmap/example.go
@@ -19,6 +19,7 @@ package configmap
 import (
 	"fmt"
 	"hash/crc32"
+	"strings"
 )
 
 const (
@@ -29,7 +30,9 @@ const (
 	ExampleChecksumAnnotation = "knative.dev/example-checksum"
 )
 
-// Checksum generates a checksum for the example value to be compared against a respective annotation.
+// Checksum generates a checksum for the example value to be compared against
+// a respective annotation.
+// Leading and trailing spaces are ignored.
 func Checksum(value string) string {
-	return fmt.Sprintf("%08x", crc32.ChecksumIEEE([]byte(value)))
+	return fmt.Sprintf("%08x", crc32.ChecksumIEEE([]byte(strings.TrimSpace(value))))
 }


Test patch:
diff --git a/configmap/example_test.go b/configmap/example_test.go
index aafc951f0..d7b291e05 100644
--- a/configmap/example_test.go
+++ b/configmap/example_test.go
@@ -28,6 +28,9 @@ func TestChecksum(t *testing.T) {
 	}, {
 		in:   "1",
 		want: "83dcefb7",
+	}, {
+		in: "   a somewhat longer test			",
+		want: "fefe6f72",
 	}, {
 		in:   "a somewhat longer test",
 		want: "fefe6f72",
diff --git a/configmap/hash-gen/testdata/add_want.yaml b/configmap/hash-gen/testdata/add_want.yaml
index fb131aaf8..374280271 100644
--- a/configmap/hash-gen/testdata/add_want.yaml
+++ b/configmap/hash-gen/testdata/add_want.yaml
@@ -20,7 +20,7 @@ metadata:
   labels:
     serving.knative.dev/release: devel
   annotations:
-    knative.dev/example-checksum: b05e1ab4
+    knative.dev/example-checksum: 81e8e656
 data:
   leave-me: "alone"
   _example: |
diff --git a/configmap/hash-gen/testdata/update_want.yaml b/configmap/hash-gen/testdata/update_want.yaml
index fb131aaf8..374280271 100644
--- a/configmap/hash-gen/testdata/update_want.yaml
+++ b/configmap/hash-gen/testdata/update_want.yaml
@@ -20,7 +20,7 @@ metadata:
   labels:
     serving.knative.dev/release: devel
   annotations:
-    knative.dev/example-checksum: b05e1ab4
+    knative.dev/example-checksum: 81e8e656
 data:
   leave-me: "alone"
   _example: |