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

fix(controller): make creator label DNS compliant. Fixes #4880 #4881

Merged
merged 2 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Currently, the following organizations are **officially** using Argo Workflows:
1. [Microblink](https://microblink.com/)
1. [Mirantis](https://mirantis.com/)
1. [Mixpanel](https://mixpanel.com)
1. [Motus](https://www.motus.com)
1. [New Relic](https://newrelic.com/)
1. [Nikkei](https://www.nikkei.co.jp/nikkeiinfo/en/)
1. [Norwegian Refugee Council](https://www.nrc.no/)
Expand Down
3 changes: 2 additions & 1 deletion workflow/creator/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ func Label(ctx context.Context, obj metav1.Object) {

func dnsFriendly(s string) string {
value := regexp.MustCompile("[^-_.a-z0-9A-Z]").ReplaceAllString(s, "-")
value = regexp.MustCompile("^[^a-z0-9A-Z]*").ReplaceAllString(value, "")
value = regexp.MustCompile("[^a-z0-9A-Z]*$").ReplaceAllString(value, "")
if len(value) > 63 {
value = value[len(value)-63:]
}
value = strings.TrimLeft(value, "-")
return value
}
7 changes: 7 additions & 0 deletions workflow/creator/creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ func TestLabel(t *testing.T) {
assert.Equal(t, "y", wf.Labels[common.LabelKeyCreator])
}
})
t.Run("InvalidDNSNames", func(t *testing.T) {
wf := &wfv1.Workflow{}
Label(context.WithValue(context.TODO(), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "!@#$%^&*()--__" + strings.Repeat("y", 35) + "__--!@#$%^&*()"}}), wf)
if assert.NotEmpty(t, wf.Labels) {
assert.Equal(t, strings.Repeat("y", 35), wf.Labels[common.LabelKeyCreator])
}
})
}