mirror of https://github.com/knative/client.git
Fixing errors related to Go 1.20 (#1779)
* Fix the errors Go 1.20 introduced * Didn't remove comments * New version of service.go * add linter directive to allow for use of math/rand * Added to changelog * fix issue with tablegenerator.go * remove factory_test.go changes, already fixed in #1777 * Revert changelog changes
This commit is contained in:
parent
954720d0bf
commit
8a2ed4cea3
|
|
@ -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:]))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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, "")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue