Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Aug 26, 2024
1 parent e13f2c2 commit 9631250
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 414 deletions.
Binary file modified bun.lockb
Binary file not shown.
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!"
162 changes: 81 additions & 81 deletions src/books/physical-cluster-creation/aws.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { PhysicalClusterCloudCreator } from "./cloud.ts";
import { $ } from "bun";
import * as path from "node:path";
import type { UtilPrompter } from "../../lib/prompts/util-prompter.ts";
import { input } from "@inquirer/prompts";
import type { YamlManipulator } from "../../lib/utility/yaml-manipulator.ts";
import type { KubectlUtil } from "../../lib/utility/kubectl-util.ts";
import type { LandscapeCluster, ServiceTreeService } from "../../lib/service-tree-def.ts";
import type { TaskRunner } from "../../tasks/tasks.ts";
import type { Git } from "../../lib/utility/git.ts";
import type { PhysicalClusterCloudCreator } from './cloud.ts';
import { $ } from 'bun';
import * as path from 'node:path';
import type { UtilPrompter } from '../../lib/prompts/util-prompter.ts';
import { input } from '@inquirer/prompts';
import type { YamlManipulator } from '../../lib/utility/yaml-manipulator.ts';
import type { KubectlUtil } from '../../lib/utility/kubectl-util.ts';
import type { LandscapeCluster, ServiceTreeService } from '../../lib/service-tree-def.ts';
import type { TaskRunner } from '../../tasks/tasks.ts';
import type { Git } from '../../lib/utility/git.ts';

class AwsPhysicalClusterCreator implements PhysicalClusterCloudCreator {
slug: string;
Expand All @@ -22,14 +22,14 @@ class AwsPhysicalClusterCreator implements PhysicalClusterCloudCreator {
private sulfoxideHelium: ServiceTreeService,
private sulfoxideKrypton: ServiceTreeService,
private sulfoxideLead: ServiceTreeService,
slug: string
slug: string,
) {
this.slug = slug;
}

async Run(
[phyLandscape, phyCluster]: LandscapeCluster,
[adminLandscape, adminCluster]: LandscapeCluster
[adminLandscape, adminCluster]: LandscapeCluster,
): Promise<void> {
// constants
const tofu = this.sulfoxideTofu;
Expand All @@ -42,215 +42,215 @@ class AwsPhysicalClusterCreator implements PhysicalClusterCloudCreator {
const Kr_Dir = `./platforms/${Kr.platform.slug}/${Kr.principal.slug}`;
const Pb_Dir = `./platforms/${Pb.platform.slug}/${Pb.principal.slug}`;

const He_YamlPath = path.join(He_Dir, "chart", `values.${adminLandscape.slug}.${adminCluster.set.slug}.yaml`);
const Kr_YamlPath = path.join(Kr_Dir, "chart", `values.${phyLandscape.slug}.${phyCluster.principal.slug}.yaml`);
const Pb_YamlPath = path.join(Pb_Dir, "chart", `values.${phyLandscape.slug}.${phyCluster.principal.slug}.yaml`);
const He_YamlPath = path.join(He_Dir, 'chart', `values.${adminLandscape.slug}.${adminCluster.set.slug}.yaml`);
const Kr_YamlPath = path.join(Kr_Dir, 'chart', `values.${phyLandscape.slug}.${phyCluster.principal.slug}.yaml`);
const Pb_YamlPath = path.join(Pb_Dir, 'chart', `values.${phyLandscape.slug}.${phyCluster.principal.slug}.yaml`);

const aCtx = `${adminLandscape.slug}-${adminCluster.principal.slug}`;
const aNS = `${He.platform.slug}-${He.principal.slug}`;

// Check if we want to inject the DO secrets
const awsSecrets = await this.up.YesNo("Do you want to inject AWS secrets?");
const awsSecrets = await this.up.YesNo('Do you want to inject AWS secrets?');
if (awsSecrets) {
const access = await input({ message: "Enter your AWS Access Key" });
const access = await input({ message: 'Enter your AWS Access Key' });
await $`infisical secrets set --projectId=${tofu.principal.projectId} --env=${phyLandscape.slug} ${phyCluster.principal.slug.toUpperCase()}_AWS_ACCESS_KEY=${access}`;
console.log("✅ AWS Access Key injected");
const secret = await input({ message: "Enter your AWS Secret Key" });
console.log('✅ AWS Access Key injected');
const secret = await input({ message: 'Enter your AWS Secret Key' });
await $`infisical secrets set --projectId=${tofu.principal.projectId} --env=${phyLandscape.slug} ${phyCluster.principal.slug.toUpperCase()}_AWS_SECRET_KEY=${secret}`;
console.log("✅ AWS Secret Key injected");
console.log('✅ AWS Secret Key injected');
}

const L0 = `${phyLandscape.slug}:l0:${phyCluster.principal.slug}`;
await this.task.Run([
"Build L0 Infrastructure",
'Build L0 Infrastructure',
async () => {
await $`pls setup`.cwd(tofuDir);
await $`pls ${{ raw: L0 }}:init`.cwd(tofuDir);
await $`pls ${{ raw: L0 }}:apply`.cwd(tofuDir);
}
},
]);

await this.task.Run([
"Retrieve Kubectl Configurations",
'Retrieve Kubectl Configurations',
async () => {
await $`pls kubectl`;
}
},
]);

// extract endpoint to use
console.log("📤 Extract endpoint to use...");
console.log('📤 Extract endpoint to use...');
const output = await $`pls ${{ raw: L0 }}:output -- -json`.cwd(tofuDir).json();
const endpoint = output.cluster_endpoint.value;
console.log(`✅ Extracted endpoint: ${endpoint}`);

// build L1 generic infrastructure
const L1G = `${phyLandscape.slug}:l1:${phyCluster.set.slug}`;
await this.task.Run([
"Build L1 Generic Infrastructure",
'Build L1 Generic Infrastructure',
async () => {
await $`pls ${{ raw: L1G }}:init`.cwd(tofuDir);
await $`pls ${{ raw: L1G }}:apply`.cwd(tofuDir);
}
},
]);

