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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"knative.dev/client/pkg/kn/config"
|
"knative.dev/client/pkg/kn/config"
|
||||||
|
|
@ -29,10 +27,6 @@ import (
|
||||||
"knative.dev/client/pkg/kn/root"
|
"knative.dev/client/pkg/kn/root"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
os.Exit(runWithExit(os.Args[1:]))
|
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 := make([]metav1beta1.TableColumnDefinition, 0, len(handler.columnDefinitions))
|
||||||
|
|
||||||
columns = append(columns, handler.columnDefinitions...)
|
columns = append(columns, handler.columnDefinitions...)
|
||||||
|
|
||||||
table := &metav1beta1.Table{
|
table := &metav1beta1.Table{
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,13 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
|
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{
|
var charChoices = []string{
|
||||||
"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x",
|
"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x",
|
||||||
"y", "z",
|
"y", "z",
|
||||||
|
|
@ -37,7 +40,7 @@ func (c *revisionTemplContext) Random(l int) string {
|
||||||
chars := make([]string, 0, l)
|
chars := make([]string, 0, l)
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
//nolint:gosec // Weak crypto is fine here, we use it for generating unique keys.
|
//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, "")
|
return strings.Join(chars, "")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
package serving
|
package serving
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
|
|
@ -30,7 +29,7 @@ type generateNameTest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateName(t *testing.T) {
|
func TestGenerateName(t *testing.T) {
|
||||||
rand.Seed(1)
|
revisionNameRand.Seed(1)
|
||||||
someRandomChars := (&revisionTemplContext{}).Random(20)
|
someRandomChars := (&revisionTemplContext{}).Random(20)
|
||||||
service := &servingv1.Service{}
|
service := &servingv1.Service{}
|
||||||
service.Name = "foo"
|
service.Name = "foo"
|
||||||
|
|
@ -45,7 +44,7 @@ func TestGenerateName(t *testing.T) {
|
||||||
{"{{.Random 5}}", "foo-" + someRandomChars[0:5], ""},
|
{"{{.Random 5}}", "foo-" + someRandomChars[0:5], ""},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
rand.Seed(1)
|
revisionNameRand.Seed(1)
|
||||||
name, err := GenerateRevisionName(c.templ, service)
|
name, err := GenerateRevisionName(c.templ, service)
|
||||||
if c.err != "" {
|
if c.err != "" {
|
||||||
assert.ErrorContains(t, err, c.err)
|
assert.ErrorContains(t, err, c.err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue