Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pkg/controller/perconaservermongodb/custom_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ func handleUsers(ctx context.Context, cr *api.PerconaServerMongoDB, mongoCli mon
continue
}

annotationKey := fmt.Sprintf("percona.com/%s-%s-hash", cr.Name, user.Name)
// Kubernetes annotation keys have a limit of 63 characters for the name part
// Format: "percona.com/<name>" where it must be less than or equal to 63 characters
// We need to keep the "-hash" suffix (5 chars), so we have 58 chars for the prefix
annotationKeyBase := fmt.Sprintf("percona.com/%s-%s", cr.Name, user.Name)
const hashSuffix = "-hash"
const maxAnnotationNameLength = 63
const maxPrefixLength = maxAnnotationNameLength - len(hashSuffix)

if len(annotationKeyBase) > maxPrefixLength {
annotationKeyBase = annotationKeyBase[:maxPrefixLength]
}
annotationKey := fmt.Sprintf("%s%s", annotationKeyBase, hashSuffix)

if userInfo == nil && !user.IsExternalDB() {
err = createUser(ctx, client, mongoCli, &user, sec, annotationKey, userSecretPassKey)
Expand Down