// Propagate Tofu outputs for Karpenter
const nodeRole = output.karpenter_node_role_name.value;
const nodeArn = output.karpenter_role_arn.value;
console.log("📤 Extract node role and ARN to use...");
console.log('📤 Extract node role and ARN to use...');
console.log(`✅ Extracted node role: ${nodeRole}`);
console.log(`✅ Extracted node ARN: ${nodeArn}`);

await this.task.Run([
"Propagate Tofu outputs to Krypton (Karpenter)",
'Propagate Tofu outputs to Krypton (Karpenter)',
async () => {
console.log(`🛣️ Propagating YAML Path: ${Kr_YamlPath}`);
await this.y.Mutate(Kr_YamlPath, [
[["nodeRole"], nodeRole],
[["karpenterRole"], nodeArn],
[['nodeRole'], nodeRole],
[['karpenterRole'], nodeArn],
]);
}
},
]);

await this.task.Run([
"Commit changes to Krypton",
'Commit changes to Krypton',
async () => {
await this.g.CommitAndPush(Kr_Dir, "action: propagate Tofu outputs to Krypton");
}
await this.g.CommitAndPush(Kr_Dir, 'action: propagate Tofu outputs to Krypton');
},
]);

// propagate Tofu outputs for Lead
const irsaRoleArn = output.irsa_role_arn.value;
const vpcId = output.vpc_id.value;
console.log("📤 Extract IRSA Role ARN and VPC ID to use...");
console.log('📤 Extract IRSA Role ARN and VPC ID to use...');
console.log(`✅ Extracted IRSA Role ARN: ${irsaRoleArn}`);
console.log(`✅ Extracted VPC ID: ${vpcId}`);
await this.task.Run([
"Propagate Tofu outputs to Lead (IRSA Components)",
'Propagate Tofu outputs to Lead (IRSA Components)',
async () => {
await this.y.Mutate(Pb_YamlPath, [
[["role"], irsaRoleArn],
[["vpcId"], vpcId],
[['role'], irsaRoleArn],
[['vpcId'], vpcId],
]);
}
},
]);

