Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an int64 version of Quantity that is much faster #25243

Merged
merged 4 commits into from
May 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,10 @@ func parseResourceList(m utilconfig.ConfigurationMap) (api.ResourceList, error)
if err != nil {
return nil, err
}
if q.Amount.Sign() == -1 {
if q.Sign() == -1 {
return nil, fmt.Errorf("resource quantity for %q cannot be negative: %v", k, v)
}
rl[api.ResourceName(k)] = *q
rl[api.ResourceName(k)] = q
default:
return nil, fmt.Errorf("cannot reserve %q resource", k)
}
Expand Down
10 changes: 2 additions & 8 deletions contrib/mesos/pkg/scheduler/resources/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,8 @@ func podResources(pod *api.Pod, resourceName api.ResourceName, def, min resource
}

// add up the request and limit sum for all containers
err = requestSum.Add(request)
if err != nil {
return
}
err = limitSum.Add(limit)
if err != nil {
return
}
requestSum.Add(request)
limitSum.Add(limit)

// optionally write request and limit back
if write {
Expand Down
16 changes: 7 additions & 9 deletions federation/apis/federation/types.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ import (
"errors"
"fmt"
codec1978 "github.com/ugorji/go/codec"
pkg4_inf_v0 "gopkg.in/inf.v0"
pkg1_api "k8s.io/kubernetes/pkg/api"
pkg3_resource "k8s.io/kubernetes/pkg/api/resource"
pkg2_unversioned "k8s.io/kubernetes/pkg/api/unversioned"
pkg5_types "k8s.io/kubernetes/pkg/types"
pkg4_types "k8s.io/kubernetes/pkg/types"
"reflect"
"runtime"
time "time"
Expand Down Expand Up @@ -65,13 +64,12 @@ func init() {
panic(err)
}
if false { // reference the types, but skip this branch at build/run time
var v0 pkg4_inf_v0.Dec
var v1 pkg1_api.ConditionStatus
var v2 pkg3_resource.Quantity
var v3 pkg2_unversioned.Time
var v4 pkg5_types.UID
var v5 time.Time
_, _, _, _, _, _ = v0, v1, v2, v3, v4, v5
var v0 pkg1_api.ConditionStatus
var v1 pkg3_resource.Quantity
var v2 pkg2_unversioned.Time
var v3 pkg4_types.UID
var v4 time.Time
_, _, _, _, _ = v0, v1, v2, v3, v4
}
}

Expand Down
16 changes: 7 additions & 9 deletions federation/apis/federation/v1alpha1/types.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ import (
"errors"
"fmt"
codec1978 "github.com/ugorji/go/codec"
pkg4_inf_v0 "gopkg.in/inf.v0"
pkg3_resource "k8s.io/kubernetes/pkg/api/resource"
pkg2_unversioned "k8s.io/kubernetes/pkg/api/unversioned"
pkg1_v1 "k8s.io/kubernetes/pkg/api/v1"
pkg5_types "k8s.io/kubernetes/pkg/types"
pkg4_types "k8s.io/kubernetes/pkg/types"
"reflect"
"runtime"
time "time"
Expand Down Expand Up @@ -65,13 +64,12 @@ func init() {
panic(err)
}
if false { // reference the types, but skip this branch at build/run time
var v0 pkg4_inf_v0.Dec
var v1 pkg3_resource.Quantity
var v2 pkg2_unversioned.Time
var v3 pkg1_v1.ConditionStatus
var v4 pkg5_types.UID
var v5 time.Time
_, _, _, _, _, _ = v0, v1, v2, v3, v4, v5
var v0 pkg3_resource.Quantity
var v1 pkg2_unversioned.Time
var v2 pkg1_v1.ConditionStatus
var v3 pkg4_types.UID
var v4 time.Time
_, _, _, _, _ = v0, v1, v2, v3, v4
}
}

Expand Down
4 changes: 2 additions & 2 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ else
linux/amd64
linux/arm
linux/arm64
linux/ppc64le
#linux/ppc64le # temporarily disabled due to a linking error
)

# If we update this we should also update the set of golang compilers we build
Expand All @@ -78,7 +78,7 @@ else
linux/386
linux/arm
linux/arm64
linux/ppc64le
#linux/ppc64le # temporarily disabled due to a linking error
darwin/amd64
darwin/386
windows/amd64
Expand Down
11 changes: 1 addition & 10 deletions pkg/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,7 @@ var Semantic = conversion.EqualitiesOrDie(
// TODO: if we decide it's important, it should be safe to start comparing the format.
//
// Uninitialized quantities are equivalent to 0 quantities.
if a.Amount == nil && b.MilliValue() == 0 {
return true
}
if b.Amount == nil && a.MilliValue() == 0 {
return true
}
if a.Amount == nil || b.Amount == nil {
return false
}
return a.Amount.Cmp(b.Amount) == 0
return a.Cmp(b) == 0
},
func(a, b unversioned.Time) bool {
return a.UTC() == b.UTC()
Expand Down
6 changes: 2 additions & 4 deletions pkg/api/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (

"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/labels"

inf "gopkg.in/inf.v0"
)

func TestConversionError(t *testing.T) {
Expand Down Expand Up @@ -56,8 +54,8 @@ func TestSemantic(t *testing.T) {
{resource.Quantity{}, resource.MustParse("0"), true},
{resource.Quantity{}, resource.MustParse("1m"), false},
{
resource.Quantity{Amount: inf.NewDec(5, 0), Format: resource.BinarySI},
resource.Quantity{Amount: inf.NewDec(5, 0), Format: resource.DecimalSI},
resource.NewQuantity(5, resource.BinarySI),
resource.NewQuantity(5, resource.DecimalSI),
true,
},
{resource.MustParse("2m"), resource.MustParse("1m"), false},
Expand Down