diff --git a/hack/verify-typecheck.sh b/hack/verify-typecheck.sh index af9585a1b2a..e3f064cc8f1 100755 --- a/hack/verify-typecheck.sh +++ b/hack/verify-typecheck.sh @@ -26,6 +26,17 @@ source "${KUBE_ROOT}/hack/lib/init.sh" cd "${KUBE_ROOT}" kube::golang::setup_env +kube::util::require-jq + +if [[ $# == 0 ]]; then + # Doing it this way is MUCH faster than simply saying "all", and there doesn't + # seem to be a simpler way to express "this whole workspace". + packages=() + kube::util::read-array packages < <( + go work edit -json | jq -r '.Use[].DiskPath + "/..."' + ) + set -- "${packages[@]}" +fi ret=0 TYPECHECK_SERIAL="${TYPECHECK_SERIAL:-false}" diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go index a6f0977204c..3cf956b3880 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go @@ -37,17 +37,19 @@ func TestCelCostStability(t *testing.T) { }{ {name: "integers", // 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. - obj: objs(math.MaxInt64, math.MaxInt64, math.MaxInt32, math.MaxInt32, math.MaxInt64, math.MaxInt64), + obj: objs(int64(math.MaxInt64), int64(math.MaxInt64), int32(math.MaxInt32), int32(math.MaxInt32), + int64(math.MaxInt64), int64(math.MaxInt64)), schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), expectCost: map[string]int64{ - ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)): 11, + ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))): 11, "self.val1 == self.val6": 5, // integer with no format is the same as int64 "type(self.val1) == int": 4, fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32): 5, // CEL integers are 64 bit }, }, {name: "numbers", - obj: objs(math.MaxFloat64, math.MaxFloat64, math.MaxFloat32, math.MaxFloat32, math.MaxFloat64, math.MaxFloat64, int64(1)), + obj: objs(float64(math.MaxFloat64), float64(math.MaxFloat64), float32(math.MaxFloat32), float32(math.MaxFloat32), + float64(math.MaxFloat64), float64(math.MaxFloat64), int64(1)), schema: schemas(numberType, numberType, floatType, floatType, doubleType, doubleType, doubleType), expectCost: map[string]int64{ ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%f", math.MaxFloat64)): 11, @@ -1218,7 +1220,7 @@ func TestCelEstimatedCostStability(t *testing.T) { // 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), expectCost: map[string]uint64{ - ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)): 8, + ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))): 8, "self.val1 == self.val6": 4, // integer with no format is the same as int64 "type(self.val1) == int": 4, fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32): 5, // CEL integers are 64 bit diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go index f042dc397d7..87a1faebd8d 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go @@ -67,12 +67,13 @@ func TestValidationExpressions(t *testing.T) { // equality, comparisons and type specific functions {name: "integers", // 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. - obj: objs(math.MaxInt64, math.MaxInt64, math.MaxInt32, math.MaxInt32, math.MaxInt64, math.MaxInt64), + obj: objs(int64(math.MaxInt64), int64(math.MaxInt64), int32(math.MaxInt32), int32(math.MaxInt32), + int64(math.MaxInt64), int64(math.MaxInt64)), schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), valid: []string{ - ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)), + ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))), ValsEqualThemselvesAndDataLiteral("self.val3", "self.val4", fmt.Sprintf("%d", math.MaxInt32)), - ValsEqualThemselvesAndDataLiteral("self.val5", "self.val6", fmt.Sprintf("%d", math.MaxInt64)), + ValsEqualThemselvesAndDataLiteral("self.val5", "self.val6", fmt.Sprintf("%d", int64(math.MaxInt64))), "self.val1 == self.val6", // integer with no format is the same as int64 "type(self.val1) == int", fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32), // CEL integers are 64 bit @@ -86,7 +87,8 @@ func TestValidationExpressions(t *testing.T) { }, }, {name: "numbers", - obj: objs(math.MaxFloat64, math.MaxFloat64, math.MaxFloat32, math.MaxFloat32, math.MaxFloat64, math.MaxFloat64, int64(1)), + obj: objs(float64(math.MaxFloat64), float64(math.MaxFloat64), float32(math.MaxFloat32), float32(math.MaxFloat32), + float64(math.MaxFloat64), float64(math.MaxFloat64), int64(1)), schema: schemas(numberType, numberType, floatType, floatType, doubleType, doubleType, doubleType), valid: []string{ ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%f", math.MaxFloat64)), @@ -2842,7 +2844,7 @@ func TestCELValidationLimit(t *testing.T) { }{ { name: "test limit", - obj: objs(math.MaxInt64), + obj: objs(int64(math.MaxInt64)), schema: schemas(integerType), valid: []string{ "self.val1 > 0", diff --git a/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/envelope_test.go b/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/envelope_test.go index 57f957a1bb0..4ce598bac28 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/envelope_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/envelope_test.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + /* Copyright 2022 The Kubernetes Authors. diff --git a/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/grpc_service_unix_test.go b/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/grpc_service_unix_test.go index a1ae59bace9..c0a78d9937d 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/grpc_service_unix_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/grpc_service_unix_test.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + /* Copyright 2022 The Kubernetes Authors. diff --git a/staging/src/k8s.io/component-base/logs/api/v1/types_test.go b/staging/src/k8s.io/component-base/logs/api/v1/types_test.go index 5eb5c9fefea..abf46f71e92 100644 --- a/staging/src/k8s.io/component-base/logs/api/v1/types_test.go +++ b/staging/src/k8s.io/component-base/logs/api/v1/types_test.go @@ -96,7 +96,7 @@ func TestVModule(t *testing.T) { }, }, { - arg: fmt.Sprintf("invalidint32=%d", math.MaxInt32+1), + arg: fmt.Sprintf("invalidint32=%d", uint(math.MaxInt32+1)), expectError: `parsing verbosity in "invalidint32=2147483648": strconv.ParseUint: parsing "2147483648": value out of range`, }, } diff --git a/staging/src/k8s.io/mount-utils/mount_linux_test.go b/staging/src/k8s.io/mount-utils/mount_linux_test.go index 53430070833..3c0842b20b3 100644 --- a/staging/src/k8s.io/mount-utils/mount_linux_test.go +++ b/staging/src/k8s.io/mount-utils/mount_linux_test.go @@ -32,6 +32,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "golang.org/x/exp/constraints" "golang.org/x/sys/unix" utilexec "k8s.io/utils/exec" testexec "k8s.io/utils/exec/testing" @@ -814,9 +815,15 @@ func TestFormatTimeout(t *testing.T) { mu.Unlock() } +// Some platforms define unix.Statfs_t.Flags differently. Our need here is +// pretty constrained, so some aggressive type-conversion is OK. +func mkStatfsFlags[T1 constraints.Integer, T2 constraints.Integer](orig T1, add T2) T1 { + return orig | T1(add) +} + func TestGetUserNSBindMountOptions(t *testing.T) { var testCases = map[string]struct { - flags int64 + flags int32 // smallest size used by any platform we care about mountoptions string }{ "ro": {flags: unix.MS_RDONLY, mountoptions: "ro"}, @@ -831,7 +838,8 @@ func TestGetUserNSBindMountOptions(t *testing.T) { } statfsMock := func(path string, buf *unix.Statfs_t) (err error) { - *buf = unix.Statfs_t{Flags: testCases[path].flags} + *buf = unix.Statfs_t{} + buf.Flags = mkStatfsFlags(buf.Flags, testCases[path].flags) return nil }