mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Move Capacity from NodeSpec to NodeStatus
This commit is contained in:
parent
8183a4805e
commit
5a11748018
@ -951,9 +951,6 @@ type EndpointsList struct {
|
|||||||
|
|
||||||
// NodeSpec describes the attributes that a node is created with.
|
// NodeSpec describes the attributes that a node is created with.
|
||||||
type NodeSpec struct {
|
type NodeSpec struct {
|
||||||
// Capacity represents the available resources of a node.
|
|
||||||
Capacity ResourceList `json:"capacity,omitempty"`
|
|
||||||
|
|
||||||
// PodCIDR represents the pod IP range assigned to the node
|
// PodCIDR represents the pod IP range assigned to the node
|
||||||
// Note: assigning IP ranges to nodes might need to be revisited when we support migratable IPs.
|
// Note: assigning IP ranges to nodes might need to be revisited when we support migratable IPs.
|
||||||
PodCIDR string `json:"podCIDR,omitempty"`
|
PodCIDR string `json:"podCIDR,omitempty"`
|
||||||
@ -977,6 +974,8 @@ type NodeSystemInfo struct {
|
|||||||
|
|
||||||
// NodeStatus is information about the current status of a node.
|
// NodeStatus is information about the current status of a node.
|
||||||
type NodeStatus struct {
|
type NodeStatus struct {
|
||||||
|
// Capacity represents the available resources of a node.
|
||||||
|
Capacity ResourceList `json:"capacity,omitempty"`
|
||||||
// NodePhase is the current lifecycle phase of the node.
|
// NodePhase is the current lifecycle phase of the node.
|
||||||
Phase NodePhase `json:"phase,omitempty"`
|
Phase NodePhase `json:"phase,omitempty"`
|
||||||
// Conditions is an array of current node conditions.
|
// Conditions is an array of current node conditions.
|
||||||
|
@ -704,7 +704,7 @@ func init() {
|
|||||||
out.PodCIDR = in.Spec.PodCIDR
|
out.PodCIDR = in.Spec.PodCIDR
|
||||||
out.ExternalID = in.Spec.ExternalID
|
out.ExternalID = in.Spec.ExternalID
|
||||||
out.Unschedulable = in.Spec.Unschedulable
|
out.Unschedulable = in.Spec.Unschedulable
|
||||||
return s.Convert(&in.Spec.Capacity, &out.NodeResources.Capacity, 0)
|
return s.Convert(&in.Status.Capacity, &out.NodeResources.Capacity, 0)
|
||||||
},
|
},
|
||||||
func(in *Minion, out *newer.Node, s conversion.Scope) error {
|
func(in *Minion, out *newer.Node, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
@ -736,7 +736,7 @@ func init() {
|
|||||||
out.Spec.PodCIDR = in.PodCIDR
|
out.Spec.PodCIDR = in.PodCIDR
|
||||||
out.Spec.ExternalID = in.ExternalID
|
out.Spec.ExternalID = in.ExternalID
|
||||||
out.Spec.Unschedulable = in.Unschedulable
|
out.Spec.Unschedulable = in.Unschedulable
|
||||||
return s.Convert(&in.NodeResources.Capacity, &out.Spec.Capacity, 0)
|
return s.Convert(&in.NodeResources.Capacity, &out.Status.Capacity, 0)
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.LimitRange, out *LimitRange, s conversion.Scope) error {
|
func(in *newer.LimitRange, out *LimitRange, s conversion.Scope) error {
|
||||||
|
@ -636,7 +636,7 @@ func init() {
|
|||||||
out.PodCIDR = in.Spec.PodCIDR
|
out.PodCIDR = in.Spec.PodCIDR
|
||||||
out.ExternalID = in.Spec.ExternalID
|
out.ExternalID = in.Spec.ExternalID
|
||||||
out.Unschedulable = in.Spec.Unschedulable
|
out.Unschedulable = in.Spec.Unschedulable
|
||||||
return s.Convert(&in.Spec.Capacity, &out.NodeResources.Capacity, 0)
|
return s.Convert(&in.Status.Capacity, &out.NodeResources.Capacity, 0)
|
||||||
},
|
},
|
||||||
func(in *Minion, out *newer.Node, s conversion.Scope) error {
|
func(in *Minion, out *newer.Node, s conversion.Scope) error {
|
||||||
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
|
||||||
@ -668,7 +668,7 @@ func init() {
|
|||||||
out.Spec.PodCIDR = in.PodCIDR
|
out.Spec.PodCIDR = in.PodCIDR
|
||||||
out.Spec.ExternalID = in.ExternalID
|
out.Spec.ExternalID = in.ExternalID
|
||||||
out.Spec.Unschedulable = in.Unschedulable
|
out.Spec.Unschedulable = in.Unschedulable
|
||||||
return s.Convert(&in.NodeResources.Capacity, &out.Spec.Capacity, 0)
|
return s.Convert(&in.NodeResources.Capacity, &out.Status.Capacity, 0)
|
||||||
},
|
},
|
||||||
|
|
||||||
func(in *newer.LimitRange, out *LimitRange, s conversion.Scope) error {
|
func(in *newer.LimitRange, out *LimitRange, s conversion.Scope) error {
|
||||||
|
@ -952,9 +952,6 @@ type EndpointsList struct {
|
|||||||
|
|
||||||
// NodeSpec describes the attributes that a node is created with.
|
// NodeSpec describes the attributes that a node is created with.
|
||||||
type NodeSpec struct {
|
type NodeSpec struct {
|
||||||
// Capacity represents the available resources of a node.
|
|
||||||
// see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/resources.md for more details.
|
|
||||||
Capacity ResourceList `json:"capacity,omitempty" description:"compute resource capacity of the node; https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/resources.md"`
|
|
||||||
// PodCIDR represents the pod IP range assigned to the node
|
// PodCIDR represents the pod IP range assigned to the node
|
||||||
PodCIDR string `json:"podCIDR,omitempty" description:"pod IP range assigned to the node"`
|
PodCIDR string `json:"podCIDR,omitempty" description:"pod IP range assigned to the node"`
|
||||||
// External ID of the node assigned by some machine database (e.g. a cloud provider)
|
// External ID of the node assigned by some machine database (e.g. a cloud provider)
|
||||||
@ -975,6 +972,9 @@ type NodeSystemInfo struct {
|
|||||||
|
|
||||||
// NodeStatus is information about the current status of a node.
|
// NodeStatus is information about the current status of a node.
|
||||||
type NodeStatus struct {
|
type NodeStatus struct {
|
||||||
|
// Capacity represents the available resources of a node.
|
||||||
|
// see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/resources.md for more details.
|
||||||
|
Capacity ResourceList `json:"capacity,omitempty" description:"compute resource capacity of the node; https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/resources.md"`
|
||||||
// NodePhase is the current lifecycle phase of the node.
|
// NodePhase is the current lifecycle phase of the node.
|
||||||
Phase NodePhase `json:"phase,omitempty" description:"most recently observed lifecycle phase of the node"`
|
Phase NodePhase `json:"phase,omitempty" description:"most recently observed lifecycle phase of the node"`
|
||||||
// Conditions is an array of current node conditions.
|
// Conditions is an array of current node conditions.
|
||||||
|
@ -910,18 +910,18 @@ func ValidateMinion(node *api.Node) errs.ValidationErrorList {
|
|||||||
allErrs := errs.ValidationErrorList{}
|
allErrs := errs.ValidationErrorList{}
|
||||||
allErrs = append(allErrs, ValidateObjectMeta(&node.ObjectMeta, false, ValidateNodeName).Prefix("metadata")...)
|
allErrs = append(allErrs, ValidateObjectMeta(&node.ObjectMeta, false, ValidateNodeName).Prefix("metadata")...)
|
||||||
// Capacity is required. Within capacity, memory and cpu resources are required.
|
// Capacity is required. Within capacity, memory and cpu resources are required.
|
||||||
if len(node.Spec.Capacity) == 0 {
|
if len(node.Status.Capacity) == 0 {
|
||||||
allErrs = append(allErrs, errs.NewFieldRequired("spec.Capacity"))
|
allErrs = append(allErrs, errs.NewFieldRequired("status.Capacity"))
|
||||||
} else {
|
} else {
|
||||||
if val, ok := node.Spec.Capacity[api.ResourceMemory]; !ok {
|
if val, ok := node.Status.Capacity[api.ResourceMemory]; !ok {
|
||||||
allErrs = append(allErrs, errs.NewFieldRequired("spec.Capacity[memory]"))
|
allErrs = append(allErrs, errs.NewFieldRequired("status.Capacity[memory]"))
|
||||||
} else if val.Value() < 0 {
|
} else if val.Value() < 0 {
|
||||||
allErrs = append(allErrs, errs.NewFieldInvalid("spec.Capacity[memory]", val, "memory capacity cannot be negative"))
|
allErrs = append(allErrs, errs.NewFieldInvalid("status.Capacity[memory]", val, "memory capacity cannot be negative"))
|
||||||
}
|
}
|
||||||
if val, ok := node.Spec.Capacity[api.ResourceCPU]; !ok {
|
if val, ok := node.Status.Capacity[api.ResourceCPU]; !ok {
|
||||||
allErrs = append(allErrs, errs.NewFieldRequired("spec.Capacity[cpu]"))
|
allErrs = append(allErrs, errs.NewFieldRequired("status.Capacity[cpu]"))
|
||||||
} else if val.Value() < 0 {
|
} else if val.Value() < 0 {
|
||||||
allErrs = append(allErrs, errs.NewFieldInvalid("spec.Capacity[cpu]", val, "cpu capacity cannot be negative"))
|
allErrs = append(allErrs, errs.NewFieldInvalid("status.Capacity[cpu]", val, "cpu capacity cannot be negative"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -949,7 +949,7 @@ func ValidateMinionUpdate(oldMinion *api.Node, minion *api.Node) errs.Validation
|
|||||||
// Ignore metadata changes now that they have been tested
|
// Ignore metadata changes now that they have been tested
|
||||||
oldMinion.ObjectMeta = minion.ObjectMeta
|
oldMinion.ObjectMeta = minion.ObjectMeta
|
||||||
// Allow users to update capacity
|
// Allow users to update capacity
|
||||||
oldMinion.Spec.Capacity = minion.Spec.Capacity
|
oldMinion.Status.Capacity = minion.Status.Capacity
|
||||||
// Allow users to unschedule node
|
// Allow users to unschedule node
|
||||||
oldMinion.Spec.Unschedulable = minion.Spec.Unschedulable
|
oldMinion.Spec.Unschedulable = minion.Spec.Unschedulable
|
||||||
// Clear status
|
// Clear status
|
||||||
|
@ -1822,15 +1822,15 @@ func TestValidateMinion(t *testing.T) {
|
|||||||
Addresses: []api.NodeAddress{
|
Addresses: []api.NodeAddress{
|
||||||
{Type: api.NodeLegacyHostIP, Address: "something"},
|
{Type: api.NodeLegacyHostIP, Address: "something"},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
Spec: api.NodeSpec{
|
|
||||||
ExternalID: "external",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
api.ResourceName("my.org/gpu"): resource.MustParse("10"),
|
api.ResourceName("my.org/gpu"): resource.MustParse("10"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "external",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
@ -1840,14 +1840,14 @@ func TestValidateMinion(t *testing.T) {
|
|||||||
Addresses: []api.NodeAddress{
|
Addresses: []api.NodeAddress{
|
||||||
{Type: api.NodeLegacyHostIP, Address: "something"},
|
{Type: api.NodeLegacyHostIP, Address: "something"},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
Spec: api.NodeSpec{
|
|
||||||
ExternalID: "external",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("0"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("0"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "external",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, successCase := range successCases {
|
for _, successCase := range successCases {
|
||||||
@ -1864,34 +1864,36 @@ func TestValidateMinion(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Status: api.NodeStatus{
|
Status: api.NodeStatus{
|
||||||
Addresses: []api.NodeAddress{},
|
Addresses: []api.NodeAddress{},
|
||||||
},
|
|
||||||
Spec: api.NodeSpec{
|
|
||||||
ExternalID: "external",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "external",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"invalid-labels": {
|
"invalid-labels": {
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "abc-123",
|
Name: "abc-123",
|
||||||
Labels: invalidSelector,
|
Labels: invalidSelector,
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
ExternalID: "external",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "external",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"missing-external-id": {
|
"missing-external-id": {
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "abc-123",
|
Name: "abc-123",
|
||||||
Labels: validSelector,
|
Labels: validSelector,
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
@ -1912,50 +1914,58 @@ func TestValidateMinion(t *testing.T) {
|
|||||||
Name: "abc-123",
|
Name: "abc-123",
|
||||||
Labels: validSelector,
|
Labels: validSelector,
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
ExternalID: "external",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "external",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"missing-cpu": {
|
"missing-cpu": {
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "abc-123",
|
Name: "abc-123",
|
||||||
Labels: validSelector,
|
Labels: validSelector,
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
ExternalID: "external",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "external",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"invalid-memory": {
|
"invalid-memory": {
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "abc-123",
|
Name: "abc-123",
|
||||||
Labels: validSelector,
|
Labels: validSelector,
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
ExternalID: "external",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("-10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("-10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "external",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"invalid-cpu": {
|
"invalid-cpu": {
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "abc-123",
|
Name: "abc-123",
|
||||||
Labels: validSelector,
|
Labels: validSelector,
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
ExternalID: "external",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("-10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("-10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "external",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for k, v := range errorCases {
|
for k, v := range errorCases {
|
||||||
@ -1966,14 +1976,14 @@ func TestValidateMinion(t *testing.T) {
|
|||||||
for i := range errs {
|
for i := range errs {
|
||||||
field := errs[i].(*errors.ValidationError).Field
|
field := errs[i].(*errors.ValidationError).Field
|
||||||
expectedFields := map[string]bool{
|
expectedFields := map[string]bool{
|
||||||
"metadata.name": true,
|
"metadata.name": true,
|
||||||
"metadata.labels": true,
|
"metadata.labels": true,
|
||||||
"metadata.annotations": true,
|
"metadata.annotations": true,
|
||||||
"metadata.namespace": true,
|
"metadata.namespace": true,
|
||||||
"spec.Capacity": true,
|
"status.Capacity": true,
|
||||||
"spec.Capacity[memory]": true,
|
"status.Capacity[memory]": true,
|
||||||
"spec.Capacity[cpu]": true,
|
"status.Capacity[cpu]": true,
|
||||||
"spec.ExternalID": true,
|
"spec.ExternalID": true,
|
||||||
}
|
}
|
||||||
if expectedFields[field] == false {
|
if expectedFields[field] == false {
|
||||||
t.Errorf("%s: missing prefix for: %v", k, errs[i])
|
t.Errorf("%s: missing prefix for: %v", k, errs[i])
|
||||||
@ -2032,7 +2042,7 @@ func TestValidateMinionUpdate(t *testing.T) {
|
|||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceCPU: resource.MustParse("10000"),
|
api.ResourceCPU: resource.MustParse("10000"),
|
||||||
api.ResourceMemory: resource.MustParse("100"),
|
api.ResourceMemory: resource.MustParse("100"),
|
||||||
@ -2042,7 +2052,7 @@ func TestValidateMinionUpdate(t *testing.T) {
|
|||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceCPU: resource.MustParse("100"),
|
api.ResourceCPU: resource.MustParse("100"),
|
||||||
api.ResourceMemory: resource.MustParse("10000"),
|
api.ResourceMemory: resource.MustParse("10000"),
|
||||||
@ -2054,7 +2064,7 @@ func TestValidateMinionUpdate(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
Labels: map[string]string{"bar": "foo"},
|
Labels: map[string]string{"bar": "foo"},
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceCPU: resource.MustParse("10000"),
|
api.ResourceCPU: resource.MustParse("10000"),
|
||||||
api.ResourceMemory: resource.MustParse("100"),
|
api.ResourceMemory: resource.MustParse("100"),
|
||||||
@ -2065,7 +2075,7 @@ func TestValidateMinionUpdate(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
Labels: map[string]string{"bar": "fooobaz"},
|
Labels: map[string]string{"bar": "fooobaz"},
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceCPU: resource.MustParse("100"),
|
api.ResourceCPU: resource.MustParse("100"),
|
||||||
api.ResourceMemory: resource.MustParse("10000"),
|
api.ResourceMemory: resource.MustParse("10000"),
|
||||||
|
@ -31,7 +31,7 @@ type NodesInterface interface {
|
|||||||
|
|
||||||
type NodeInterface interface {
|
type NodeInterface interface {
|
||||||
Get(name string) (result *api.Node, err error)
|
Get(name string) (result *api.Node, err error)
|
||||||
Create(minion *api.Node) (*api.Node, error)
|
Create(node *api.Node) (*api.Node, error)
|
||||||
List() (*api.NodeList, error)
|
List() (*api.NodeList, error)
|
||||||
Delete(name string) error
|
Delete(name string) error
|
||||||
Update(*api.Node) (*api.Node, error)
|
Update(*api.Node) (*api.Node, error)
|
||||||
@ -43,13 +43,13 @@ type nodes struct {
|
|||||||
r *Client
|
r *Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// newNodes returns a nodes object. Uses "minions" as the
|
// newNodes returns a nodes object.
|
||||||
// URL resource name for v1beta1 and v1beta2.
|
|
||||||
func newNodes(c *Client) *nodes {
|
func newNodes(c *Client) *nodes {
|
||||||
return &nodes{c}
|
return &nodes{c}
|
||||||
}
|
}
|
||||||
|
|
||||||
// resourceName returns node's URL resource name based on resource version.
|
// resourceName returns node's URL resource name based on resource version.
|
||||||
|
// Uses "minions" as the URL resource name for v1beta1 and v1beta2.
|
||||||
func (c *nodes) resourceName() string {
|
func (c *nodes) resourceName() string {
|
||||||
if api.PreV1Beta3(c.r.APIVersion()) {
|
if api.PreV1Beta3(c.r.APIVersion()) {
|
||||||
return "minions"
|
return "minions"
|
||||||
@ -58,9 +58,9 @@ func (c *nodes) resourceName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new node.
|
// Create creates a new node.
|
||||||
func (c *nodes) Create(minion *api.Node) (*api.Node, error) {
|
func (c *nodes) Create(node *api.Node) (*api.Node, error) {
|
||||||
result := &api.Node{}
|
result := &api.Node{}
|
||||||
err := c.r.Post().Resource(c.resourceName()).Body(minion).Do().Into(result)
|
err := c.r.Post().Resource(c.resourceName()).Body(node).Do().Into(result)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,13 +84,13 @@ func (c *nodes) Delete(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update updates an existing node.
|
// Update updates an existing node.
|
||||||
func (c *nodes) Update(minion *api.Node) (*api.Node, error) {
|
func (c *nodes) Update(node *api.Node) (*api.Node, error) {
|
||||||
result := &api.Node{}
|
result := &api.Node{}
|
||||||
if len(minion.ResourceVersion) == 0 {
|
if len(node.ResourceVersion) == 0 {
|
||||||
err := fmt.Errorf("invalid update object, missing resource version: %v", minion)
|
err := fmt.Errorf("invalid update object, missing resource version: %v", node)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err := c.r.Put().Resource(c.resourceName()).Name(minion.Name).Body(minion).Do().Into(result)
|
err := c.r.Put().Resource(c.resourceName()).Name(node.Name).Body(node).Do().Into(result)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
@ -69,11 +69,13 @@ func TestCreateMinion(t *testing.T) {
|
|||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "minion-1",
|
Name: "minion-1",
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceCPU: resource.MustParse("1000m"),
|
api.ResourceCPU: resource.MustParse("1000m"),
|
||||||
api.ResourceMemory: resource.MustParse("1Mi"),
|
api.ResourceMemory: resource.MustParse("1Mi"),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
Unschedulable: false,
|
Unschedulable: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -109,11 +111,13 @@ func TestUpdateMinion(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceCPU: resource.MustParse("1000m"),
|
api.ResourceCPU: resource.MustParse("1000m"),
|
||||||
api.ResourceMemory: resource.MustParse("1Mi"),
|
api.ResourceMemory: resource.MustParse("1Mi"),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
Unschedulable: true,
|
Unschedulable: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
@ -292,7 +292,7 @@ func (nc *NodeController) populateNodeInfo(node *api.Node) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for key, value := range nodeInfo.Capacity {
|
for key, value := range nodeInfo.Capacity {
|
||||||
node.Spec.Capacity[key] = value
|
node.Status.Capacity[key] = value
|
||||||
}
|
}
|
||||||
if node.Status.NodeInfo.BootID != "" &&
|
if node.Status.NodeInfo.BootID != "" &&
|
||||||
node.Status.NodeInfo.BootID != nodeInfo.NodeSystemInfo.BootID {
|
node.Status.NodeInfo.BootID != nodeInfo.NodeSystemInfo.BootID {
|
||||||
@ -521,8 +521,11 @@ func (nc *NodeController) GetStaticNodesWithSpec() (*api.NodeList, error) {
|
|||||||
node := api.Node{
|
node := api.Node{
|
||||||
ObjectMeta: api.ObjectMeta{Name: nodeID},
|
ObjectMeta: api.ObjectMeta{Name: nodeID},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{
|
||||||
Capacity: nc.staticResources.Capacity,
|
ExternalID: nodeID,
|
||||||
ExternalID: nodeID},
|
},
|
||||||
|
Status: api.NodeStatus{
|
||||||
|
Capacity: nc.staticResources.Capacity,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
result.Items = append(result.Items, node)
|
result.Items = append(result.Items, node)
|
||||||
}
|
}
|
||||||
@ -553,7 +556,7 @@ func (nc *NodeController) GetCloudNodesWithSpec() (*api.NodeList, error) {
|
|||||||
resources = nc.staticResources
|
resources = nc.staticResources
|
||||||
}
|
}
|
||||||
if resources != nil {
|
if resources != nil {
|
||||||
node.Spec.Capacity = resources.Capacity
|
node.Status.Capacity = resources.Capacity
|
||||||
}
|
}
|
||||||
instanceID, err := instances.ExternalID(node.Name)
|
instanceID, err := instances.ExternalID(node.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -281,12 +281,13 @@ func TestCreateGetStaticNodesWithSpec(t *testing.T) {
|
|||||||
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{
|
||||||
ExternalID: "node0",
|
ExternalID: "node0",
|
||||||
|
},
|
||||||
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Status: api.NodeStatus{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -299,23 +300,25 @@ func TestCreateGetStaticNodesWithSpec(t *testing.T) {
|
|||||||
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{
|
||||||
ExternalID: "node0",
|
ExternalID: "node0",
|
||||||
|
},
|
||||||
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Status: api.NodeStatus{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "node1"},
|
ObjectMeta: api.ObjectMeta{Name: "node1"},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{
|
||||||
ExternalID: "node1",
|
ExternalID: "node1",
|
||||||
|
},
|
||||||
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Status: api.NodeStatus{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -364,7 +367,7 @@ func TestCreateGetCloudNodesWithSpec(t *testing.T) {
|
|||||||
Items: []api.Node{
|
Items: []api.Node{
|
||||||
{
|
{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
||||||
Spec: api.NodeSpec{Capacity: resourceList},
|
Status: api.NodeStatus{Capacity: resourceList},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -378,11 +381,11 @@ func TestCreateGetCloudNodesWithSpec(t *testing.T) {
|
|||||||
Items: []api.Node{
|
Items: []api.Node{
|
||||||
{
|
{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
||||||
Spec: api.NodeSpec{Capacity: resourceList},
|
Status: api.NodeStatus{Capacity: resourceList},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "node1"},
|
ObjectMeta: api.ObjectMeta{Name: "node1"},
|
||||||
Spec: api.NodeSpec{Capacity: resourceList},
|
Status: api.NodeStatus{Capacity: resourceList},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -759,14 +762,14 @@ func TestSyncProbedNodeStatus(t *testing.T) {
|
|||||||
Addresses: []api.NodeAddress{
|
Addresses: []api.NodeAddress{
|
||||||
{Type: api.NodeLegacyHostIP, Address: "1.2.3.4"},
|
{Type: api.NodeLegacyHostIP, Address: "1.2.3.4"},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
Spec: api.NodeSpec{
|
|
||||||
ExternalID: "node0",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "node0",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "node1"},
|
ObjectMeta: api.ObjectMeta{Name: "node1"},
|
||||||
@ -790,14 +793,14 @@ func TestSyncProbedNodeStatus(t *testing.T) {
|
|||||||
Addresses: []api.NodeAddress{
|
Addresses: []api.NodeAddress{
|
||||||
{Type: api.NodeLegacyHostIP, Address: "1.2.3.4"},
|
{Type: api.NodeLegacyHostIP, Address: "1.2.3.4"},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
Spec: api.NodeSpec{
|
|
||||||
ExternalID: "node1",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "node1",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedRequestCount: 3, // List + 2xUpdate
|
expectedRequestCount: 3, // List + 2xUpdate
|
||||||
@ -1319,14 +1322,14 @@ func TestMonitorNodeStatusUpdateStatus(t *testing.T) {
|
|||||||
LastTransitionTime: util.Date(2015, 1, 1, 11, 0, 0, 0, time.UTC),
|
LastTransitionTime: util.Date(2015, 1, 1, 11, 0, 0, 0, time.UTC),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
Spec: api.NodeSpec{
|
|
||||||
ExternalID: "node0",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "node0",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Fake: client.Fake{
|
Fake: client.Fake{
|
||||||
@ -1350,14 +1353,14 @@ func TestMonitorNodeStatusUpdateStatus(t *testing.T) {
|
|||||||
LastTransitionTime: fakeNow,
|
LastTransitionTime: fakeNow,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
Spec: api.NodeSpec{
|
|
||||||
ExternalID: "node0",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "node0",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1381,14 +1384,14 @@ func TestMonitorNodeStatusUpdateStatus(t *testing.T) {
|
|||||||
LastTransitionTime: fakeNow,
|
LastTransitionTime: fakeNow,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
Spec: api.NodeSpec{
|
|
||||||
ExternalID: "node0",
|
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
ExternalID: "node0",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Fake: client.Fake{
|
Fake: client.Fake{
|
||||||
@ -1420,6 +1423,8 @@ func newNode(name string) *api.Node {
|
|||||||
ObjectMeta: api.ObjectMeta{Name: name},
|
ObjectMeta: api.ObjectMeta{Name: name},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{
|
||||||
ExternalID: name,
|
ExternalID: name,
|
||||||
|
},
|
||||||
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
||||||
|
@ -393,9 +393,9 @@ func describeNode(node *api.Node, pods []api.Pod, events *api.EventList) (string
|
|||||||
addresses = append(addresses, address.Address)
|
addresses = append(addresses, address.Address)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "Addresses:\t%s\n", strings.Join(addresses, ","))
|
fmt.Fprintf(out, "Addresses:\t%s\n", strings.Join(addresses, ","))
|
||||||
if len(node.Spec.Capacity) > 0 {
|
if len(node.Status.Capacity) > 0 {
|
||||||
fmt.Fprintf(out, "Capacity:\n")
|
fmt.Fprintf(out, "Capacity:\n")
|
||||||
for resource, value := range node.Spec.Capacity {
|
for resource, value := range node.Status.Capacity {
|
||||||
fmt.Fprintf(out, " %s:\t%s\n", resource, value.String())
|
fmt.Fprintf(out, " %s:\t%s\n", resource, value.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,8 @@ func TestPathBuilder(t *testing.T) {
|
|||||||
func TestNodeBuilder(t *testing.T) {
|
func TestNodeBuilder(t *testing.T) {
|
||||||
node := &api.Node{
|
node := &api.Node{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "node1", Namespace: "should-not-have", ResourceVersion: "10"},
|
ObjectMeta: api.ObjectMeta{Name: "node1", Namespace: "should-not-have", ResourceVersion: "10"},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{},
|
||||||
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceCPU: resource.MustParse("1000m"),
|
api.ResourceCPU: resource.MustParse("1000m"),
|
||||||
api.ResourceMemory: resource.MustParse("1Mi"),
|
api.ResourceMemory: resource.MustParse("1Mi"),
|
||||||
|
@ -1935,7 +1935,7 @@ func (kl *Kubelet) tryUpdateNodeStatus() error {
|
|||||||
node.Status.NodeInfo.MachineID = info.MachineID
|
node.Status.NodeInfo.MachineID = info.MachineID
|
||||||
node.Status.NodeInfo.SystemUUID = info.SystemUUID
|
node.Status.NodeInfo.SystemUUID = info.SystemUUID
|
||||||
node.Status.NodeInfo.BootID = info.BootID
|
node.Status.NodeInfo.BootID = info.BootID
|
||||||
node.Spec.Capacity = CapacityFromMachineInfo(info)
|
node.Status.Capacity = CapacityFromMachineInfo(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTime := util.Now()
|
currentTime := util.Now()
|
||||||
|
@ -3138,12 +3138,7 @@ func TestUpdateNewNodeStatus(t *testing.T) {
|
|||||||
mockCadvisor.On("MachineInfo").Return(machineInfo, nil)
|
mockCadvisor.On("MachineInfo").Return(machineInfo, nil)
|
||||||
expectedNode := &api.Node{
|
expectedNode := &api.Node{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "testnode"},
|
ObjectMeta: api.ObjectMeta{Name: "testnode"},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{},
|
||||||
Capacity: api.ResourceList{
|
|
||||||
api.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI),
|
|
||||||
api.ResourceMemory: *resource.NewQuantity(1024, resource.BinarySI),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Status: api.NodeStatus{
|
Status: api.NodeStatus{
|
||||||
Conditions: []api.NodeCondition{
|
Conditions: []api.NodeCondition{
|
||||||
{
|
{
|
||||||
@ -3159,6 +3154,10 @@ func TestUpdateNewNodeStatus(t *testing.T) {
|
|||||||
SystemUUID: "abc",
|
SystemUUID: "abc",
|
||||||
BootID: "1b3",
|
BootID: "1b3",
|
||||||
},
|
},
|
||||||
|
Capacity: api.ResourceList{
|
||||||
|
api.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI),
|
||||||
|
api.ResourceMemory: *resource.NewQuantity(1024, resource.BinarySI),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3193,12 +3192,7 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
|
|||||||
kubeClient.MinionsList = api.NodeList{Items: []api.Node{
|
kubeClient.MinionsList = api.NodeList{Items: []api.Node{
|
||||||
{
|
{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "testnode"},
|
ObjectMeta: api.ObjectMeta{Name: "testnode"},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{},
|
||||||
Capacity: api.ResourceList{
|
|
||||||
api.ResourceCPU: *resource.NewMilliQuantity(3000, resource.DecimalSI),
|
|
||||||
api.ResourceMemory: *resource.NewQuantity(2048, resource.BinarySI),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Status: api.NodeStatus{
|
Status: api.NodeStatus{
|
||||||
Conditions: []api.NodeCondition{
|
Conditions: []api.NodeCondition{
|
||||||
{
|
{
|
||||||
@ -3209,6 +3203,10 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
|
|||||||
LastTransitionTime: util.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
|
LastTransitionTime: util.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Capacity: api.ResourceList{
|
||||||
|
api.ResourceCPU: *resource.NewMilliQuantity(3000, resource.DecimalSI),
|
||||||
|
api.ResourceMemory: *resource.NewQuantity(2048, resource.BinarySI),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
@ -3222,12 +3220,7 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
|
|||||||
mockCadvisor.On("MachineInfo").Return(machineInfo, nil)
|
mockCadvisor.On("MachineInfo").Return(machineInfo, nil)
|
||||||
expectedNode := &api.Node{
|
expectedNode := &api.Node{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "testnode"},
|
ObjectMeta: api.ObjectMeta{Name: "testnode"},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{},
|
||||||
Capacity: api.ResourceList{
|
|
||||||
api.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI),
|
|
||||||
api.ResourceMemory: *resource.NewQuantity(1024, resource.BinarySI),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Status: api.NodeStatus{
|
Status: api.NodeStatus{
|
||||||
Conditions: []api.NodeCondition{
|
Conditions: []api.NodeCondition{
|
||||||
{
|
{
|
||||||
@ -3243,6 +3236,10 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
|
|||||||
SystemUUID: "abc",
|
SystemUUID: "abc",
|
||||||
BootID: "1b3",
|
BootID: "1b3",
|
||||||
},
|
},
|
||||||
|
Capacity: api.ResourceList{
|
||||||
|
api.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI),
|
||||||
|
api.ResourceMemory: *resource.NewQuantity(1024, resource.BinarySI),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +64,8 @@ func validNewNode() *api.Node {
|
|||||||
},
|
},
|
||||||
Spec: api.NodeSpec{
|
Spec: api.NodeSpec{
|
||||||
ExternalID: "external",
|
ExternalID: "external",
|
||||||
|
},
|
||||||
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
||||||
api.ResourceName(api.ResourceMemory): resource.MustParse("0"),
|
api.ResourceName(api.ResourceMemory): resource.MustParse("0"),
|
||||||
|
@ -42,7 +42,7 @@ func MakeMinionList(minions []string, nodeResources api.NodeResources) *api.Node
|
|||||||
}
|
}
|
||||||
for i := range minions {
|
for i := range minions {
|
||||||
list.Items[i].Name = minions[i]
|
list.Items[i].Name = minions[i]
|
||||||
list.Items[i].Spec.Capacity = nodeResources.Capacity
|
list.Items[i].Status.Capacity = nodeResources.Capacity
|
||||||
}
|
}
|
||||||
return &list
|
return &list
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ func (r *ResourceFit) PodFitsResources(pod api.Pod, existingPods []api.Pod, node
|
|||||||
pods := []api.Pod{}
|
pods := []api.Pod{}
|
||||||
copy(pods, existingPods)
|
copy(pods, existingPods)
|
||||||
pods = append(existingPods, pod)
|
pods = append(existingPods, pod)
|
||||||
_, exceeding := CheckPodsExceedingCapacity(pods, info.Spec.Capacity)
|
_, exceeding := CheckPodsExceedingCapacity(pods, info.Status.Capacity)
|
||||||
if len(exceeding) > 0 {
|
if len(exceeding) > 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func TestPodFitsResources(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
node := api.Node{Spec: api.NodeSpec{Capacity: makeResources(10, 20).Capacity}}
|
node := api.Node{Status: api.NodeStatus{Capacity: makeResources(10, 20).Capacity}}
|
||||||
|
|
||||||
fit := ResourceFit{FakeNodeInfo(node)}
|
fit := ResourceFit{FakeNodeInfo(node)}
|
||||||
fits, err := fit.PodFitsResources(test.pod, test.existingPods, "machine")
|
fits, err := fit.PodFitsResources(test.pod, test.existingPods, "machine")
|
||||||
|
@ -53,8 +53,8 @@ func calculateOccupancy(pod api.Pod, node api.Node, pods []api.Pod) HostPriority
|
|||||||
totalMemory += container.Resources.Limits.Memory().Value()
|
totalMemory += container.Resources.Limits.Memory().Value()
|
||||||
}
|
}
|
||||||
|
|
||||||
capacityMilliCPU := node.Spec.Capacity.Cpu().MilliValue()
|
capacityMilliCPU := node.Status.Capacity.Cpu().MilliValue()
|
||||||
capacityMemory := node.Spec.Capacity.Memory().Value()
|
capacityMemory := node.Status.Capacity.Memory().Value()
|
||||||
|
|
||||||
cpuScore := calculateScore(totalMilliCPU, capacityMilliCPU, node.Name)
|
cpuScore := calculateScore(totalMilliCPU, capacityMilliCPU, node.Name)
|
||||||
memoryScore := calculateScore(totalMemory, capacityMemory, node.Name)
|
memoryScore := calculateScore(totalMemory, capacityMemory, node.Name)
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
func makeMinion(node string, milliCPU, memory int64) api.Node {
|
func makeMinion(node string, milliCPU, memory int64) api.Node {
|
||||||
return api.Node{
|
return api.Node{
|
||||||
ObjectMeta: api.ObjectMeta{Name: node},
|
ObjectMeta: api.ObjectMeta{Name: node},
|
||||||
Spec: api.NodeSpec{
|
Status: api.NodeStatus{
|
||||||
Capacity: api.ResourceList{
|
Capacity: api.ResourceList{
|
||||||
"cpu": *resource.NewMilliQuantity(milliCPU, resource.DecimalSI),
|
"cpu": *resource.NewMilliQuantity(milliCPU, resource.DecimalSI),
|
||||||
"memory": *resource.NewQuantity(memory, resource.BinarySI),
|
"memory": *resource.NewQuantity(memory, resource.BinarySI),
|
||||||
|
Loading…
Reference in New Issue
Block a user