-
Notifications
You must be signed in to change notification settings - Fork 48
/
setup.js
172 lines (158 loc) · 4.09 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import * as param from '@jkcfg/std/param'
import * as std from '@jkcfg/std'
const config = param.all();
let output = [];
const numNodes = config => config.controlPlane.nodes + config.workers.nodes;
const backend = {
docker: {
image: 'quay.io/footloose/centos7:0.6.0',
// The below is required for dockerd to run smoothly.
// See also: https://github.com/weaveworks/footloose#running-dockerd-in-container-machines
privileged: true,
volumes: [{
type: 'volume',
destination: '/var/lib/docker',
}]
},
ignite: {
image: 'chanwit/ignite-rhel7:latest', // 'chanwit/ignite-centos:7_pre2', // 'weaveworks/ignite-centos:firekube-pre3',
privileged: false,
volumes: [],
},
};
const image = config => backend[config.backend].image;
const privileged = config => backend[config.backend].privileged;
const volumes = (name, config) => {
let result = [Object.assign({}, backend[config.backend].volumes[0])];
result[0].source = name;
return result;
}
const footloose = config => ({
cluster: {
name: 'firekube',
privateKey: 'cluster-key',
},
machines: [{
count: 1,
spec: {
image: 'chanwit/minifk-master',
name: 'master-%d',
backend: config.backend,
ignite: {
cpus: 2,
memory: '4GB',
diskSize: '5GB',
kernel: 'chanwit/ignite-kernel:4.19.47',
},
portMappings: [{
containerPort: 22,
hostPort: 2222,
}, {
containerPort: 6443,
hostPort: 6443,
}, {
containerPort: 30443,
hostPort: 30443,
}, {
containerPort: 30080,
hostPort: 30080,
}],
privileged: privileged(config),
volumes: volumes('minifk-0', config),
},
},
{
count: 1,
spec: {
image: 'chanwit/minifk-worker',
name: 'worker-%d',
backend: config.backend,
ignite: {
cpus: 2,
memory: '4GB',
diskSize: '5GB',
kernel: 'chanwit/ignite-kernel:4.19.47',
},
portMappings: [{
containerPort: 22,
hostPort: 2222,
}, {
containerPort: 6443,
hostPort: 6443,
}, {
containerPort: 30443,
hostPort: 30443,
}, {
containerPort: 30080,
hostPort: 30080,
}],
privileged: privileged(config),
volumes: volumes('minifk-1', config),
},
}],
});
output.push({ path: 'footloose.yaml', value: footloose(config) });
// List is a Kubernetes list.
const List = items => ({
apiVersion: "v1",
kind: "List",
items
});
// Machine returns a WKS machine description from a configuration object describing its public IP, private IP, id, and its role.
const Machine = ({ id, privateIP, sshPort, role, kubeVersion }) => ({
apiVersion: 'cluster.k8s.io/v1alpha1',
kind: 'Machine',
metadata: {
labels: {
set: role,
},
name: `${role}-${id}`,
namespace: 'weavek8sops'
},
spec: {
versions: {
kubelet: `${kubeVersion}`,
controlPlane: `${kubeVersion}`
},
providerSpec: {
value: {
apiVersion: 'baremetalproviderspec/v1alpha1',
kind: 'BareMetalMachineProviderSpec',
public: {
address: '127.0.0.1',
port: sshPort,
},
private: {
address: privateIP,
port: 22,
}
}
}
}
});
const sshPort = machine => machine.ports.find(p => p.guest == 22).host;
if (config.machines !== undefined) {
const machines = [];
for (let i = 0; i < config.controlPlane.nodes; i++ ) {
const machine = config.machines[i];
machines.push(Machine({
id: i,
privateIP: machine.runtimeNetworks[0].ip,
sshPort: sshPort(machine),
role: 'master',
kubeVersion: config.version,
}));
}
for (let i = 0; i < config.workers.nodes; i++ ) {
const machine = config.machines[config.controlPlane.nodes + i];
machines.push(Machine({
id: i,
privateIP: machine.runtimeNetworks[0].ip,
sshPort: sshPort(machine),
role: 'worker',
kubeVersion: config.version,
}));
}
output.push({ path: 'machines.yaml', value: List(machines) });
}
export default output;