Repository: knative/pkg
Pull request #2074 (2021-03-30 07:35:24)

Fix int conversion in statefulset ordinals
# Changes

Fixes https://github.com/knative/pkg/security/code-scanning/1?query=ref%3Arefs%2Fheads%2Fmain

Just a small change really to make the code scanner happy. This is not likely an issue at all, but :shrug:.

/assign @yanweiguo @vagababov 


knative-prow-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 ask for approval from **markusthoemmes** after the PR has been reviewed.

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

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

- **[OWNERS](https://github.com/knative/pkg/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":["markusthoemmes"]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative/pkg/pull/2074?src=pr&el=h1) Report
> Merging [#2074](https://codecov.io/gh/knative/pkg/pull/2074?src=pr&el=desc) (03805d8) into [main](https://codecov.io/gh/knative/pkg/commit/9d92ea16c0d3b2b03ac456782563321030726280?el=desc) (9d92ea1) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/knative/pkg/pull/2074/graphs/tree.svg?width=650&height=150&src=pr&token=rlqpDnfxbO)](https://codecov.io/gh/knative/pkg/pull/2074?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##             main    #2074      +/-   ##
==========================================
+ Coverage   67.36%   67.39%   +0.02%     
==========================================
  Files         215      215              
  Lines        9111     9111              
==========================================
+ Hits         6138     6140       +2     
+ Misses       2698     2697       -1     
+ Partials      275      274       -1     
```


| [Impacted Files](https://codecov.io/gh/knative/pkg/pull/2074?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [leaderelection/config.go](https://codecov.io/gh/knative/pkg/pull/2074/diff?src=pr&el=tree#diff-bGVhZGVyZWxlY3Rpb24vY29uZmlnLmdv) | `77.27% <100.00%> (ø)` | |
| [test/gcs/mock/mock.go](https://codecov.io/gh/knative/pkg/pull/2074/diff?src=pr&el=tree#diff-dGVzdC9nY3MvbW9jay9tb2NrLmdv) | `91.39% <0.00%> (+1.07%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/knative/pkg/pull/2074?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/pkg/pull/2074?src=pr&el=footer). Last update [9d92ea1...03805d8](https://codecov.io/gh/knative/pkg/pull/2074?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

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

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/2074#pullrequestreview-624448956" title="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:

- ~~[OWNERS](https://github.com/knative/pkg/blob/main/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":[]} -->

Patch:
diff --git a/leaderelection/config.go b/leaderelection/config.go
index 96164bd00..3d9df1dc7 100644
--- a/leaderelection/config.go
+++ b/leaderelection/config.go
@@ -134,8 +134,8 @@ type statefulSetID struct {
 
 func (ssID *statefulSetID) Decode(v string) error {
 	if i := strings.LastIndex(v, "-"); i != -1 {
-		ui, err := strconv.ParseUint(v[i+1:], 10, 64)
-		ssID.ordinal = int(ui)
+		ui, err := strconv.Atoi(v[i+1:])
+		ssID.ordinal = ui
 		ssID.ssName = v[:i]
 		return err
 	}


Test patch:
diff --git a/leaderelection/config_test.go b/leaderelection/config_test.go
index ad2e5185f..0cfa4b3cd 100644
--- a/leaderelection/config_test.go
+++ b/leaderelection/config_test.go
@@ -211,7 +211,7 @@ func TestNewStatefulSetConfig(t *testing.T) {
 	}, {
 		name:    "failure with invalid name",
 		pod:     "as-abcd",
-		wantErr: `envconfig.Process: assigning STATEFUL_CONTROLLER_ORDINAL to StatefulSetID: converting 'as-abcd' to type leaderelection.statefulSetID. details: strconv.ParseUint: parsing "abcd": invalid syntax`,
+		wantErr: `envconfig.Process: assigning STATEFUL_CONTROLLER_ORDINAL to StatefulSetID: converting 'as-abcd' to type leaderelection.statefulSetID. details: strconv.Atoi: parsing "abcd": invalid syntax`,
 	}}
 
 	for _, tc := range cases {