Skip to content

Commit

Permalink
fix: dns truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Aug 29, 2023
1 parent ccb4b97 commit 643cadb
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions plugins/contrib/patches/03-dns-truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,36 @@ module.exports = (manifests, _options, context) => {
const { utils } = context
const { yaml, slug, logger } = utils

const subdomainsToTruncate = []
for (const manifest of manifests) {
if (manifest.kind !== "Ingress") {
continue
}
const rules = manifest.spec?.rules || []
for (const { host } of rules) {
const domainParts = host.split(".")
for (const subdomain of domainParts) {
if (subdomain.length > MAX_DNS_LENGTH) {
subdomainsToTruncate.push(subdomain)
let subdomainsToTruncate = []
do {
subdomainsToTruncate = []
for (const manifest of manifests) {
if (manifest.kind !== "Ingress") {
continue
}
const rules = manifest.spec?.rules || []
for (const { host } of rules) {
const domainParts = host.split(".")
for (const subdomain of domainParts) {
if (subdomain.length > MAX_DNS_LENGTH) {
subdomainsToTruncate.push(subdomain)
}
}
}
}
}
if (subdomainsToTruncate.length > 0) {
let inline = yaml.dump(manifests)
for (const subdomain of subdomainsToTruncate) {
const slugSubdomain = slug(subdomain)
logger.debug(
`replacing too long subdomain "${subdomain}" -> "${slugSubdomain}"`
)
inline = inline.replaceAll(subdomain, slugSubdomain)

if (subdomainsToTruncate.length > 0) {
let inline = yaml.dump(manifests)
for (const subdomain of subdomainsToTruncate) {
const slugSubdomain = slug(subdomain)
logger.debug(
`replacing too long subdomain "${subdomain}" -> "${slugSubdomain}"`
)
inline = inline.replaceAll(subdomain, slugSubdomain)
}
manifests = yaml.load(inline)
}
manifests = yaml.load(inline)
}
} while (subdomainsToTruncate.length > 0)

return manifests
}

0 comments on commit 643cadb

Please sign in to comment.