Repository: knative/client
Pull request #1779 (2023-02-15 19:21:32)

Fixing errors related to Go 1.20
## Description

This pull request will fix errors that came about with Go 1.20 deprecating rand.Seed.

## Changes

<!-- Please add list of more detailed changes. These changes should be reflected also in the commit messages -->

* Changed loop in tablegenerator.go to use the variadic function
* Removed the random number generator seed from main.go, and added a package local variable doing this to service.go, since this is the only place the seed from main.go was used.

## Reference

Issue #1775 

**Release Note**

```release-note
 Fix deprecated functions related to Go 1.20 
```

<!--
Please add an entry to CHANGELOG.adoc file, too, as part of your Pull Request.

In the following cases, add a short description of PR to the unreleased section in CHANGELOG.adoc:

- 🎁 New feature
- 🐛 Bug fix
- ✨ Feature Update
- 🐣 Refactoring
- 🗑️ Remove feature or internal logic

See other entries in CHANGELOG.adoc as an example for how to add the entry, including a reference to the corresponding issue/PR

PLEASE DON'T ADD THAT LINE HERE IN THE PULL-REQUEST DESCRIPTION BUT DIRECTLY IN CHANGELOG.ADOC AND ADD CHANGELOG.ADOC AS PART OF YOUR PULL-REQUEST.
-->

<!--
To automatically lint go code in this pull request uncomment the line below. You get feedback as comments on your pull request then -->



linux-foundation-easycla[bot]:  <a href="https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/25767896/161563145/1779/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-not-signed.svg" alt="CLA Not Signed" align="left" height="28" width="328"></a><br/><br /><ul><li><a href='https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/25767896/161563145/1779/#/?version=2' target='_blank'>:x:</a> - login: @scottmason88 / name: Scott Mason . The commit (b2864b65e637326c40c5197cfda74a05f7cb36c8, 703355bd768f28ecb9c730d6d129357ce836c2a5, cf7c913e182ac3f96cdeffd909c19ff631afb917, 917d04f2e45bb0d62de74bbe80455aee0e72df03, 131375feb4e15c8e75e28682aad831d0d94a4d90) is not authorized under a signed CLA. <a href='https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/25767896/161563145/1779/#/?version=2' target='_blank'>Please click here to be authorized</a>. For further assistance with EasyCLA, <a href='https://jira.linuxfoundation.org/servicedesk/customer/portal/4' target='_blank'>please submit a support request ticket</a>.</li></ul>
knative-prow-robot: 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>
knative-prow[bot]: Welcome @scottmason88! It looks like this is your first PR to knative/client 🎉
knative-prow[bot]: Hi @scottmason88. Thanks for your PR.

I'm waiting for a [knative](https://github.com/orgs/knative/people) member to verify that this patch is reasonable to test. If it is, they should reply with `/ok-to-test` on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should [join the org](https://github.com/orgs/knative/people) to skip this step.

Once the patch is verified, the new status will be reflected by the `ok-to-test` label.

