-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add validation to SDN objects with invalid name funcs #13124
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package validation | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"k8s.io/kubernetes/pkg/api/validation" | ||
|
@@ -85,6 +86,10 @@ func ValidateClusterNetworkUpdate(obj *sdnapi.ClusterNetwork, old *sdnapi.Cluste | |
func ValidateHostSubnet(hs *sdnapi.HostSubnet) field.ErrorList { | ||
allErrs := validation.ValidateObjectMeta(&hs.ObjectMeta, false, path.ValidatePathSegmentName, field.NewPath("metadata")) | ||
|
||
if hs.Host != hs.Name { | ||
allErrs = append(allErrs, field.Invalid(field.NewPath("host"), hs.Host, fmt.Sprintf("must be the same as metadata.name: %q", hs.Name))) | ||
} | ||
|
||
if hs.Subnet == "" { | ||
// check if annotation exists, then let the Subnet field be empty | ||
if _, ok := hs.Annotations[sdnapi.AssignHostSubnetAnnotation]; !ok { | ||
|
@@ -117,8 +122,12 @@ func ValidateHostSubnetUpdate(obj *sdnapi.HostSubnet, old *sdnapi.HostSubnet) fi | |
func ValidateNetNamespace(netnamespace *sdnapi.NetNamespace) field.ErrorList { | ||
allErrs := validation.ValidateObjectMeta(&netnamespace.ObjectMeta, false, path.ValidatePathSegmentName, field.NewPath("metadata")) | ||
|
||
if netnamespace.NetName != netnamespace.Name { | ||
allErrs = append(allErrs, field.Invalid(field.NewPath("netname"), netnamespace.NetName, fmt.Sprintf("must be the same as metadata.name: %q", netnamespace.Name))) | ||
} | ||
|
||
if err := sdnapi.ValidVNID(netnamespace.NetID); err != nil { | ||
allErrs = append(allErrs, field.Invalid(field.NewPath("netID"), netnamespace.NetID, err.Error())) | ||
allErrs = append(allErrs, field.Invalid(field.NewPath("netid"), netnamespace.NetID, err.Error())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately we're not consistent with that. But most the places I've checked use uppercase ID, so I'd suggest leaving as was. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to match the struct tags. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't notice, sorry for the noise in that case. |
||
} | ||
return allErrs | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we default Host to Name, if it's empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would simplify the redundancy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have a strong opinion on if we should or should not default this value. All existing code should be setting both of them to the same thing, so I am leaning towards just leaving this as-is.