Skip to content

Commit

Permalink
fix(#530): support email usernames
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
gbenhaim committed Aug 5, 2024
1 parent add0d0d commit 3ae9522
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/webhooks/author/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (w *Webhook) setAuthorLabel(username string, obj client.Object) {
// sanitizeLabelValue takes a username and returns it in a form appropriate to use as a label value.
func (w *Webhook) sanitizeLabelValue(username string) string {
author := strings.Replace(username, ":", "_", -1) // Colons disallowed in labels
author = strings.Replace(author, "@", ".", 1) // At sign is disallowed. Support usernames that uses email address.

if len(author) > metadata.MaxLabelLength {
author = string(author)[0:metadata.MaxLabelLength]
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/webhooks/author/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,5 +526,10 @@ var _ = Describe("Author webhook", Ordered, func() {
str := webhook.sanitizeLabelValue("abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_1234567890")
Expect(str).To(Equal("abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_123456789"))
})

It("should convert @ to .", func() {
str := webhook.sanitizeLabelValue("[email protected]")
Expect(str).To(Equal("user.konflux-ci.dev"))
})
})
})

0 comments on commit 3ae9522

Please sign in to comment.