Merge pull request #51761 from karataliu/ccmupdatenode

Automatic merge from submit-queue (batch tested with PRs 51819, 51706, 51761, 51818, 51500)

Fix providerID update validation

**What this PR does / why we need it**:
Cloud controller manager supports updating providerID in #50730, but the node updating was blocked by 
validation rule.

This is to propose a fix for updating the validation rule by allowing altering spec.providerID if not set.

Please check #51596 for detail

**Which issue this PR fixes**
fixes #51596

**Special notes for your reviewer**:

**Release note**:
```release-note
```
This commit is contained in:
Kubernetes Submit Queue 2017-09-03 15:00:07 -07:00 committed by GitHub
commit 3c621d6ee6
2 changed files with 37 additions and 0 deletions

View File

@ -3476,6 +3476,16 @@ func ValidateNodeUpdate(node, oldNode *api.Node) field.ErrorList {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "podCIDR"), "node updates may not change podCIDR except from \"\" to valid"))
}
}
// Allow controller manager updating provider ID when not set
if len(oldNode.Spec.ProviderID) == 0 {
oldNode.Spec.ProviderID = node.Spec.ProviderID
} else {
if oldNode.Spec.ProviderID != node.Spec.ProviderID {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "providerID"), "node updates may not change providerID except from \"\" to valid"))
}
}
// TODO: move reset function to its own location
// Ignore metadata changes now that they have been tested
oldNode.ObjectMeta = node.ObjectMeta

View File

@ -8375,6 +8375,33 @@ func TestValidateNodeUpdate(t *testing.T) {
},
},
}, false},
{api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "update-provider-id-when-not-set",
},
}, api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "update-provider-id-when-not-set",
},
Spec: api.NodeSpec{
ProviderID: "provider:///new",
},
}, true},
{api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "update-provider-id-when-set",
},
Spec: api.NodeSpec{
ProviderID: "provider:///old",
},
}, api.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "update-provider-id-when-set",
},
Spec: api.NodeSpec{
ProviderID: "provider:///new",
},
}, false},
}
for i, test := range tests {
test.oldNode.ObjectMeta.ResourceVersion = "1"