5export const overwriteextdnsowner = async () => { 6 const hostname = process.env.OVERWRITE_HOSTNAME 7 if (!hostname) return throPtErr('set OVERWRITE_HOSTNAME env var') 12 const zoneName = hostname.split('.').slice(-2).join('.') 13 console.log(`deleting external-dns ownership for ${hostname}`) 15 const zones = await cfFetch('/zones', headers) 16 const zone = zones.find((z: any) => z.name === zoneName) 19 const allRecords = await cfFetch(`/zones/${zone.id}/dns_records?per_page=1000`, headers) 20 const matchNames = [hostname, `a-${hostname}`, `cname-${hostname}`] 21 const txtOwnerRecords = allRecords.filter((r: any) => 22 r.type === 'TXT' && r.content.includes('heritage=external-dns') && matchNames.includes(r.name) 24 const aRecords = allRecords.filter((r: any) => 25 (r.type === 'A' || r.type === 'CNAME') && r.name === hostname 27 const toDelete = [...txtOwnerRecords, ...aRecords] 29 if (toDelete.length > 0) { 30 for (const record of toDelete) { 31 console.log(`deleting ${record.type} ${record.name}: ${(record.content || '').slice(0, 60)}`) 32 await cfFetch(`/zones/${zone.id}/dns_records/${record.id}`, headers, {method: 'DELETE'}) 34 console.log(`done - deleted ${toDelete.length} record(s), external-dns will recreate with correct owner on next sync`) 36 console.log('no matching records found') 40overwriteextdnsowner.cliDescript = 'delete external-dns TXT ownership record so current cluster can claim it' 41overwriteextdnsowner.cliAdvanced = true