Repository: kubernetes/kubernetes (language: go)

Issue:
pull-kubernetes-typecheck doesn't notice compile errors in staging test files
_Originally posted by @liggitt in https://github.com/kubernetes/kubernetes/issues/125571#issuecomment-2198419708_

/sig testing
/area test
/kind bug

`pull-kubernetes-typecheck — Job succeeded.`
yet:
```
ERROR: staging/src/k8s.io/dynamic-resource-allocation/structured/namedresources/cel/compile.go:1: : # k8s.io/dynamic-resource-allocation/structured/namedresources/cel [k8s.io/dynamic-resource-allocation/structured/namedresources/cel.test]
ERROR: staging/src/k8s.io/dynamic-resource-allocation/structured/namedresources/cel/compile_test.go:127:14: undefined: Compiler (typecheck)
```

(I fixed this in that PR, but it should be reproducible by reintroducing a compile error in a test file like that)


Discussion / hints:
/triage accepted

Fix patch:
diff --git a/hack/verify-typecheck.sh b/hack/verify-typecheck.sh
index af9585a1b2ab6..e3f064cc8f1d3 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}"


Test patch:
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 a6f0977204c48..3cf956b3880f8 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 f042dc397d7df..87a1faebd8d6f 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 57f957a1bb059..4ce598bac2855 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 a1ae59bace925..c0a78d9937dab 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 5eb5c9fefea8f..abf46f71e92d1 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 5343007083360..3c0842b20b35c 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
 	}