From 3fbe93371258704e56dc741218b4faa399395f8a Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 4 Jul 2022 17:24:24 +0200 Subject: envVarValueResourceFieldRef: use int64 for value int can be 32 or 64 bit depending on the architecture. The total memory is int64 so we have to use int64 for the value as well otherwise we get an overflow on 32 bit systems. Fixes #14819 Signed-off-by: Paul Holzinger --- pkg/specgen/generate/kube/kube.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pkg') diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index 689c740f0..39e15f950 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -810,8 +810,8 @@ func envVarValueResourceFieldRef(env v1.EnvVar, opts *CtrSpecGenOptions) (*strin } // k8s rounds up the result to the nearest integer - intValue := int(math.Ceil(value.AsApproximateFloat64() / divisor.AsApproximateFloat64())) - stringValue := strconv.Itoa(intValue) + intValue := int64(math.Ceil(value.AsApproximateFloat64() / divisor.AsApproximateFloat64())) + stringValue := strconv.FormatInt(intValue, 10) return &stringValue, nil } -- cgit v1.2.3-54-g00ecf From 5b1867923e1f1787e0675e9a808c3385b6348eee Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 4 Jul 2022 17:32:13 +0200 Subject: TestEnvVarValue: fix assertion assert.Equal() already follows to pointer and compares by value so we can just directly pass the values. This will make errors much more obvious. Also remove the fmt.Println() since the error now contains the values. Signed-off-by: Paul Holzinger --- pkg/specgen/generate/kube/play_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'pkg') diff --git a/pkg/specgen/generate/kube/play_test.go b/pkg/specgen/generate/kube/play_test.go index e01d62b08..466dab610 100644 --- a/pkg/specgen/generate/kube/play_test.go +++ b/pkg/specgen/generate/kube/play_test.go @@ -2,7 +2,6 @@ package kube import ( "encoding/json" - "fmt" "math" "runtime" "strconv" @@ -777,8 +776,7 @@ func TestEnvVarValue(t *testing.T) { if test.expected == nilString { assert.Nil(t, result) } else { - fmt.Println(*result, test.expected) - assert.Equal(t, &(test.expected), result) + assert.Equal(t, test.expected, *result) } }) } -- cgit v1.2.3-54-g00ecf From 33a474286b7e64429f73d9faf4f7e35e4b815bef Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 4 Jul 2022 18:09:30 +0200 Subject: pkg/machine: add missing build tags to tests Machine can only run on amd64 and arm64 platforms so we need to make sure the test are only run on those platforms. We do not have CI checks for this but it fails in debian build infra since debian supports many other architectures as well. Signed-off-by: Paul Holzinger --- pkg/machine/config_test.go | 3 +++ pkg/machine/qemu/config_test.go | 3 +++ pkg/machine/qemu/machine_test.go | 3 +++ 3 files changed, 9 insertions(+) (limited to 'pkg') diff --git a/pkg/machine/config_test.go b/pkg/machine/config_test.go index d9fc5425e..ca08660b9 100644 --- a/pkg/machine/config_test.go +++ b/pkg/machine/config_test.go @@ -1,3 +1,6 @@ +//go:build amd64 || arm64 +// +build amd64 arm64 + package machine import ( diff --git a/pkg/machine/qemu/config_test.go b/pkg/machine/qemu/config_test.go index 4d96ec6e7..72cb3ed90 100644 --- a/pkg/machine/qemu/config_test.go +++ b/pkg/machine/qemu/config_test.go @@ -1,3 +1,6 @@ +//go:build (amd64 && !windows) || (arm64 && !windows) +// +build amd64,!windows arm64,!windows + package qemu import ( diff --git a/pkg/machine/qemu/machine_test.go b/pkg/machine/qemu/machine_test.go index 62ca6068a..4c393d0f4 100644 --- a/pkg/machine/qemu/machine_test.go +++ b/pkg/machine/qemu/machine_test.go @@ -1,3 +1,6 @@ +//go:build (amd64 && !windows) || (arm64 && !windows) +// +build amd64,!windows arm64,!windows + package qemu import ( -- cgit v1.2.3-54-g00ecf