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

[JENKINS-51248] Added label and container regex to fail job if bad #332

Merged
merged 8 commits into from
Jun 12, 2018

Conversation

MattLud
Copy link
Contributor

@MattLud MattLud commented May 25, 2018

Initial approach to providing validation and immediate job failure on bad label and name.

Please review correctness of regex and if throwable Exception should be changed.

@carlossg
Copy link
Contributor

I don't like the fact that a lot of setters throw exceptions and get propagated all over the place

I have asked around and got this advice

throw IllegalArgumentException from @DataBoundConstructor / @DataBoundSetter
matched with StepDescriptor.doCheckXXX for the Pipeline Syntax UI
you can also just throw (say) AbortException from Step.start

public void setLabel(String label) throws Exception {
if(!PodTemplateUtils.validateLabel(label))
{
throw new Exception(String.format("Labels must follow required specs - https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set - %s", label));
Copy link
Member

Choose a reason for hiding this comment

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

Why not IllegalArgumentException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct - removed it and replaced with above advice.

@@ -81,6 +81,10 @@ public ContainerTemplate(String name, String image, String command, String args)

@DataBoundSetter
public void setName(String name) {
if(!PodTemplateUtils.validateContainerName(name))
{
throw new IllegalArgumentException(String.format("Container Names MUST match RFC 1123 - They can only contain lowercase letters, numbers or dashes. ContainerName-%s",name));
Copy link
Member

Choose a reason for hiding this comment

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

Fine but you should then add FormValidation DescriptorImpl.doCheckName(@QueryParameter String name) so that users of Pipeline Syntax will see that a proposed step configuration is invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Thanks!

@MattLud MattLud force-pushed the JENKINS-51248 branch 2 times, most recently from 44bbb2c to 3cc14a0 Compare May 29, 2018 22:49
@MattLud
Copy link
Contributor Author

MattLud commented May 29, 2018

Updated to remove grossy unnecessary exception declarations.

@carlossg carlossg changed the title [WIP]JENKINS-51248: Added label and container regex to fail job if bad [JENKINS-51248] Added label and container regex to fail job if bad May 30, 2018
carlossg added 7 commits May 30, 2018 09:51
Move pipeline tests that don't need kubernetes to a new class
Need to pass it explicitly because if ip does not exist tests will fail with

    java.net.BindException: Cannot assign requested address
@carlossg carlossg merged commit 4dca515 into jenkinsci:master Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants