Repository: kubernetes/kubernetes (language: go)

Issue:
[Failing Test]  TestNestedNumberAsFloat64/found_int64_not_representable_as_float64 is failing on arm64, ppc64le
### Which jobs are failing?

https://prow.k8s.io/job-history/gs/ppc64le-kubernetes/logs/periodic-kubernetes-unit-test-ppc64le

### Which tests are failing?

```

=== FAIL: k8s.io/apimachinery/pkg/apis/meta/v1/unstructured TestNestedNumberAsFloat64/found_int64_not_representable_as_float64 (0.00s)
    helpers_test.go:283: got 9.223372036854776e+18, wanted 0
    helpers_test.go:286: got true, wanted false
    helpers_test.go:290: got nil error, wanted .value accessor error: int64 value 9223372036854775807 cannot be losslessly converted to float64

=== FAIL: k8s.io/apimachinery/pkg/apis/meta/v1/unstructured TestNestedNumberAsFloat64 (0.00s)
```

https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers_test.go#L272


### Since when has it been failing?

Since the testcase addition in change https://github.com/kubernetes/kubernetes/pull/127838

### Testgrid link

https://testgrid.k8s.io/ibm-k8s-unit-tests-ppc64le#periodic-k8s-unit-tests-ppc64le

### Reason for failure (if possible)

The value of MaxInt64 from math package's file [const.go](https://github.com/golang/go/blob/master/src/math/const.go#L50) varies across architectures as mentioned at the top of file.

`// This package does not guarantee bit-identical results across architectures.`

We need to avoid values which trigger implementation defined behavior.

### Anything else we need to know?

We could confirm this failure on `arm64` and `ppc64le` architectures.

### Relevant SIG(s)

/sig testing


Discussion / hints:
cc @benluddy @liggitt 
Looking... I don't think we depend a particular bit representation of the int64 fixture, but double-checking the Go spec, the result of the int64-to-float64 conversion is implementation-defined. I'll figure out how to do this in a portable way.
> The value of MaxInt64 from math package's file [const.go](https://github.com/golang/go/blob/master/src/math/const.go#L50) varies across architectures as mentioned at the top of file.

I don't think that's accurate... MaxInt64 does not vary across architectures... though the float might
This failure introduced almost a week back and happening on arm64 platform as well, wondering why it is unnoticed so far? where can we see all the UT test runs for the arm64 architecture?
/sig api-machinery
/triage accepted
/assign
Similar behaviour fixed in the past, see if this helps - https://github.com/kubernetes/kubernetes/pull/120097

Fix patch:
diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go
index 203c325d26cc5..71f7b163a1cb8 100644
--- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go
+++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go
@@ -20,6 +20,7 @@ import (
 	gojson "encoding/json"
 	"fmt"
 	"io"
+	"math/big"
 	"strings"
 
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -136,10 +137,11 @@ func NestedNumberAsFloat64(obj map[string]interface{}, fields ...string) (float6
 	}
 	switch x := val.(type) {
 	case int64:
-		if x != int64(float64(x)) {
+		f, accuracy := big.NewInt(x).Float64()
+		if accuracy != big.Exact {
 			return 0, false, fmt.Errorf("%v accessor error: int64 value %v cannot be losslessly converted to float64", jsonPath(fields), x)
 		}
-		return float64(x), true, nil
+		return f, true, nil
 	case float64:
 		return x, true, nil
 	default:


Test patch: