Skip to content

Commit

Permalink
fix(controller): Deal with hyphen in creator. Fixes #4058 (#4643)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec committed Dec 9, 2020
1 parent 2d05d56 commit 1285984
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions workflow/creator/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package creator
import (
"context"
"regexp"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand All @@ -18,6 +19,7 @@ func Label(ctx context.Context, obj metav1.Object) {
if len(value) > 63 {
value = value[len(value)-63:]
}
value = strings.TrimLeft(value, "-")
labels.Label(obj, common.LabelKeyCreator, value)
}
}
7 changes: 7 additions & 0 deletions workflow/creator/creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ func TestLabel(t *testing.T) {
assert.Equal(t, strings.Repeat("x", 62)+"y", wf.Labels[common.LabelKeyCreator])
}
})
t.Run("TooLongHyphen", func(t *testing.T) {
wf := &wfv1.Workflow{}
Label(context.WithValue(context.TODO(), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: strings.Repeat("-", 63) + "y"}}), wf)
if assert.NotEmpty(t, wf.Labels) {
assert.Equal(t, "y", wf.Labels[common.LabelKeyCreator])
}
})
}

0 comments on commit 1285984

Please sign in to comment.