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

label: Invalidate empty or invalid value labels #8556

Merged
merged 1 commit into from May 28, 2015
Merged

label: Invalidate empty or invalid value labels #8556

merged 1 commit into from May 28, 2015

Conversation

0xmichalis
Copy link
Contributor

No description provided.

@0xmichalis 0xmichalis changed the title label: Invalidate empty value labels label: Invalidate empty or invalid value labels May 20, 2015
@k8s-bot
Copy link

k8s-bot commented May 21, 2015

Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist")

If this message is too spammy, please complain @ixdy.

@bgrant0607 bgrant0607 assigned j3ffml and unassigned brendandburns May 22, 2015
@bgrant0607
Copy link
Member

ok to test

@@ -103,7 +104,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) {
for _, labelSpec := range spec {
if strings.Index(labelSpec, "=") != -1 {
parts := strings.Split(labelSpec, "=")
if len(parts) != 2 {
if len(parts) != 2 || len(parts[1]) == 0 || !util.IsValidLabelValue(parts[1]) {
return nil, nil, fmt.Errorf("invalid label spec: %v", labelSpec)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's preexisting, but invalid user input should return UsageError. Do you mind fixing references in this file?

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 this in the main RunLabel function.

@j3ffml
Copy link
Contributor

j3ffml commented May 22, 2015

Users shouldn't be expected to remember the rules for a valid label spec. Let's include the valid label regexp in the help string.

@0xmichalis
Copy link
Contributor Author

Users shouldn't be expected to remember the rules for a valid label spec. Let's include the valid label regexp in the help string.

I've updated the help string with a simple explanation of what's needed for a valid label value.

"github.com/spf13/cobra"
)

const (
label_long = `Update the labels on a resource.

A valid label value is consisted of letters and/or numbers with a max length of %[1]d characters.
Copy link
Contributor

Choose a reason for hiding this comment

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

Labels can also contain -, ., and_, which is why I was suggesting putting the regex into the help string. Rule is here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about mentioning those characters as well?

A valid label value is consisted of letters, numbers, and some special characters (hyphen, dot, underscore) with a max length of 63 characters.

Imho it feels much more user-friendly than eg.

A valid label value has to comply with the ([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9] regural expression with a max length of 63 characters.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm probably weird in that I prefer the regex. Fine with me to stick to English, so long as the rule is concisely and accurately stated. Label must begin with a letter or number, and may contain letters, numbers, hyphens, dots, and underscores, up to 63 characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@j3ffml
Copy link
Contributor

j3ffml commented May 26, 2015

LGTM, thanks!

@j3ffml j3ffml added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 26, 2015
@thockin
Copy link
Member

thockin commented May 27, 2015

needs rebase

@0xmichalis
Copy link
Contributor Author

rebased

thockin added a commit that referenced this pull request May 28, 2015
label: Invalidate empty or invalid value labels
@thockin thockin merged commit d355154 into kubernetes:master May 28, 2015
@0xmichalis 0xmichalis deleted the label-parsing-fix branch May 29, 2015 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants