-
Notifications
You must be signed in to change notification settings - Fork 40
🌱 improve ip address validation #1249
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,8 +86,28 @@ func (webhook *IPAddress) ValidateCreate(_ context.Context, obj runtime.Object) | |
| "cannot be empty", | ||
| ), | ||
| ) | ||
| } else if validateIP(c.Spec.Address) != nil { | ||
| allErrs = append(allErrs, | ||
| field.Invalid( | ||
| field.NewPath("spec", "address"), | ||
| c.Spec.Address, | ||
| "is not a valid IP address", | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| // Validate requested IP address if present in annotations (for CAPI claims) | ||
| if requestedIP, ok := c.ObjectMeta.Annotations["ipAddress"]; ok && requestedIP != "" { | ||
| if validateIP(ipamv1.IPAddressStr(requestedIP)) != nil { | ||
| allErrs = append(allErrs, | ||
| field.Invalid( | ||
| field.NewPath("metadata", "annotations", "ipAddress"), | ||
| requestedIP, | ||
| "is not a valid IP address", | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
|
Comment on lines
+99
to
+110
|
||
| if len(allErrs) == 0 { | ||
| return nil, nil | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,19 @@ func (webhook *IPClaim) ValidateCreate(_ context.Context, obj runtime.Object) (a | |
| ) | ||
| } | ||
|
|
||
| // Validate requested IP address if present in annotations | ||
| if requestedIP, ok := c.ObjectMeta.Annotations["ipAddress"]; ok && requestedIP != "" { | ||
| if err := validateIP(ipamv1.IPAddressStr(requestedIP)); err != nil { | ||
| allErrs = append(allErrs, | ||
| field.Invalid( | ||
| field.NewPath("metadata", "annotations", "ipAddress"), | ||
| requestedIP, | ||
| "is not a valid IP address", | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
|
Comment on lines
+71
to
+82
|
||
|
|
||
| if len(allErrs) == 0 { | ||
| return nil, nil | ||
| } | ||
|
|
@@ -113,6 +126,19 @@ func (webhook *IPClaim) ValidateUpdate(_ context.Context, oldObj, newObj runtime | |
| ) | ||
| } | ||
|
|
||
| // Validate requested IP address if present in annotations | ||
| if requestedIP, ok := newIPClaim.ObjectMeta.Annotations["ipAddress"]; ok && requestedIP != "" { | ||
| if validateIP(ipamv1.IPAddressStr(requestedIP)) != nil { | ||
| allErrs = append(allErrs, | ||
| field.Invalid( | ||
| field.NewPath("metadata", "annotations", "ipAddress"), | ||
| requestedIP, | ||
| "is not a valid IP address", | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
|
Comment on lines
+129
to
+140
|
||
|
|
||
| if len(allErrs) == 0 { | ||
| return nil, nil | ||
| } | ||
|
|
||
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.
Is user allowed to add annotation after creation?
if yes lets add this validation in Update also?