I understand the commands that are listed [here](https://go.k8s.io/bot-commands?repo=knative%2Fclient).

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

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

This pull-request has been approved by: *<a href="https://github.com/knative/client/pull/1779#" title="Author self-approved">scottmason88</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign dprotaso for approval. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

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

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

- **[OWNERS](https://github.com/knative/client/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":["dprotaso"]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative/client/pull/1779?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) Report
Base: **79.88**% // Head: **79.87**% // Decreases project coverage by **`-0.01%`** :warning:
> Coverage data is based on head [(`1d24121`)](https://codecov.io/gh/knative/client/pull/1779?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) compared to base [(`badd909`)](https://codecov.io/gh/knative/client/commit/badd909328f3e9969f7ecf65c780daa26f2e0499?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #1779      +/-   ##
==========================================
- Coverage   79.88%   79.87%   -0.01%     
==========================================
  Files         174      174              
  Lines       13594    13593       -1     
==========================================
- Hits        10859    10858       -1     
  Misses       1992     1992              
  Partials      743      743              
```


| [Impacted Files](https://codecov.io/gh/knative/client/pull/1779?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) | Coverage Δ | |
|---|---|---|
| [cmd/kn/main.go](https://codecov.io/gh/knative/client/pull/1779?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative#diff-Y21kL2tuL21haW4uZ28=) | `87.82% <ø> (-0.21%)` | :arrow_down: |
| [pkg/printers/tablegenerator.go](https://codecov.io/gh/knative/client/pull/1779?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative#diff-cGtnL3ByaW50ZXJzL3RhYmxlZ2VuZXJhdG9yLmdv) | `100.00% <100.00%> (ø)` | |
| [pkg/serving/service.go](https://codecov.io/gh/knative/client/pull/1779?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative#diff-cGtnL3NlcnZpbmcvc2VydmljZS5nbw==) | `90.32% <100.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/knative/client/pull/1779?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative).


Patch:
diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES
index 7a2fb71d..4989f6f5 100644
--- a/OWNERS_ALIASES
+++ b/OWNERS_ALIASES
@@ -123,6 +123,11 @@ aliases:
   - izabelacg
   - jsanin-vmw
   - kauana
+  - pradnyavmw
+  - retocode
+  - skonto
+  serving-triage:
+  - KauzClay
   - retocode
   - skonto
   serving-wg-leads:
diff --git a/cmd/kn/main.go b/cmd/kn/main.go
index c130d1df..b5e2bfb4 100644
--- a/cmd/kn/main.go
+++ b/cmd/kn/main.go
@@ -17,11 +17,9 @@ package main
 import (
 	"errors"
 	"fmt"
-	"math/rand"
 	"os"
 	"regexp"
 	"strings"
-	"time"
 
 	"github.com/spf13/cobra"
 	"knative.dev/client/pkg/kn/config"
@@ -29,10 +27,6 @@ import (
 	"knative.dev/client/pkg/kn/root"
 )
 
-func init() {
-	rand.Seed(time.Now().UnixNano())
-}
-
 func main() {
 	os.Exit(runWithExit(os.Args[1:]))
 }
diff --git a/pkg/printers/tablegenerator.go b/pkg/printers/tablegenerator.go
index f7adda57..95fd6d8a 100644
--- a/pkg/printers/tablegenerator.go
+++ b/pkg/printers/tablegenerator.go
@@ -74,6 +74,7 @@ func (h *HumanReadablePrinter) GenerateTable(obj runtime.Object, options PrintOp
 	}
 
 	columns := make([]metav1beta1.TableColumnDefinition, 0, len(handler.columnDefinitions))
+
 	columns = append(columns, handler.columnDefinitions...)
 
 	table := &metav1beta1.Table{
diff --git a/pkg/serving/service.go b/pkg/serving/service.go
index 306dc0d3..6e37a158 100644
--- a/pkg/serving/service.go
+++ b/pkg/serving/service.go
@@ -19,10 +19,13 @@ import (
 	"math/rand"
 	"strings"
 	"text/template"
+	"time"
 
 	servingv1 "knative.dev/serving/pkg/apis/serving/v1"
 )
 
+var revisionNameRand = rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec // Weak crypto is fine here, we use it for generating unique keys.
+
 var charChoices = []string{
 	"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x",
 	"y", "z",
@@ -37,7 +40,7 @@ func (c *revisionTemplContext) Random(l int) string {
 	chars := make([]string, 0, l)
 	for i := 0; i < l; i++ {
 		//nolint:gosec // Weak crypto is fine here, we use it for generating unique keys.
-		chars = append(chars, charChoices[rand.Int()%len(charChoices)])
+		chars = append(chars, charChoices[revisionNameRand.Int()%len(charChoices)])
 	}
 	return strings.Join(chars, "")
 }


Test patch:
diff --git a/pkg/serving/service_test.go b/pkg/serving/service_test.go
index 7e2e1613..6c942f01 100644
--- a/pkg/serving/service_test.go
+++ b/pkg/serving/service_test.go
@@ -15,7 +15,6 @@
 package serving
 
 import (
-	"math/rand"
 	"testing"
 
 	"gotest.tools/v3/assert"
@@ -30,7 +29,7 @@ type generateNameTest struct {
 }
 
 func TestGenerateName(t *testing.T) {
-	rand.Seed(1)
+	revisionNameRand.Seed(1)
 	someRandomChars := (&revisionTemplContext{}).Random(20)
 	service := &servingv1.Service{}
 	service.Name = "foo"
@@ -45,7 +44,7 @@ func TestGenerateName(t *testing.T) {
 		{"{{.Random 5}}", "foo-" + someRandomChars[0:5], ""},
 	}
 	for _, c := range cases {
-		rand.Seed(1)
+		revisionNameRand.Seed(1)
 		name, err := GenerateRevisionName(c.templ, service)
 		if c.err != "" {
 			assert.ErrorContains(t, err, c.err)