-
Notifications
You must be signed in to change notification settings - Fork 831
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
feat: pipeline and model name validation #5872
Merged
driev
merged 9 commits into
SeldonIO:v2
from
driev:INFRA-1049/model-and-pipeline-name-validation
Sep 9, 2024
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4f3be40
adding pipeline name validation
driev 2f2dfda
adding some validation for model names
driev 5ea074d
hyphens not dashses
driev 46f6796
modifying the regex
driev b5f35cb
check for k8s format and existence of .
driev 11183b5
fixing the error message
driev 0dd681e
fixing another error message
driev 9b24377
removing grouping
driev 9b69b6b
simplify regex
driev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package utils | ||
|
||
import "regexp" | ||
|
||
func CheckName(name string) bool { | ||
ok, err := regexp.Match("^[a-zA-Z0-9][a-zA-Z0-9-_]*[a-zA-Z0-9]$", []byte(name)) | ||
if !ok || err != nil { | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestCheckName(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
tests := []struct { | ||
name string | ||
value string | ||
expectedResult bool | ||
}{ | ||
{ | ||
"a valid name", | ||
"this-NAME_is_valid1234-5", | ||
true, | ||
}, | ||
{ | ||
"a valid numerical name", | ||
"111111111111111111", | ||
true, | ||
}, | ||
{ | ||
"an invalid name that begins and ends with something alphanumeric", | ||
driev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"1-----______A", | ||
true, | ||
}, | ||
|
||
{ | ||
"an invalid name that doesn't begin and end with something alphanumeric", | ||
"-----______", | ||
false, | ||
}, | ||
{ | ||
"an invalid name that doesn't end with something alphanumeric", | ||
"A-----______", | ||
false, | ||
}, | ||
{ | ||
"an invalid name that doesn't begin with something alphanumeric", | ||
"-----______1", | ||
false, | ||
}, | ||
{ | ||
"an invalid name with a dot", | ||
"this-Is-some-NA.ME_that_is_valid1234-5", | ||
false, | ||
}, | ||
} | ||
driev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
g.Expect(CheckName(test.value)).To(BeIdenticalTo(test.expectedResult)) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The spec on what names are allowed in k8s is this one: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
k8s will already reject all names that don't obey the regex:
[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*
(this is the regex that kubectl reports when trying to create a resource with an invalid name). In particular, upper-case letters and underscores are also excluded.We'll still want to do this validation explicitly so that we deal in an uniform way with k8s and non-k8s deployments.
Beyond k8s's existing validation, we want to reserve the
.
for Seldon -- this is because internally we do header-based routing and a pipeline's name (for example) is referred to as '[name].pipeline`.I'm not sure why we don't just trim the element after the last dot when post-processing such names (and allow dots in user-provided names). I don't have the context on whether there are any other reasons why we might reserve the
.
, but perhaps we take this as a separate issue to investigate.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.
Yes, some more investigation is necessary. It would be great to have this validation aligned with k8s.