diff --git a/pkg/api/types.go b/pkg/api/types.go index 81a65d13685..109bb6fc390 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -951,9 +951,6 @@ type EndpointsList struct { // NodeSpec describes the attributes that a node is created with. 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 // Note: assigning IP ranges to nodes might need to be revisited when we support migratable IPs. PodCIDR string `json:"podCIDR,omitempty"` @@ -977,6 +974,8 @@ type NodeSystemInfo struct { // NodeStatus is information about the current status of a node. 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. Phase NodePhase `json:"phase,omitempty"` // Conditions is an array of current node conditions. diff --git a/pkg/api/v1beta1/conversion.go b/pkg/api/v1beta1/conversion.go index 9b11125bd06..da18a18c146 100644 --- a/pkg/api/v1beta1/conversion.go +++ b/pkg/api/v1beta1/conversion.go @@ -704,7 +704,7 @@ func init() { out.PodCIDR = in.Spec.PodCIDR out.ExternalID = in.Spec.ExternalID 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 { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { @@ -736,7 +736,7 @@ func init() { out.Spec.PodCIDR = in.PodCIDR out.Spec.ExternalID = in.ExternalID 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 { diff --git a/pkg/api/v1beta2/conversion.go b/pkg/api/v1beta2/conversion.go index ea23bfbbe81..89b5cd80571 100644 --- a/pkg/api/v1beta2/conversion.go +++ b/pkg/api/v1beta2/conversion.go @@ -636,7 +636,7 @@ func init() { out.PodCIDR = in.Spec.PodCIDR out.ExternalID = in.Spec.ExternalID 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 { if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil { @@ -668,7 +668,7 @@ func init() { out.Spec.PodCIDR = in.PodCIDR out.Spec.ExternalID = in.ExternalID 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 { diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index a448020623b..1a15a3686b2 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -952,9 +952,6 @@ type EndpointsList struct { // NodeSpec describes the attributes that a node is created with. 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 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) @@ -975,6 +972,9 @@ type NodeSystemInfo struct { // NodeStatus is information about the current status of a node. 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. Phase NodePhase `json:"phase,omitempty" description:"most recently observed lifecycle phase of the node"` // Conditions is an array of current node conditions. diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index a5eb689fc8e..9700b460d8c 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -910,18 +910,18 @@ func ValidateMinion(node *api.Node) errs.ValidationErrorList { allErrs := errs.ValidationErrorList{} allErrs = append(allErrs, ValidateObjectMeta(&node.ObjectMeta, false, ValidateNodeName).Prefix("metadata")...) // Capacity is required. Within capacity, memory and cpu resources are required. - if len(node.Spec.Capacity) == 0 { - allErrs = append(allErrs, errs.NewFieldRequired("spec.Capacity")) + if len(node.Status.Capacity) == 0 { + allErrs = append(allErrs, errs.NewFieldRequired("status.Capacity")) } else { - if val, ok := node.Spec.Capacity[api.ResourceMemory]; !ok { - allErrs = append(allErrs, errs.NewFieldRequired("spec.Capacity[memory]")) + if val, ok := node.Status.Capacity[api.ResourceMemory]; !ok { + allErrs = append(allErrs, errs.NewFieldRequired("status.Capacity[memory]")) } 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 { - allErrs = append(allErrs, errs.NewFieldRequired("spec.Capacity[cpu]")) + if val, ok := node.Status.Capacity[api.ResourceCPU]; !ok { + allErrs = append(allErrs, errs.NewFieldRequired("status.Capacity[cpu]")) } 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 oldMinion.ObjectMeta = minion.ObjectMeta // Allow users to update capacity - oldMinion.Spec.Capacity = minion.Spec.Capacity + oldMinion.Status.Capacity = minion.Status.Capacity // Allow users to unschedule node oldMinion.Spec.Unschedulable = minion.Spec.Unschedulable // Clear status diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index b5d0e112564..798a3179d36 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -1822,15 +1822,15 @@ func TestValidateMinion(t *testing.T) { Addresses: []api.NodeAddress{ {Type: api.NodeLegacyHostIP, Address: "something"}, }, - }, - Spec: api.NodeSpec{ - ExternalID: "external", Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), api.ResourceName("my.org/gpu"): resource.MustParse("10"), }, }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, }, { ObjectMeta: api.ObjectMeta{ @@ -1840,14 +1840,14 @@ func TestValidateMinion(t *testing.T) { Addresses: []api.NodeAddress{ {Type: api.NodeLegacyHostIP, Address: "something"}, }, - }, - Spec: api.NodeSpec{ - ExternalID: "external", Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("0"), }, }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, }, } for _, successCase := range successCases { @@ -1864,34 +1864,36 @@ func TestValidateMinion(t *testing.T) { }, Status: api.NodeStatus{ Addresses: []api.NodeAddress{}, - }, - Spec: api.NodeSpec{ - ExternalID: "external", Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, }, "invalid-labels": { ObjectMeta: api.ObjectMeta{ Name: "abc-123", Labels: invalidSelector, }, - Spec: api.NodeSpec{ - ExternalID: "external", + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, }, "missing-external-id": { ObjectMeta: api.ObjectMeta{ Name: "abc-123", Labels: validSelector, }, - Spec: api.NodeSpec{ + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), @@ -1912,50 +1914,58 @@ func TestValidateMinion(t *testing.T) { Name: "abc-123", Labels: validSelector, }, - Spec: api.NodeSpec{ - ExternalID: "external", + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), }, }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, }, "missing-cpu": { ObjectMeta: api.ObjectMeta{ Name: "abc-123", Labels: validSelector, }, - Spec: api.NodeSpec{ - ExternalID: "external", + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, }, "invalid-memory": { ObjectMeta: api.ObjectMeta{ Name: "abc-123", Labels: validSelector, }, - Spec: api.NodeSpec{ - ExternalID: "external", + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("-10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, }, "invalid-cpu": { ObjectMeta: api.ObjectMeta{ Name: "abc-123", Labels: validSelector, }, - Spec: api.NodeSpec{ - ExternalID: "external", + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("-10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, }, } for k, v := range errorCases { @@ -1966,14 +1976,14 @@ func TestValidateMinion(t *testing.T) { for i := range errs { field := errs[i].(*errors.ValidationError).Field expectedFields := map[string]bool{ - "metadata.name": true, - "metadata.labels": true, - "metadata.annotations": true, - "metadata.namespace": true, - "spec.Capacity": true, - "spec.Capacity[memory]": true, - "spec.Capacity[cpu]": true, - "spec.ExternalID": true, + "metadata.name": true, + "metadata.labels": true, + "metadata.annotations": true, + "metadata.namespace": true, + "status.Capacity": true, + "status.Capacity[memory]": true, + "status.Capacity[cpu]": true, + "spec.ExternalID": true, } if expectedFields[field] == false { t.Errorf("%s: missing prefix for: %v", k, errs[i]) @@ -2032,7 +2042,7 @@ func TestValidateMinionUpdate(t *testing.T) { ObjectMeta: api.ObjectMeta{ Name: "foo", }, - Spec: api.NodeSpec{ + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceCPU: resource.MustParse("10000"), api.ResourceMemory: resource.MustParse("100"), @@ -2042,7 +2052,7 @@ func TestValidateMinionUpdate(t *testing.T) { ObjectMeta: api.ObjectMeta{ Name: "foo", }, - Spec: api.NodeSpec{ + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceCPU: resource.MustParse("100"), api.ResourceMemory: resource.MustParse("10000"), @@ -2054,7 +2064,7 @@ func TestValidateMinionUpdate(t *testing.T) { Name: "foo", Labels: map[string]string{"bar": "foo"}, }, - Spec: api.NodeSpec{ + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceCPU: resource.MustParse("10000"), api.ResourceMemory: resource.MustParse("100"), @@ -2065,7 +2075,7 @@ func TestValidateMinionUpdate(t *testing.T) { Name: "foo", Labels: map[string]string{"bar": "fooobaz"}, }, - Spec: api.NodeSpec{ + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceCPU: resource.MustParse("100"), api.ResourceMemory: resource.MustParse("10000"), diff --git a/pkg/client/minions.go b/pkg/client/nodes.go similarity index 84% rename from pkg/client/minions.go rename to pkg/client/nodes.go index 6d42fa3150f..1d996d8a6cd 100644 --- a/pkg/client/minions.go +++ b/pkg/client/nodes.go @@ -31,7 +31,7 @@ type NodesInterface interface { type NodeInterface interface { 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) Delete(name string) error Update(*api.Node) (*api.Node, error) @@ -43,13 +43,13 @@ type nodes struct { r *Client } -// newNodes returns a nodes object. Uses "minions" as the -// URL resource name for v1beta1 and v1beta2. +// newNodes returns a nodes object. func newNodes(c *Client) *nodes { return &nodes{c} } // 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 { if api.PreV1Beta3(c.r.APIVersion()) { return "minions" @@ -58,9 +58,9 @@ func (c *nodes) resourceName() string { } // 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{} - 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 } @@ -84,13 +84,13 @@ func (c *nodes) Delete(name string) error { } // 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{} - if len(minion.ResourceVersion) == 0 { - err := fmt.Errorf("invalid update object, missing resource version: %v", minion) + if len(node.ResourceVersion) == 0 { + err := fmt.Errorf("invalid update object, missing resource version: %v", node) 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 } diff --git a/pkg/client/minions_test.go b/pkg/client/nodes_test.go similarity index 98% rename from pkg/client/minions_test.go rename to pkg/client/nodes_test.go index 56cf1d74423..994879b7b95 100644 --- a/pkg/client/minions_test.go +++ b/pkg/client/nodes_test.go @@ -69,11 +69,13 @@ func TestCreateMinion(t *testing.T) { ObjectMeta: api.ObjectMeta{ Name: "minion-1", }, - Spec: api.NodeSpec{ + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceCPU: resource.MustParse("1000m"), api.ResourceMemory: resource.MustParse("1Mi"), }, + }, + Spec: api.NodeSpec{ Unschedulable: false, }, } @@ -109,11 +111,13 @@ func TestUpdateMinion(t *testing.T) { Name: "foo", ResourceVersion: "1", }, - Spec: api.NodeSpec{ + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceCPU: resource.MustParse("1000m"), api.ResourceMemory: resource.MustParse("1Mi"), }, + }, + Spec: api.NodeSpec{ Unschedulable: true, }, } diff --git a/pkg/cloudprovider/controller/nodecontroller.go b/pkg/cloudprovider/controller/nodecontroller.go index e469b505a30..fcad935211d 100644 --- a/pkg/cloudprovider/controller/nodecontroller.go +++ b/pkg/cloudprovider/controller/nodecontroller.go @@ -292,7 +292,7 @@ func (nc *NodeController) populateNodeInfo(node *api.Node) error { return err } for key, value := range nodeInfo.Capacity { - node.Spec.Capacity[key] = value + node.Status.Capacity[key] = value } if node.Status.NodeInfo.BootID != "" && node.Status.NodeInfo.BootID != nodeInfo.NodeSystemInfo.BootID { @@ -521,8 +521,11 @@ func (nc *NodeController) GetStaticNodesWithSpec() (*api.NodeList, error) { node := api.Node{ ObjectMeta: api.ObjectMeta{Name: nodeID}, Spec: api.NodeSpec{ - Capacity: nc.staticResources.Capacity, - ExternalID: nodeID}, + ExternalID: nodeID, + }, + Status: api.NodeStatus{ + Capacity: nc.staticResources.Capacity, + }, } result.Items = append(result.Items, node) } @@ -553,7 +556,7 @@ func (nc *NodeController) GetCloudNodesWithSpec() (*api.NodeList, error) { resources = nc.staticResources } if resources != nil { - node.Spec.Capacity = resources.Capacity + node.Status.Capacity = resources.Capacity } instanceID, err := instances.ExternalID(node.Name) if err != nil { diff --git a/pkg/cloudprovider/controller/nodecontroller_test.go b/pkg/cloudprovider/controller/nodecontroller_test.go index 8cac27f68cf..7324a04b4a8 100644 --- a/pkg/cloudprovider/controller/nodecontroller_test.go +++ b/pkg/cloudprovider/controller/nodecontroller_test.go @@ -281,12 +281,13 @@ func TestCreateGetStaticNodesWithSpec(t *testing.T) { ObjectMeta: api.ObjectMeta{Name: "node0"}, Spec: api.NodeSpec{ ExternalID: "node0", + }, + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, - Status: api.NodeStatus{}, }, }, }, @@ -299,23 +300,25 @@ func TestCreateGetStaticNodesWithSpec(t *testing.T) { ObjectMeta: api.ObjectMeta{Name: "node0"}, Spec: api.NodeSpec{ ExternalID: "node0", + }, + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, - Status: api.NodeStatus{}, }, { ObjectMeta: api.ObjectMeta{Name: "node1"}, Spec: api.NodeSpec{ ExternalID: "node1", + }, + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, - Status: api.NodeStatus{}, }, }, }, @@ -364,7 +367,7 @@ func TestCreateGetCloudNodesWithSpec(t *testing.T) { Items: []api.Node{ { 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{ { ObjectMeta: api.ObjectMeta{Name: "node0"}, - Spec: api.NodeSpec{Capacity: resourceList}, + Status: api.NodeStatus{Capacity: resourceList}, }, { 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{ {Type: api.NodeLegacyHostIP, Address: "1.2.3.4"}, }, - }, - Spec: api.NodeSpec{ - ExternalID: "node0", Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "node0", + }, }, { ObjectMeta: api.ObjectMeta{Name: "node1"}, @@ -790,14 +793,14 @@ func TestSyncProbedNodeStatus(t *testing.T) { Addresses: []api.NodeAddress{ {Type: api.NodeLegacyHostIP, Address: "1.2.3.4"}, }, - }, - Spec: api.NodeSpec{ - ExternalID: "node1", Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "node1", + }, }, }, 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), }, }, - }, - Spec: api.NodeSpec{ - ExternalID: "node0", Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "node0", + }, }, }, Fake: client.Fake{ @@ -1350,14 +1353,14 @@ func TestMonitorNodeStatusUpdateStatus(t *testing.T) { LastTransitionTime: fakeNow, }, }, - }, - Spec: api.NodeSpec{ - ExternalID: "node0", Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "node0", + }, }, }, }, @@ -1381,14 +1384,14 @@ func TestMonitorNodeStatusUpdateStatus(t *testing.T) { LastTransitionTime: fakeNow, }, }, - }, - Spec: api.NodeSpec{ - ExternalID: "node0", Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), }, }, + Spec: api.NodeSpec{ + ExternalID: "node0", + }, }, }, Fake: client.Fake{ @@ -1420,6 +1423,8 @@ func newNode(name string) *api.Node { ObjectMeta: api.ObjectMeta{Name: name}, Spec: api.NodeSpec{ ExternalID: name, + }, + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("10G"), diff --git a/pkg/kubectl/describe.go b/pkg/kubectl/describe.go index b102b42fa22..d0a335987dc 100644 --- a/pkg/kubectl/describe.go +++ b/pkg/kubectl/describe.go @@ -393,9 +393,9 @@ func describeNode(node *api.Node, pods []api.Pod, events *api.EventList) (string addresses = append(addresses, address.Address) } 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") - for resource, value := range node.Spec.Capacity { + for resource, value := range node.Status.Capacity { fmt.Fprintf(out, " %s:\t%s\n", resource, value.String()) } } diff --git a/pkg/kubectl/resource/builder_test.go b/pkg/kubectl/resource/builder_test.go index 4fb57d61b6b..e3f59479144 100644 --- a/pkg/kubectl/resource/builder_test.go +++ b/pkg/kubectl/resource/builder_test.go @@ -185,7 +185,8 @@ func TestPathBuilder(t *testing.T) { func TestNodeBuilder(t *testing.T) { node := &api.Node{ ObjectMeta: api.ObjectMeta{Name: "node1", Namespace: "should-not-have", ResourceVersion: "10"}, - Spec: api.NodeSpec{ + Spec: api.NodeSpec{}, + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceCPU: resource.MustParse("1000m"), api.ResourceMemory: resource.MustParse("1Mi"), diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index ee2b1230abd..8ee5d2e642a 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -1935,7 +1935,7 @@ func (kl *Kubelet) tryUpdateNodeStatus() error { node.Status.NodeInfo.MachineID = info.MachineID node.Status.NodeInfo.SystemUUID = info.SystemUUID node.Status.NodeInfo.BootID = info.BootID - node.Spec.Capacity = CapacityFromMachineInfo(info) + node.Status.Capacity = CapacityFromMachineInfo(info) } currentTime := util.Now() diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index 5eec297391c..0b52260c7db 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -3138,12 +3138,7 @@ func TestUpdateNewNodeStatus(t *testing.T) { mockCadvisor.On("MachineInfo").Return(machineInfo, nil) expectedNode := &api.Node{ ObjectMeta: api.ObjectMeta{Name: "testnode"}, - Spec: api.NodeSpec{ - Capacity: api.ResourceList{ - api.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI), - api.ResourceMemory: *resource.NewQuantity(1024, resource.BinarySI), - }, - }, + Spec: api.NodeSpec{}, Status: api.NodeStatus{ Conditions: []api.NodeCondition{ { @@ -3159,6 +3154,10 @@ func TestUpdateNewNodeStatus(t *testing.T) { SystemUUID: "abc", 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{ { ObjectMeta: api.ObjectMeta{Name: "testnode"}, - Spec: api.NodeSpec{ - Capacity: api.ResourceList{ - api.ResourceCPU: *resource.NewMilliQuantity(3000, resource.DecimalSI), - api.ResourceMemory: *resource.NewQuantity(2048, resource.BinarySI), - }, - }, + Spec: api.NodeSpec{}, Status: api.NodeStatus{ Conditions: []api.NodeCondition{ { @@ -3209,6 +3203,10 @@ func TestUpdateExistingNodeStatus(t *testing.T) { 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) expectedNode := &api.Node{ ObjectMeta: api.ObjectMeta{Name: "testnode"}, - Spec: api.NodeSpec{ - Capacity: api.ResourceList{ - api.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI), - api.ResourceMemory: *resource.NewQuantity(1024, resource.BinarySI), - }, - }, + Spec: api.NodeSpec{}, Status: api.NodeStatus{ Conditions: []api.NodeCondition{ { @@ -3243,6 +3236,10 @@ func TestUpdateExistingNodeStatus(t *testing.T) { SystemUUID: "abc", BootID: "1b3", }, + Capacity: api.ResourceList{ + api.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI), + api.ResourceMemory: *resource.NewQuantity(1024, resource.BinarySI), + }, }, } diff --git a/pkg/registry/minion/etcd/etcd_test.go b/pkg/registry/minion/etcd/etcd_test.go index 9ea955acd99..e64a17b81aa 100644 --- a/pkg/registry/minion/etcd/etcd_test.go +++ b/pkg/registry/minion/etcd/etcd_test.go @@ -64,6 +64,8 @@ func validNewNode() *api.Node { }, Spec: api.NodeSpec{ ExternalID: "external", + }, + Status: api.NodeStatus{ Capacity: api.ResourceList{ api.ResourceName(api.ResourceCPU): resource.MustParse("10"), api.ResourceName(api.ResourceMemory): resource.MustParse("0"), diff --git a/pkg/registry/registrytest/minion.go b/pkg/registry/registrytest/minion.go index 5eef464d4a0..5094e991ba0 100644 --- a/pkg/registry/registrytest/minion.go +++ b/pkg/registry/registrytest/minion.go @@ -42,7 +42,7 @@ func MakeMinionList(minions []string, nodeResources api.NodeResources) *api.Node } for i := range minions { list.Items[i].Name = minions[i] - list.Items[i].Spec.Capacity = nodeResources.Capacity + list.Items[i].Status.Capacity = nodeResources.Capacity } return &list } diff --git a/pkg/scheduler/predicates.go b/pkg/scheduler/predicates.go index b902714c573..c43b2b27696 100644 --- a/pkg/scheduler/predicates.go +++ b/pkg/scheduler/predicates.go @@ -137,7 +137,7 @@ func (r *ResourceFit) PodFitsResources(pod api.Pod, existingPods []api.Pod, node pods := []api.Pod{} copy(pods, existingPods) pods = append(existingPods, pod) - _, exceeding := CheckPodsExceedingCapacity(pods, info.Spec.Capacity) + _, exceeding := CheckPodsExceedingCapacity(pods, info.Status.Capacity) if len(exceeding) > 0 { return false, nil } diff --git a/pkg/scheduler/predicates_test.go b/pkg/scheduler/predicates_test.go index 1768f3f57b2..566259bd8d8 100644 --- a/pkg/scheduler/predicates_test.go +++ b/pkg/scheduler/predicates_test.go @@ -120,7 +120,7 @@ func TestPodFitsResources(t *testing.T) { }, } 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)} fits, err := fit.PodFitsResources(test.pod, test.existingPods, "machine") diff --git a/pkg/scheduler/priorities.go b/pkg/scheduler/priorities.go index ee3d8729ea5..aa9c0bdb368 100644 --- a/pkg/scheduler/priorities.go +++ b/pkg/scheduler/priorities.go @@ -53,8 +53,8 @@ func calculateOccupancy(pod api.Pod, node api.Node, pods []api.Pod) HostPriority totalMemory += container.Resources.Limits.Memory().Value() } - capacityMilliCPU := node.Spec.Capacity.Cpu().MilliValue() - capacityMemory := node.Spec.Capacity.Memory().Value() + capacityMilliCPU := node.Status.Capacity.Cpu().MilliValue() + capacityMemory := node.Status.Capacity.Memory().Value() cpuScore := calculateScore(totalMilliCPU, capacityMilliCPU, node.Name) memoryScore := calculateScore(totalMemory, capacityMemory, node.Name) diff --git a/pkg/scheduler/priorities_test.go b/pkg/scheduler/priorities_test.go index 61537919670..9c19a7f97dd 100644 --- a/pkg/scheduler/priorities_test.go +++ b/pkg/scheduler/priorities_test.go @@ -28,7 +28,7 @@ import ( func makeMinion(node string, milliCPU, memory int64) api.Node { return api.Node{ ObjectMeta: api.ObjectMeta{Name: node}, - Spec: api.NodeSpec{ + Status: api.NodeStatus{ Capacity: api.ResourceList{ "cpu": *resource.NewMilliQuantity(milliCPU, resource.DecimalSI), "memory": *resource.NewQuantity(memory, resource.BinarySI),