Merge pull request #2893 from brendandburns/pd3

Make it easier to update nodes, make it possible to update capacity.
This commit is contained in:
Brendan Burns
2014-12-18 10:18:54 -08:00
4 changed files with 79 additions and 1 deletions

View File

@@ -26,6 +26,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"
)
// ServiceLister is an abstract interface for testing.
@@ -568,9 +570,18 @@ func ValidateMinion(minion *api.Node) errs.ValidationErrorList {
// ValidateMinionUpdate tests to make sure a minion update can be applied. Modifies oldMinion.
func ValidateMinionUpdate(oldMinion *api.Node, minion *api.Node) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
if !reflect.DeepEqual(minion.Status, api.NodeStatus{}) {
allErrs = append(allErrs, errs.NewFieldInvalid("status", minion.Status, "status must be empty"))
}
// Allow users to update labels and capacity
oldMinion.Labels = minion.Labels
oldMinion.Spec.Capacity = minion.Spec.Capacity
if !reflect.DeepEqual(oldMinion, minion) {
allErrs = append(allErrs, fmt.Errorf("update contains more than labels changes"))
glog.V(4).Infof("Update failed validation %#v vs %#v", oldMinion, minion)
allErrs = append(allErrs, fmt.Errorf("update contains more than labels or capacity changes"))
}
return allErrs
}

View File

@@ -1178,6 +1178,64 @@ func TestValidateMinionUpdate(t *testing.T) {
Labels: map[string]string{"foo": "baz"},
},
}, true},
{api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo",
},
Spec: api.NodeSpec{
Capacity: api.ResourceList{
"cpu": util.NewIntOrStringFromInt(10000),
"memory": util.NewIntOrStringFromInt(100),
},
},
}, api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo",
},
Spec: api.NodeSpec{
Capacity: api.ResourceList{
"cpu": util.NewIntOrStringFromInt(100),
"memory": util.NewIntOrStringFromInt(10000),
},
},
}, true},
{api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Labels: map[string]string{"bar": "foo"},
},
Spec: api.NodeSpec{
Capacity: api.ResourceList{
"cpu": util.NewIntOrStringFromInt(10000),
"memory": util.NewIntOrStringFromInt(100),
},
},
}, api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Labels: map[string]string{"bar": "fooobaz"},
},
Spec: api.NodeSpec{
Capacity: api.ResourceList{
"cpu": util.NewIntOrStringFromInt(100),
"memory": util.NewIntOrStringFromInt(10000),
},
},
}, true},
{api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Labels: map[string]string{"bar": "foo"},
},
}, api.Node{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Labels: map[string]string{"bar": "fooobaz"},
},
Status: api.NodeStatus{
HostIP: "1.2.3.4",
},
}, false},
}
for _, test := range tests {
errs := ValidateMinionUpdate(&test.oldMinion, &test.minion)