Skip to content

Commit

Permalink
fix(controller): make creator label DNS compliant. Fixes #4880 (#4881)
Browse files Browse the repository at this point in the history
igned-off-by: Eric Meaney <emeaney@motus.com>
  • Loading branch information
ermeaney committed Jan 14, 2021
1 parent 2ff11cc commit 17e79e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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])
}
})
}

0 comments on commit 17e79e8

Please sign in to comment.