-
Notifications
You must be signed in to change notification settings - Fork 564
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
Validate benchmark name in createBenchmark.sh script #8455
Conversation
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.
Hey @korthout thanks I also ran into this multiple times. I think it make sense to use the real regex here.
So the k8 docs says https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
RFC 1123 Label Names
Some resource types require their names to follow the DNS label standard as defined in RFC 1123. This means the name must:contain at most 63 characters
contain only lowercase alphanumeric characters or '-'
start with an alphanumeric character
end with an alphanumeric character
Found on SO that if you use a wrong namespace kubectl will tell you which regex they use
$ k create ns not-valid1234234$%
The Namespace "not-valid1234234$%" is invalid: metadata.name: Invalid value: "not-valid1234234$%": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')
Based on that and some other posts
I end with this: ^[a-z0-9]([-a-z0-9]*[a-z0-9]){,63}$
Tests:
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ test =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9]){,63}$ ]] ; then echo "valid"; fi
valid
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ test.test =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9]){,63}$ ]] ; then echo "valid"; fi
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ test-test =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9]){,63}$ ]] ; then echo "valid"; fi
valid
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ tes123t-test =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9]){,63}$ ]] ; then echo "valid"; fi
valid
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ tes123.t-test =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9]){,63}$ ]] ; then echo "valid"; fi
So my suggestion would be to use that regex to match the benchmark name. :)
Sorry the first one was not complete (or allowed to many characters): New one: [zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=123456789-123456789-123456789-123456789-123456789-123456789-123
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
valid
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=123456789-123456789-123456789-123456789-123456789-123456789-1234
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=123456789-123456789-123456789-123456789-123456789-123456789-12-
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=123456789-123456789-123456789-123456789-123456789-123456789-12A
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=123456789-123456789-123456789-123456789-123456789-123456789-12
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
valid
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=123456789-123456789-123456789-123456789-123456789-123456789-1.2
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=2
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
valid
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=-
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=2-
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=2-2
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
valid
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=22
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
valid
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ test=2.2
[zell ~/ cluster: zeebe-cluster ns:zell-st-gw-v3]$ if [[ $test =~ ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$ ]] ; then echo "valid"; fi
|
cae468f
to
96fe4d5
Compare
Tested manually:
|
createBenchmark.sh
Outdated
fi | ||
benchmark=$1 | ||
|
||
if [[ ! $benchmark =~ ^[a-z0-9][-a-z0-9]{0,61}[a-z0-9]$ ]]; then |
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.
Specific reason why not using ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$
? Single letters are normally allowed.
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.
It forced a - to be present for anything longer than 1 character
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.
But that's interesting. We can rework it to also allow 1 char
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.
It forced a - to be present for anything longer than 1 character
Not sure what you mean but above you can see in my tests #8455 (comment) it worked also for 22
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.
Hmm perhaps I had my test wrong. I'll have another look tomorrow :D
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 checked among many others ab
is not accepted by ^[a-z0-9]([-a-z0-9]{,61}[a-z0-9])?$
see https://regex101.com/r/vjsrEy/1
We can use ^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?$
see https://regex101.com/r/vjsrEy/2 🎉
96fe4d5
to
a0524d1
Compare
8473: Add recreate benchmark script r=korthout a=korthout ## Description <!-- Please explain the changes you made here. --> One of the steps in the daily release process is to check whether there are new commits on the release branch. If there are any, the benchmark must be restarted. There did not exist any script for this yet, and the manual steps are not straight forward (e.g. `newBenchmark` will fail because the namespace is already in use). To avoid these problems, a new `recreateBenchmark.sh` script is introduced that: - checks whether the namespace already exists and if not suggests solutions - rebuilds the project and the docker images - redeploys the benchmark This uses a special check for the benchmark name to be a valid DNS label. See #8455 for more details ## Related issues <!-- Which issues are closed by this PR or are related --> NA Co-authored-by: Nico Korthout <nico.korthout@camunda.com>
8473: Add recreate benchmark script r=korthout a=korthout ## Description <!-- Please explain the changes you made here. --> One of the steps in the daily release process is to check whether there are new commits on the release branch. If there are any, the benchmark must be restarted. There did not exist any script for this yet, and the manual steps are not straight forward (e.g. `newBenchmark` will fail because the namespace is already in use). To avoid these problems, a new `recreateBenchmark.sh` script is introduced that: - checks whether the namespace already exists and if not suggests solutions - rebuilds the project and the docker images - redeploys the benchmark This uses a special check for the benchmark name to be a valid DNS label. See #8455 for more details ## Related issues <!-- Which issues are closed by this PR or are related --> NA Co-authored-by: Nico Korthout <nico.korthout@camunda.com>
The create benchmark script uses the benchmark name among others for the k8s namespace. However, k8s does not accept dots in the namespace. I found this out after fully building Zeebe and the docker images locally, which takes a few minutes. We can simply check for this at the start of the script to fail early and help users of the script with such mistakes.
60ab749
to
8a6d421
Compare
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.
Thanks @korthout 💟 🎖️
bors r+
Description
The create benchmark script uses the benchmark name among others for the
k8s namespace. However, k8s does not accept dots in the namespace. I
found this out after fully building Zeebe and the docker images locally,
which takes a few minutes. We can simply check for this at the start of
the script to fail early and help users of the script with such
mistakes.
Related issues
NA
Definition of Done
Not all items need to be done depending on the issue and the pull request.
Code changes:
backport stable/0.25
) to the PR, in case that fails you need to create backports manually.Testing:
Documentation: