Pretty similar to Convert any string to a valid DNS subdomain, except asking it for Python (I'm using 3.10) and (sort of) Kubernetes. Hoping to accomplish this in the most pythonic (i.e. just grab a library that someone else wrote) way possible.
Kubernetes requires that resource names be a valid DNS subdomain.
I'm looking for something that more or less does:
- Converts all uppercase to lowercase
- Replaces all invalid characters with something valid (e.g.
.
or-
) - Chops invalid characters off the end
So for example:
import awesomelibrary
input = 'Inv@l^d_Stuff$.-'
output = awesomelibrary.convert_to_rfc1123_compliant(input)
print(output)
Expected output:
inv-l-d-stuff