Add Allocatable to NodeStatus

Adds `Allocatable` to `NodeStatus`, as described in
[17201](https://github.com/kubernetes/kubernetes/pull/17201)
This commit is contained in:
Tim St. Clair 2015-12-14 18:01:30 -08:00
parent 7069a81116
commit 8fdd321dc1
13 changed files with 15653 additions and 15405 deletions

View File

@ -13294,7 +13294,11 @@
"properties": {
"capacity": {
"type": "any",
"description": "Capacity represents the available resources of a node. More info: http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity for more details."
"description": "Capacity represents the total resources of a node. More info: http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity for more details."
},
"allocatable": {
"type": "any",
"description": "Allocatable represents the resources of a node that are available for scheduling. Defaults to Capacity."
},
"phase": {
"type": "string",

View File

@ -3790,7 +3790,14 @@ The resulting set of endpoints can be viewed as:<br>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">capacity</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Capacity represents the available resources of a node. More info: <a href="http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity">http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity</a> for more details.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Capacity represents the total resources of a node. More info: <a href="http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity">http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity</a> for more details.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_any">any</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">allocatable</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Allocatable represents the resources of a node that are available for scheduling. Defaults to Capacity.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_any">any</a></p></td>
<td class="tableblock halign-left valign-top"></td>
@ -6911,7 +6918,7 @@ The resulting set of endpoints can be viewed as:<br>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2015-12-14 19:06:15 UTC
Last updated 2015-12-16 19:00:42 UTC
</div>
</div>
</body>

View File

@ -1007,6 +1007,18 @@ func deepCopy_api_NodeStatus(in NodeStatus, out *NodeStatus, c *conversion.Clone
} else {
out.Capacity = nil
}
if in.Allocatable != nil {
out.Allocatable = make(ResourceList)
for key, val := range in.Allocatable {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
return err
}
out.Allocatable[key] = *newVal
}
} else {
out.Allocatable = nil
}
out.Phase = in.Phase
if in.Conditions != nil {
out.Conditions = make([]NodeCondition, len(in.Conditions))

View File

@ -388,6 +388,10 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
c.FuzzNoCustom(n)
n.Spec.ExternalID = "external"
},
func(s *api.NodeStatus, c fuzz.Continue) {
c.FuzzNoCustom(s)
s.Allocatable = s.Capacity
},
func(s *extensions.APIVersion, c fuzz.Continue) {
// We can't use c.RandString() here because it may generate empty
// string, which will cause tests failure.

File diff suppressed because it is too large Load Diff

View File

@ -1489,8 +1489,10 @@ 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 represents the total resources of a node.
Capacity ResourceList `json:"capacity,omitempty"`
// Allocatable represents the resources of a node that are available for scheduling.
Allocatable ResourceList `json:"allocatable,omitempty"`
// NodePhase is the current lifecycle phase of the node.
Phase NodePhase `json:"phase,omitempty"`
// Conditions is an array of current node conditions.

View File

@ -1413,6 +1413,18 @@ func autoconvert_api_NodeStatus_To_v1_NodeStatus(in *api.NodeStatus, out *NodeSt
} else {
out.Capacity = nil
}
if in.Allocatable != nil {
out.Allocatable = make(ResourceList)
for key, val := range in.Allocatable {
newVal := resource.Quantity{}
if err := s.Convert(&val, &newVal, 0); err != nil {
return err
}
out.Allocatable[ResourceName(key)] = newVal
}
} else {
out.Allocatable = nil
}
out.Phase = NodePhase(in.Phase)
if in.Conditions != nil {
out.Conditions = make([]NodeCondition, len(in.Conditions))
@ -4440,6 +4452,18 @@ func autoconvert_v1_NodeStatus_To_api_NodeStatus(in *NodeStatus, out *api.NodeSt
} else {
out.Capacity = nil
}
if in.Allocatable != nil {
out.Allocatable = make(api.ResourceList)
for key, val := range in.Allocatable {
newVal := resource.Quantity{}
if err := s.Convert(&val, &newVal, 0); err != nil {
return err
}
out.Allocatable[api.ResourceName(key)] = newVal
}
} else {
out.Allocatable = nil
}
out.Phase = api.NodePhase(in.Phase)
if in.Conditions != nil {
out.Conditions = make([]api.NodeCondition, len(in.Conditions))

View File

@ -1025,6 +1025,18 @@ func deepCopy_v1_NodeStatus(in NodeStatus, out *NodeStatus, c *conversion.Cloner
} else {
out.Capacity = nil
}
if in.Allocatable != nil {
out.Allocatable = make(ResourceList)
for key, val := range in.Allocatable {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
return err
}
out.Allocatable[key] = *newVal
}
} else {
out.Allocatable = nil
}
out.Phase = in.Phase
if in.Conditions != nil {
out.Conditions = make([]NodeCondition, len(in.Conditions))

View File

@ -198,6 +198,15 @@ func addDefaultingFuncs() {
obj.Spec.ExternalID = obj.Name
}
},
func(obj *NodeStatus) {
if obj.Allocatable == nil && obj.Capacity != nil {
obj.Allocatable = make(ResourceList, len(obj.Capacity))
for key, value := range obj.Capacity {
obj.Allocatable[key] = *(value.Copy())
}
obj.Allocatable = obj.Capacity
}
},
func(obj *ObjectFieldSelector) {
if obj.APIVersion == "" {
obj.APIVersion = "v1"

View File

@ -406,6 +406,80 @@ func TestSetDefaultNodeExternalID(t *testing.T) {
}
}
func TestSetDefaultNodeStatusAllocatable(t *testing.T) {
capacity := versioned.ResourceList{
versioned.ResourceCPU: resource.MustParse("1000m"),
versioned.ResourceMemory: resource.MustParse("10G"),
}
allocatable := versioned.ResourceList{
versioned.ResourceCPU: resource.MustParse("500m"),
versioned.ResourceMemory: resource.MustParse("5G"),
}
tests := []struct {
capacity versioned.ResourceList
allocatable versioned.ResourceList
expectedAllocatable versioned.ResourceList
}{{ // Everything set, no defaulting.
capacity: capacity,
allocatable: allocatable,
expectedAllocatable: allocatable,
}, { // Allocatable set, no defaulting.
capacity: nil,
allocatable: allocatable,
expectedAllocatable: allocatable,
}, { // Capacity set, allocatable defaults to capacity.
capacity: capacity,
allocatable: nil,
expectedAllocatable: capacity,
}, { // Nothing set, allocatable "defaults" to capacity.
capacity: nil,
allocatable: nil,
expectedAllocatable: nil,
}}
copyResourceList := func(rl versioned.ResourceList) versioned.ResourceList {
if rl == nil {
return nil
}
copy := make(versioned.ResourceList, len(rl))
for k, v := range rl {
copy[k] = *v.Copy()
}
return copy
}
resourceListsEqual := func(a versioned.ResourceList, b versioned.ResourceList) bool {
if len(a) != len(b) {
return false
}
for k, v := range a {
vb, found := b[k]
if !found {
return false
}
if v.Cmp(vb) != 0 {
return false
}
}
return true
}
for i, testcase := range tests {
node := versioned.Node{
Status: versioned.NodeStatus{
Capacity: copyResourceList(testcase.capacity),
Allocatable: copyResourceList(testcase.allocatable),
},
}
node2 := roundTrip(t, runtime.Object(&node)).(*versioned.Node)
actual := node2.Status.Allocatable
expected := testcase.expectedAllocatable
if !resourceListsEqual(expected, actual) {
t.Errorf("[%d] Expected NodeStatus.Allocatable: %+v; Got: %+v", i, expected, actual)
}
}
}
func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
s := versioned.PodSpec{
Containers: []versioned.Container{

File diff suppressed because it is too large Load Diff

View File

@ -1864,9 +1864,12 @@ 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 represents the total resources of a node.
// More info: http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity for more details.
Capacity ResourceList `json:"capacity,omitempty"`
// Allocatable represents the resources of a node that are available for scheduling.
// Defaults to Capacity.
Allocatable ResourceList `json:"allocatable,omitempty"`
// NodePhase is the recently observed lifecycle phase of the node.
// More info: http://releases.k8s.io/HEAD/docs/admin/node.md#node-phase
Phase NodePhase `json:"phase,omitempty"`

View File

@ -702,7 +702,8 @@ func (NodeSpec) SwaggerDoc() map[string]string {
var map_NodeStatus = map[string]string{
"": "NodeStatus is information about the current status of a node.",
"capacity": "Capacity represents the available resources of a node. More info: http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity for more details.",
"capacity": "Capacity represents the total resources of a node. More info: http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#capacity for more details.",
"allocatable": "Allocatable represents the resources of a node that are available for scheduling. Defaults to Capacity.",
"phase": "NodePhase is the recently observed lifecycle phase of the node. More info: http://releases.k8s.io/HEAD/docs/admin/node.md#node-phase",
"conditions": "Conditions is an array of current observed node conditions. More info: http://releases.k8s.io/HEAD/docs/admin/node.md#node-condition",
"addresses": "List of addresses reachable to the node. Queried from cloud provider, if available. More info: http://releases.k8s.io/HEAD/docs/admin/node.md#node-addresses",