mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #20380 from mqliang/podcidr-validation
pod cidr validation
This commit is contained in:
commit
e6639de333
@ -1835,13 +1835,19 @@ func ValidateNodeUpdate(node, oldNode *api.Node) field.ErrorList {
|
|||||||
addresses[address] = true
|
addresses[address] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(oldNode.Spec.PodCIDR) == 0 {
|
||||||
|
// Allow the controller manager to assign a CIDR to a node if it doesn't have one.
|
||||||
|
oldNode.Spec.PodCIDR = node.Spec.PodCIDR
|
||||||
|
} else {
|
||||||
|
if oldNode.Spec.PodCIDR != node.Spec.PodCIDR {
|
||||||
|
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "podCIDR"), "node updates may not change podCIDR except from \"\" to valid"))
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: move reset function to its own location
|
// TODO: move reset function to its own location
|
||||||
// Ignore metadata changes now that they have been tested
|
// Ignore metadata changes now that they have been tested
|
||||||
oldNode.ObjectMeta = node.ObjectMeta
|
oldNode.ObjectMeta = node.ObjectMeta
|
||||||
// Allow users to update capacity
|
// Allow users to update capacity
|
||||||
oldNode.Status.Capacity = node.Status.Capacity
|
oldNode.Status.Capacity = node.Status.Capacity
|
||||||
// Allow the controller manager to assign a CIDR to a node.
|
|
||||||
oldNode.Spec.PodCIDR = node.Spec.PodCIDR
|
|
||||||
// Allow users to unschedule node
|
// Allow users to unschedule node
|
||||||
oldNode.Spec.Unschedulable = node.Spec.Unschedulable
|
oldNode.Spec.Unschedulable = node.Spec.Unschedulable
|
||||||
// Clear status
|
// Clear status
|
||||||
|
@ -3245,6 +3245,36 @@ func TestValidateNodeUpdate(t *testing.T) {
|
|||||||
Labels: map[string]string{"foo": "baz"},
|
Labels: map[string]string{"foo": "baz"},
|
||||||
},
|
},
|
||||||
}, true},
|
}, true},
|
||||||
|
{api.Node{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
PodCIDR: "",
|
||||||
|
},
|
||||||
|
}, api.Node{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
PodCIDR: "192.168.0.0/16",
|
||||||
|
},
|
||||||
|
}, true},
|
||||||
|
{api.Node{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
PodCIDR: "192.123.0.0/16",
|
||||||
|
},
|
||||||
|
}, api.Node{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: api.NodeSpec{
|
||||||
|
PodCIDR: "192.168.0.0/16",
|
||||||
|
},
|
||||||
|
}, false},
|
||||||
{api.Node{
|
{api.Node{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Loading…
Reference in New Issue
Block a user