Skip to content
Merged
Changes from all commits
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: 13 additions & 0 deletions pkg/controller/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var (
ErrMaxLenTooSmall = errors.New("maxLen must be greater than 10")
)

// K8sMaxNameLength is the maximum length for Kubernetes resource names.
const K8sMaxNameLength = 63

// version8UUID creates a new UUID (version 8) from a byte slice. Returns an error if the slice does not have a length of 16. The bytes are copied from the slice.
// The bits 48-51 and 64-65 are modified to make the output recognizable as a version 8 UUID, so only 122 out of 128 bits from the input data will be kept.
func version8UUID(data []byte) (uuid.UUID, error) {
Expand Down Expand Up @@ -136,3 +139,13 @@ func ShortenToXCharacters(input string, maxLen int) (string, error) {

return input[:trimLength] + suffix, nil
}

// ShortenToXCharactersUnsafe works like ShortenToXCharacters, but panics instead of returning an error.
// This should only be used in places where the input is guaranteed to be valid.
func ShortenToXCharactersUnsafe(input string, maxLen int) string {
result, err := ShortenToXCharacters(input, maxLen)
if err != nil {
panic(err)
}
return result
}