diff --git a/cmd/kn/main.go b/cmd/kn/main.go index c130d1dfa..b5e2bfb44 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 f7adda57d..95fd6d8a1 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 306dc0d30..6e37a1580 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, "") } diff --git a/pkg/serving/service_test.go b/pkg/serving/service_test.go index 7e2e16137..6c942f016 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)