await this.task.Run([
"Commit changes to Lead",
'Commit changes to Lead',
async () => {
await this.g.CommitAndPush(Pb_Dir, "action: propagate Tofu outputs to Lead");
}
await this.g.CommitAndPush(Pb_Dir, 'action: propagate Tofu outputs to Lead');
},
]);

// build L1 infrastructure
const L1 = `${phyLandscape.slug}:l1:${phyCluster.principal.slug}`;
await this.task.Run([
"Build L1 Infrastructure",
'Build L1 Infrastructure',
async () => {
await $`pls ${{ raw: L1 }}:init`.cwd(tofuDir);
await $`pls ${{ raw: L1 }}:apply`.cwd(tofuDir);
}
},
]);

// retrieve yaml in helium folder and replace
await this.task.Run([
"Update Helium Configuration",
'Update Helium Configuration',
async () => {
await this.y.Mutate(He_YamlPath, [
[["connector", "clusters", phyLandscape.slug, phyCluster.principal.slug, "enable"], true],
[["connector", "clusters", phyLandscape.slug, phyCluster.principal.slug, "deployAppSet"], true],
[["connector", "clusters", phyLandscape.slug, phyCluster.principal.slug, "aoa", "enable"], true],
[["connector", "clusters", phyLandscape.slug, phyCluster.principal.slug, "destination"], endpoint]
[['connector', 'clusters', phyLandscape.slug, phyCluster.principal.slug, 'enable'], true],
[['connector', 'clusters', phyLandscape.slug, phyCluster.principal.slug, 'deployAppSet'], true],
[['connector', 'clusters', phyLandscape.slug, phyCluster.principal.slug, 'aoa', 'enable'], true],
[['connector', 'clusters', phyLandscape.slug, phyCluster.principal.slug, 'destination'], endpoint],
]);
}
},
]);

// apply ArgoCD configurations
const HePls = `${adminLandscape.slug}:${adminCluster.set.slug}`;
await this.task.Run([
"Apply Helium Configuration",
'Apply Helium Configuration',
async () => {
await $`pls ${{ raw: HePls }}:install -- --kube-context ${aCtx} -n ${aNS}`.cwd(He_Dir);
}
},
]);

// retrieve kubectl configurations again
await this.task.Run([
"Retrieve Kubectl Configurations",
'Retrieve Kubectl Configurations',
async () => {
await $`pls kubectl`;
}
},
]);

// wait for iodine to be ready
console.log("🕙 Waiting for iodine to be ready...");
console.log('🕙 Waiting for iodine to be ready...');

await this.task.Exec([
"Wait for iodine applications to be ready",
'Wait for iodine applications to be ready',
async () => {
await this.k.WaitForApplications(3, {
kind: "app",
kind: 'app',
context: aCtx,
namespace: aNS,
selector: [
["atomi.cloud/sync-wave", "wave-5"],
["atomi.cloud/landscape", phyLandscape.slug],
["atomi.cloud/cluster", phyCluster.principal.slug]
]
['atomi.cloud/sync-wave', 'wave-5'],
['atomi.cloud/landscape', phyLandscape.slug],
['atomi.cloud/cluster', phyCluster.principal.slug],
],
});
}
},
]);

await this.task.Exec([
"Wait for statefulset (etcd) to be ready",
'Wait for statefulset (etcd) to be ready',
async () => {
for (const ns of ["pichu", "pikachu", "raichu"]) {
for (const ns of ['pichu', 'pikachu', 'raichu']) {
await this.k.WaitForReplica({
kind: "statefulset",
kind: 'statefulset',
context: `${phyLandscape.slug}-${phyCluster.principal.slug}`,
namespace: ns,
name: `${phyLandscape.slug}-${ns}-iodine-etcd`
name: `${phyLandscape.slug}-${ns}-iodine-etcd`,
});
}
}
},
]);

