-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DNS switcher switches the external DNS to internal DNS that is organized per cluster which allows for HA. This task includes waiting for the DNS propagation (locally) to finish
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ with packages; | |
terraform | ||
bun | ||
curl | ||
dogdns | ||
]; | ||
|
||
lint = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ let | |
{ | ||
inherit | ||
coreutils | ||
dogdns | ||
sd | ||
curl | ||
bash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Task } from "./tasks.ts"; | ||
import type { CloudTreeClusterPrincipal } from "../lib/service-tree-def.ts"; | ||
import { $ } from "bun"; | ||
|
||
class LoadBalancerDNSSwitcher { | ||
constructor( | ||
private external: string, | ||
private internal: string | ||
) { | ||
} | ||
|
||
name: string = "Switching DNS for Load Balancing"; | ||
|
||
task(from: CloudTreeClusterPrincipal, target: CloudTreeClusterPrincipal): Task { | ||
return [ | ||
this.name, | ||
async () => { | ||
console.log(`🚧 Switching DNS from ${from.name} to ${target.name}`); | ||
const path = `./platforms/sulfoxide/tofu`; | ||
await $`nix develop -c pls setup`.cwd(path); | ||
await $`nix develop -c pls arceus:apply -- -var="target_cluster=${{ raw: target.slug }}" -auto-approve `.cwd(path); | ||
console.log(`✅ DNS now points to ${target.name}`); | ||
await $`sleep 120`; | ||
console.log("🔍 Checking if DNS has propagated..."); | ||
const query = async (): Promise<string> => { | ||
const result = await $`dog pichu.${this.external} -J`.cwd(path).json(); | ||
const answers: { name: string, type: string, data: { domain: string } }[] = result.responses[0].answers; | ||
return answers.find(x => x.type === "CNAME")?.data.domain ?? ""; | ||
}; | ||
const t = `${target.slug}.${this.internal}`; | ||
let domain = await query(); | ||
while (domain != t) { | ||
console.log(`⏳ Waiting for DNS to propagate...`); | ||
await $`sleep 5`; | ||
domain = await query(); | ||
} | ||
console.log(`✅ DNS propagated!`); | ||
} | ||
]; | ||
} | ||
} | ||
|
||
export { LoadBalancerDNSSwitcher }; |