Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix providerID update validation #51761

Merged
merged 1 commit into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3437,6 +3437,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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if oldNode.Spec.ProviderID == ""

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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the new ProviderID to the error to make this easier to debug?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't usually do that for Forbidden errors because ... I forget why. If we want to do that, we should add a field to the error struct and do it all over.

}
}

// TODO: move reset function to its own location
// Ignore metadata changes now that they have been tested
oldNode.ObjectMeta = node.ObjectMeta
Expand Down
27 changes: 27 additions & 0 deletions pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8245,6 +8245,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"
Expand Down