Skip to content

Commit d6e15ed

Browse files
authored
Merge pull request konflux-ci#530 from gbenhaim/username
fix(konflux-ci#530): support email usernames K8s allows usernames to be in the format of an email address. Changing the the author mutating webhook to support it. Signed-off-by: gbenhaim <[email protected]>
2 parents a463e28 + 95e35f3 commit d6e15ed

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

api/v1alpha1/webhooks/author/webhook.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (w *Webhook) setAuthorLabel(username string, obj client.Object) {
163163
// sanitizeLabelValue takes a username and returns it in a form appropriate to use as a label value.
164164
func (w *Webhook) sanitizeLabelValue(username string) string {
165165
author := strings.Replace(username, ":", "_", -1) // Colons disallowed in labels
166+
author = strings.Replace(author, "@", ".", 1) // At sign is disallowed. Support usernames that uses email address.
166167

167168
if len(author) > metadata.MaxLabelLength {
168169
author = string(author)[0:metadata.MaxLabelLength]

api/v1alpha1/webhooks/author/webhook_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,5 +526,10 @@ var _ = Describe("Author webhook", Ordered, func() {
526526
str := webhook.sanitizeLabelValue("abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_1234567890")
527527
Expect(str).To(Equal("abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_123456789"))
528528
})
529+
530+
It("should convert @ to .", func() {
531+
str := webhook.sanitizeLabelValue("[email protected]")
532+
Expect(str).To(Equal("user.konflux-ci.dev"))
533+
})
529534
})
530535
})

0 commit comments

Comments
 (0)