-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestions.js
296 lines (296 loc) · 8.72 KB
/
questions.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
module.exports = {
generalQuestions: [
{
type: "input",
name: "name",
message: "Application name:",
validate: async (input) => {
if (input && input.replace(/\s|-|_|["']|\.|\//g, "").length >= 1) return true
else return "The name of the application cannot be empty"
},
filter: async (input) => input.toLowerCase().replace(/\s|_|["']|\.|\//g, "")
},
{
type: "input",
name: "description",
message: "Description:",
default: "A Helm chart for Kubernetes",
},
{
type: "input",
name: "keywords",
message: "Keywords (separated by commas):",
filter: async (input) => {
input = input.split(",").map(i=>i.replace(/\s/g, ""))
if (input.length > 0 && input[0] === "") return []
return input
}
},
{
type: "input",
name: "chartVersion",
message: "Chart version:",
default: "0.1.0",
validate: async (input) => {
let semVerPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
if (semVerPattern.test(input)) return true
else return "The chart version must follow the Semantic Versioning Specification"
}
},
{
type: "input",
name: "appVersion",
message: "App version:",
default: "0.1.0",
validate: async (input) => {
let semVerPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
if (semVerPattern.test(input)) return true
else return "The app version of the chart (actually the application version) must follow the Semantic Versioning Specification"
}
},
{
type: "number",
name: "components",
message: "Number of components:",
default: 1,
validate: async (input) => {
if (input >= 1) return true
else return "The number of components must be greater than zero"
}
},
{
type: "number",
name: "jobs",
message: "Number of Jobs:",
default: 0,
},
{
type: "number",
name: "cronjobs",
message: "Number of CronJobs:",
default: 0,
},
{
type: "number",
name: "dependencies",
message: "Number of dependencies:",
default: 0,
}
],
componentQuestions: [
{
type: "input",
name: "name",
message: "Component name:",
filter: async (input) => input.toLowerCase().replace(/\s|_|["']|\.|\//g, "")
},
{
type: "list",
name: "type",
message: "Component type",
choices: ["deployment", "statefulset", "daemonset"],
default: "deployment",
},
{
type: "input",
name: "imageRepo",
message: "Component image repository:",
validate: async (input) => {
if (input) return true
else return "The image repository cannot be empty"
}
},
{
type: "input",
name: "imageTag",
message: "Component image tag:",
filter: async (input) => (input.replace(/\s/g, "") === "\"\"") ? "" : input
},
{
type: "list",
name: "hasEnvVars",
message: "Does this component use environment variables?",
choices: ["yes", "no"],
default: "yes",
filter: async (input) => input === "yes"
},
// {
// type: "confirm",
// name: "hasEnvVars",
// message: "Does this component use environment variables?",
// default: true
// },
{
type: "list",
name: "hasService",
message: "Has this component a linked service?",
choices: ["yes", "no"],
default: "yes",
filter: async (input) => input === "yes"
},
{
type: "list",
name: "serviceType",
message: "Service type",
choices: ["NodePort", "ClusterIP", "LoadBalancer"],
default: "NodePort",
when: async (answers) => answers.hasService
},
{
type: "number",
name: "ports",
message: "Number of ports of the service",
default: 1,
validate: async (input) => {
if (input >= 1) return true
else return "The number of ports must be greater than zero"
},
when: async (answers) => answers.hasService
},
{
type: "list",
name: "hostNetwork",
message: "Does this Daemonset use the node's host network",
choices: ["yes", "no"],
default: "no",
filter: async (input) => input === "yes",
when: async (answers) => !answers.hasService && answers.type === "daemonset"
},
{
type: "list",
name: "dnsPolicy",
message: "DNS Policy",
choices: ["Default", "ClusterFirst", "ClusterFirstWithHostNet", "None"],
default: "Default",
when: async (answers) => answers.type === "daemonset"
},
],
servicePortsQuestions: [
{
type: "input",
name: "name",
message: "Port name:",
validate: async (input) => {
if (input.length >= 15) return "The port name can't have more than 15 characters"
else return true
},
filter: async (input) => input.toLowerCase().replace(/\s|_|["']|\.|\//g, "")
},
{
type: "list",
name: "protocol",
message: "Port protocol:",
choices: ["TCP", "UDP", "SCTP"],
default: "TCP"
},
{
type: "input",
name: "port",
message: "Service port number (this value will be used for the 'port' and 'targetPort' fields of the service template and for the 'containerPort' field of the component template",
default: 80,
validate: async (input) => {
if (!isNaN(input) && input >= 0 && input <= 65535) return true
else return "The port number must be a valid number (between 0 and 65353)"
}
}
],
jobQuestions: [
{
type: "input",
name: "name",
message: "Job name:",
filter: async (input) => input.toLowerCase().replace(/\s|_|["']|\.|\//g, "")
},
{
type: "input",
name: "imageRepo",
message: "Job image repository:",
validate: async (input) => {
if (input) return true
else return "The image repository cannot be empty"
}
},
{
type: "input",
name: "imageTag",
message: "Job image tag:",
filter: async (input) => (input.replace(/\s/g, "") === "\"\"") ? "" : input
},
{
type: "list",
name: "hasEnvVars",
message: "Does this Job use environment variables?",
choices: ["yes", "no"],
default: "yes",
filter: async (input) => input === "yes"
}
],
cronJobQuestions: [
{
type: "input",
name: "name",
message: "CronJob name:",
filter: async (input) => input.toLowerCase().replace(/\s|_|["']|\.|\//g, "")
},
{
type: "input",
name: "imageRepo",
message: "CronJob image repository:",
validate: async (input) => {
if (input) return true
else return "The image repository cannot be empty"
}
},
{
type: "input",
name: "imageTag",
message: "CronJob image tag:",
filter: async (input) => (input.replace(/\s/g, "") === "\"\"") ? "" : input.replace(/\s/g, "")
},
{
type: "list",
name: "hasEnvVars",
message: "Does this CronJob use environment variables?",
choices: ["yes", "no"],
default: "yes",
filter: async (input) => input === "yes"
},
{
type: "input",
name: "schedule",
message: "CronJob schedule config:",
default: "* * * * *",
}
],
dependencyQuestions: [
{
type: "input",
name: "name",
message: "Dependency name:",
validate: async (input) => {
if (input && input.replace(/\s|-|_|["']|\.|\//g, "").length >= 1) return true
else return "The name of the dependency cannot be empty"
},
filter: async (input) => input.toLowerCase().replace(/\s|_|["']|\.|\//g, "")
},
{
type: "input",
name: "version",
message: "Dependency version:",
validate: async (input) => {
let semVerPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)|x\.(0|[1-9]\d*)|x(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
if (input && semVerPattern.test(input)) return true
else return "The version of the dependency must follow the Semantic Versioning Specification"
}
},
{
type: "input",
name: "repository",
message: "Dependency repository:",
validate: async (input) => {
if (input) return true
else return "The repository of the dependency cannot be empty"
}
}
]
}