await this.task.Exec([
"Wait for deployment (iodine) to be ready",
'Wait for deployment (iodine) to be ready',
async () => {
for (const ns of ["pichu", "pikachu", "raichu"]) {
for (const ns of ['pichu', 'pikachu', 'raichu']) {
await this.k.WaitForReplica({
kind: "deployment",
kind: 'deployment',
context: `${phyLandscape.slug}-${phyCluster.principal.slug}`,
namespace: ns,
name: `${phyLandscape.slug}-${ns}-iodine`
name: `${phyLandscape.slug}-${ns}-iodine`,
});
}
}
},
]);

// retrieve kubectl configurations again
await this.task.Run([
"Retrieve Kubectl Configurations",
'Retrieve Kubectl Configurations',
async () => {
await $`pls kubectl`;
}
},
]);

// last applications to be ready
await this.task.Exec([
"Wait for vcluster carbon's last sync wave to be ready",
async () => {
await this.k.WaitForApplications(3, {
kind: "app",
kind: 'app',
context: aCtx,
namespace: aNS,
selector: [
["atomi.cloud/sync-wave", "wave-5"],
["atomi.cloud/element", "silicon"],
["atomi.cloud/cluster", phyCluster.principal.slug]
]
['atomi.cloud/sync-wave', 'wave-5'],
['atomi.cloud/element', 'silicon'],
['atomi.cloud/cluster', phyCluster.principal.slug],
],
});
}
},
]);
}
}
Expand Down
24 changes: 10 additions & 14 deletions src/init/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UtilPrompter } from "../lib/prompts/util-prompter.ts";
import { HttpUtil } from "../lib/utility/http-util.ts";
import { KubectlUtil } from "../lib/utility/kubectl-util.ts";
import { ServiceTreePrinter } from "../lib/utility/service-tree-printer.ts";
import { YamlManipulator } from "../lib/utility/yaml-manipulator.ts";
import { ServiceTreePrompter } from "../lib/prompts/landscape.ts";
import { CLOUD_TREE, LANDSCAPE_TREE } from "../lib/service-tree.ts";
import { TaskRunner } from "../tasks/tasks.ts";
import { Git } from "../lib/utility/git.ts";
import { UtilPrompter } from '../lib/prompts/util-prompter.ts';
import { HttpUtil } from '../lib/utility/http-util.ts';
import { KubectlUtil } from '../lib/utility/kubectl-util.ts';
import { ServiceTreePrinter } from '../lib/utility/service-tree-printer.ts';
import { YamlManipulator } from '../lib/utility/yaml-manipulator.ts';
import { ServiceTreePrompter } from '../lib/prompts/landscape.ts';
import { CLOUD_TREE, LANDSCAPE_TREE } from '../lib/service-tree.ts';
import { TaskRunner } from '../tasks/tasks.ts';
import { Git } from '../lib/utility/git.ts';

interface Dependencies {
httpUtil: HttpUtil;
Expand All @@ -25,11 +25,7 @@ const utilPrompter = new UtilPrompter();
const kubectl = new KubectlUtil(utilPrompter);
const serviceTreePrinter = new ServiceTreePrinter();
const yamlManipulator = new YamlManipulator();
const stp = new ServiceTreePrompter(
CLOUD_TREE,
LANDSCAPE_TREE.a,
LANDSCAPE_TREE.p,
);
const stp = new ServiceTreePrompter(CLOUD_TREE, LANDSCAPE_TREE.a, LANDSCAPE_TREE.p);
const taskRunner = new TaskRunner(utilPrompter);
const git = new Git();

Expand Down
Loading

0 comments on commit 9631250

Please sign in to comment.