Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/oxlint-0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee authored Aug 27, 2024
2 parents db14e6e + cf5f941 commit 58271b6
Show file tree
Hide file tree
Showing 39 changed files with 928 additions and 877 deletions.
2 changes: 1 addition & 1 deletion .gitlint
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ contrib=CT1
ignore=B6

[contrib-title-conventional-commits]
types = amend,build,ci,config,docs,feat,fix,perf,refactor,style,test
types = amend,build,ci,config,docs,feat,fix,perf,refactor,style,test,chore
8 changes: 8 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tabWidth: 2
semi: true
singleQuote: true
bracketSpacing: true
trailingComma: all
arrowParens: avoid
printWidth: 120
singleAttributePerLine: false
8 changes: 4 additions & 4 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3"
version: '3'

env:
SERVICES: >-
Expand Down Expand Up @@ -29,9 +29,9 @@ tasks:
kubectl:
desc: Generate kubeconfig from all clusters
env:
SLUGS: "pichu pikachu raichu suicune entei"
PCLUSTERS: "entei"
VCLUSTERS: "pichu pikachu raichu"
SLUGS: 'pichu pikachu raichu suicune entei'
PCLUSTERS: 'entei'
VCLUSTERS: 'pichu pikachu raichu'
cmds:
- ./scripts/local/update-kubectl.sh
sync:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
24 changes: 11 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { search } from "@inquirer/prompts";
import { dependencies } from "./src/init";
import { initTasks } from "./src/init/tasks.ts";
import { initRunBooks } from "./src/init/runbooks.ts";
import type { RunBook } from "./src/books/run-book.ts";
import { search } from '@inquirer/prompts';
import { dependencies } from './src/init';
import { initTasks } from './src/init/tasks.ts';
import { initRunBooks } from './src/init/runbooks.ts';
import type { RunBook } from './src/books/run-book.ts';

