Skip to content

Commit

Permalink
fix: Improved example for k8s cluster and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondshtogu committed Aug 28, 2023
1 parent e109389 commit 969eb7e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 45 deletions.
30 changes: 0 additions & 30 deletions examples/08_k8s_cluster_with_talos_linux/nodejs/bootstrap.yaml

This file was deleted.

37 changes: 25 additions & 12 deletions examples/08_k8s_cluster_with_talos_linux/nodejs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {VirtualMachineFactory, VirtualMachineConfig} from './vmFactory';
import {VirtualMachine} from "@pulumiverse/esxi-native";
import {local} from "@pulumi/command";
import {interpolate} from "@pulumi/pulumi";

export = async () => {
const outputs = {
Expand Down Expand Up @@ -52,6 +53,16 @@ export = async () => {
]
}
},
{
op: "replace",
path: "/cluster/inlineManifests",
value: [
{
name: "talos-vmtoolsd-config",
contents: "apiVersion: v1\ndata:\n talosconfig: <TALOS_CONFIG>\nkind: Secret\nmetadata:\n name: talos-vmtoolsd-config\n namespace: kube-system\n"
}
]
},
{
op: "replace",
path: "/cluster/extraManifests",
Expand Down Expand Up @@ -93,20 +104,23 @@ export = async () => {
});

const controlPlaneConfig = new local.Command("control-plane-config", {
create: `cat controlplane.yaml`,
create: "config=$(cat controlplane.yaml) && echo ${config//<TALOS_CONFIG>/$(base64 talosconfig)}",
dir: process.cwd(),
}, {dependsOn: validateConfigs})
}, {dependsOn: talosConfig})

const workerConfig = new local.Command("worker-config", {
create: `cat worker.yaml`,
dir: process.cwd(),
}, {dependsOn: validateConfigs})

let vms: VirtualMachine[] = []
let cp: VirtualMachine
const factory = new VirtualMachineFactory(controlPlaneConfig.stdout, workerConfig.stdout)

vmConfigs.forEach(config => {
const vm = factory.make(config);
if (config.Type == "control-plane" && cp == null)
cp = vm
vms.push(vm)
outputs.nodes.push({
id: vm.id,
Expand All @@ -115,20 +129,19 @@ export = async () => {
})
})

const controlPlaneIp1 = "192.168.20.211";
const bootstrap = new local.Command("cluster-bootstrap", {
create: `talosctl --talosconfig talosconfig bootstrap -e ${controlPlaneIp1} -n ${controlPlaneIp1}`,
create: `talosctl --talosconfig talosconfig bootstrap -e ${cp.ipAddress} -n ${cp.ipAddress}`,
dir: process.cwd(),
}, {dependsOn: vms})

// const k8sConfig = new local.Command("cluster-bootstrap", {
// create: `talosctl --talosconfig talosconfig bootstrap -e ${controlPlaneIp} -n ${controlPlaneIp}`,
// dir: process.cwd(),
// }, {dependsOn: vms})
//
// Object.assign(outputs, outputs, {
// talosConfig: talosConfig.stdout,
// });
const k8sConfig = new local.Command("cluster-bootstrap", {
create: `talosctl --talosconfig talosconfig bootstrap -e ${controlPlaneIp} -n ${controlPlaneIp}`,
dir: process.cwd(),
}, {dependsOn: bootstrap})

Object.assign(outputs, outputs, {
k8sConfig: k8sConfig.stdout,
});

return outputs;
}
5 changes: 2 additions & 3 deletions examples/08_k8s_cluster_with_talos_linux/nodejs/vmFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ export class VirtualMachineFactory {
],
os: machineOs,
resourcePoolName: "/",
// in this case we will lower the startup timeout as the vm-tools are not yet
// up and running and the IP will not be fetched
startupTimeout: 5,
// in this case we will set the startup timeout to 300 as the vm-tools need to be configured, up and running, so the IP can be fetched
startupTimeout: 300,
shutdownTimeout: 5,
virtualDisks: disks,
virtualHWVer: 13
Expand Down

0 comments on commit 969eb7e

Please sign in to comment.