type Choice<Value> = {
value: Value;
Expand All @@ -17,13 +17,11 @@ const tasks = initTasks(dependencies);
const books = initRunBooks(dependencies, tasks);

const book = (await search<RunBook>({
message: "Which run book do you want to run?",
source: (
input: string | undefined,
): Choice<RunBook>[] | Promise<Choice<RunBook>[]> => {
message: 'Which run book do you want to run?',
source: (input: string | undefined): Choice<RunBook>[] | Promise<Choice<RunBook>[]> => {
return books
.filter((b) => b.name.toLowerCase().includes((input ?? "").toLowerCase()))
.map((b) => ({
.filter(b => b.name.toLowerCase().includes((input ?? '').toLowerCase()))
.map(b => ({
name: b.name,
value: b,
description: b.desc,
Expand All @@ -37,9 +35,9 @@ try {
if (e != null) {
if (e.exitCode) {
console.log(`❌ Error running book, exit code: ${e.exitCode}`);
console.log("========= stderr start ==========");
console.log('========= stderr start ==========');
console.log(e.stderr.toString());
console.log("========= stderr end ==========");
console.log('========= stderr end ==========');
console.log(
Bun.inspect(e, {
colors: true,
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -eou pipefail

bun i
bun i --frozen-lockfile

pre-commit run --all-files -v
2 changes: 1 addition & 1 deletion scripts/local/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ for service in ${SERVICES[@]}; do
fi
done

echo "🔧 Done!"
echo "🔧 Done!"
43 changes: 20 additions & 23 deletions src/books/admin-cluster-migration/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { RunBook } from "../run-book.ts";
import type { ServiceTreePrompter } from "../../lib/prompts/landscape.ts";
import type { ServiceTreePrinter } from "../../lib/utility/service-tree-printer.ts";
import type { BareAdminClusterCloudCreator } from "../bare-admin-cluster-creation/cloud.ts";
import type { GenericGracefulAdminClusterDestructor } from "../graceful-admin-cluster-destruction/generic.ts";
import type { AdminClusterTransitioner } from "./transition.ts";
import type { RunBook } from '../run-book.ts';
import type { ServiceTreePrompter } from '../../lib/prompts/landscape.ts';
import type { ServiceTreePrinter } from '../../lib/utility/service-tree-printer.ts';
import type { BareAdminClusterCloudCreator } from '../bare-admin-cluster-creation/cloud.ts';
import type { GenericGracefulAdminClusterDestructor } from '../graceful-admin-cluster-destruction/generic.ts';
import type { AdminClusterTransitioner } from './transition.ts';

class AdminClusterMigrator implements RunBook {
name: string = "Admin Cluster Migration";
desc: string = "Migrate an admin cluster to a new cluster";
name: string = 'Admin Cluster Migration';
desc: string = 'Migrate an admin cluster to a new cluster';

constructor(
private stp: ServiceTreePrompter,
Expand All @@ -19,31 +19,28 @@ class AdminClusterMigrator implements RunBook {

async Run(): Promise<void> {
const [fromLandscape, fromCluster] = await this.stp.AdminLandscapeCluster(
"Select the admin landscape to migrate from",
"Select the admin cloud to migrate from",
"Select the admin cluster to migrate from",
'Select the admin landscape to migrate from',
'Select the admin cloud to migrate from',
'Select the admin cluster to migrate from',
);
const [toLandscape, toCluster] = await this.stp.AdminLandscapeCluster(
"Select the admin landscape to migrate to",
"Select the admin cloud to migrate to",
"Select the admin cluster to migrate to",
'Select the admin landscape to migrate to',
'Select the admin cloud to migrate to',
'Select the admin cluster to migrate to',
);

console.log("🎯 Selected Service Tree to migrate");
this.printer.Print("From", [fromLandscape, fromCluster]);
this.printer.Print("To ", [toLandscape, toCluster]);
console.log('🎯 Selected Service Tree to migrate');
this.printer.Print('From', [fromLandscape, fromCluster]);
this.printer.Print('To ', [toLandscape, toCluster]);

// select the cloud to create the new cluster in
const c = this.clouds.find((x) => x.slug === toCluster.cloud.slug);
if (!c) return console.log("⚠️ Cloud not supported");
const c = this.clouds.find(x => x.slug === toCluster.cloud.slug);
if (!c) return console.log('⚠️ Cloud not supported');

await c.Run([toLandscape, toCluster]);

// perform transition
await this.transition.Run(
[fromLandscape, fromCluster],
[toLandscape, toCluster],
);
await this.transition.Run([fromLandscape, fromCluster], [toLandscape, toCluster]);

// destroy old cluster
await this.destructors.Run([fromLandscape, fromCluster]);
Expand Down
61 changes: 26 additions & 35 deletions src/books/admin-cluster-migration/transition.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type {
LandscapeCluster,
ServiceTreeService,
} from "../../lib/service-tree-def.ts";
import type { TaskRunner } from "../../tasks/tasks.ts";
import type { KubectlUtil, Resource } from "../../lib/utility/kubectl-util.ts";
import { $ } from "bun";
import type { SulfoxideHeliumWaiter } from "../../tasks/sulfoxide-helium-waiter.ts";
import type { SulfoxideBoronWaiter } from "../../tasks/sulfoxide-boron-waiter.ts";
import type { LandscapeCluster, ServiceTreeService } from '../../lib/service-tree-def.ts';
import type { TaskRunner } from '../../tasks/tasks.ts';
import type { KubectlUtil, Resource } from '../../lib/utility/kubectl-util.ts';
import { $ } from 'bun';
import type { SulfoxideHeliumWaiter } from '../../tasks/sulfoxide-helium-waiter.ts';
import type { SulfoxideBoronWaiter } from '../../tasks/sulfoxide-boron-waiter.ts';

class AdminClusterTransitioner {
constructor(
Expand All @@ -19,10 +16,7 @@ class AdminClusterTransitioner {
private sulfoxideBoronWaiter: SulfoxideBoronWaiter,
) {}

async Run(
[fL, fC]: LandscapeCluster,
[tL, tC]: LandscapeCluster,
): Promise<void> {
async Run([fL, fC]: LandscapeCluster, [tL, tC]: LandscapeCluster): Promise<void> {
// common variables

// services
Expand All @@ -41,7 +35,7 @@ class AdminClusterTransitioner {
// dir
const F_Dir = `./platforms/${F.platform.slug}/${F.principal.slug}`;

console.log("🎯 Both systems are operational, performing transition...");
console.log('🎯 Both systems are operational, performing transition...');
const prefix = `${He_NS}-argocd`;
const resources: Resource[] = [
...[
Expand All @@ -50,14 +44,14 @@ class AdminClusterTransitioner {
`${prefix}-redis`,
`${prefix}-server`,
`${prefix}-repo-server`,
].map((name) => ({
kind: "deployment",
].map(name => ({
kind: 'deployment',
context: fCtx,
namespace: He_NS,
name,
})),
{
kind: "statefulset",
kind: 'statefulset',
context: fCtx,
namespace: He_NS,
name: `${prefix}-application-controller`,
Expand All @@ -66,65 +60,62 @@ class AdminClusterTransitioner {
const replicas: Record<string, number> = {};

await this.t.Run([
"Get Replicas",
'Get Replicas',
async () => {
for (const resource of resources)
replicas[resource.name] = await this.k.GetReplica(resource);
for (const resource of resources) replicas[resource.name] = await this.k.GetReplica(resource);
},
]);

console.log("🔀 Replicas before scaling down:", replicas);
console.log('🔀 Replicas before scaling down:', replicas);

await this.t.Run([
"Scale Down Old Cluster",
'Scale Down Old Cluster',
async () => {
for (const resource of resources) await this.k.Scale(resource, 0);
},
]);

// perform migration via velero
await this.t.Run([
"Velero Migration",
'Velero Migration',
async () => {
await $`nix develop -c pls migrate -- ${fCtx} ${tCtx}`.cwd(F_Dir);
},
]);

await this.t.Exec([
"Wait for Helium to be migrated",
'Wait for Helium to be migrated',
async () => {
await this.k.Wait(5, 5, {
kind: "deployment",
kind: 'deployment',
context: tCtx,
namespace: He_NS,
selector: [["app.kubernetes.io/part-of", `argocd`]],
selector: [['app.kubernetes.io/part-of', `argocd`]],
});
await this.k.Wait(1, 5, {
kind: "statefulset",
kind: 'statefulset',
context: tCtx,
namespace: He_NS,
selector: [["app.kubernetes.io/part-of", `argocd`]],
selector: [['app.kubernetes.io/part-of', `argocd`]],
});
},
]);

await this.t.Exec([
"Wait for Boron to be migrated",
'Wait for Boron to be migrated',
async () => {
await this.k.Wait(1, 5, {
kind: "deployment",
kind: 'deployment',
context: tCtx,
namespace: B_NS,
fieldSelector: [
["metadata.name", `${B.platform.slug}-${B.principal.slug}`],
],
fieldSelector: [['metadata.name', `${B.platform.slug}-${B.principal.slug}`]],
});
},
]);

// Scale back up the new cluster
await this.t.Run([
"Scale Up New Cluster",
'Scale Up New Cluster',
async () => {
for (const resource of resources) {
resource.context = tCtx;
Expand All @@ -140,7 +131,7 @@ class AdminClusterTransitioner {
const waitForBoron = this.sulfoxideBoronWaiter.task(tCtx, B_NS);
await this.t.Run(waitForBoron);

console.log("🎉 Transition completed!");
console.log('🎉 Transition completed!');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/books/bare-admin-cluster-creation/cloud.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LandscapeCluster } from "../../lib/service-tree-def.ts";
import type { LandscapeCluster } from '../../lib/service-tree-def.ts';

interface BareAdminClusterCloudCreator {
slug: string;
Expand Down
Loading

0 comments on commit 58271b6

Please sign in to comment.