-
Notifications
You must be signed in to change notification settings - Fork 15
/
helm.js
158 lines (136 loc) · 5.21 KB
/
helm.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
const commandBuilder = require('./commandBuilder');
const helperMethods = require('./helperMethods');
const Executer = require('./Executer');
module.exports = class Helm {
constructor(config) {
this.config = config;
this.executer = new Executer(config.helmCommand, config.output);
}
command(commandString, done){
this.executer.callByCommand(commandString, callbackHandler(done, false));
}
executeCommandByArguments(options, command, done) {
commandBuilder.addParentOptions(options, command);
this.executer.callByArguments(command, callbackHandler(done, false));
}
install(options, done) {
let command = ['install'];
if(options.chartName == null){
throw new Error("Missing required parameter 'chartName'");
}
command.push(options.chartName);
if (options.releaseName == null) {
throw new Error("Missing required parameters 'releaseName'");
}
command.push('--name');
command.push(options.releaseName);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
if(options.version){
command.push('--version');
command.push(options.version);
}
if (options.values) {
command.push('--set');
command.push(helperMethods.flattenValuesToString(options.values));
}
this.executeCommandByArguments(options, command, done);
}
upgrade(options, done) {
let command = ['upgrade', options.releaseName];
if (options.chartName == null) {
throw new Error ("Missing parameter 'chartName'");
}
command.push(options.chartName);
if(options.version){
command.push('--version');
command.push(options.version);
}
if (options.values) {
command.push('--set');
var valuesString = helperMethods.flattenValuesToString(options.values);
valuesString = valuesString.slice(0, -1);
command.push(valuesString);
}
if (options.reuseValues) {
command.push('--reuse-values');
}
this.executeCommandByArguments(options, command, done);
}
delete(options, done) {
let command = ['delete'];
if(options.releaseName == null){
throw new Error("Missing parameter 'releaseName'");
}
if(options.shouldPurge){
command.push('--purge');
}
command.push(options.releaseName);
this.executeCommandByArguments(options, command, done);
}
list(options, done){
let command = ['list'];
this.executeCommandByArguments(options, command, done);
}
get(options, done){
let command = ['get'];
if(options.releaseName == null){
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
this.executeCommandByArguments(options, command, done);
}
history(options, done){
let command = ['history'];
if(options.releaseName == null){
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
this.executeCommandByArguments(options, command, done);
}
test(options, done){
let command = ['test'];
if(options.releaseName == null){
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
this.executeCommandByArguments(options, command, done);
}
status(options, done){
let command = ['status'];
if(options.releaseName == null){
throw new Error("Missing parameter 'releaseName'");
}
if (options.outputFormat){
command.push('--output')
command.push(options.outputFormat)
}
command.push(options.releaseName);
this.executeCommandByArguments(options, command, done);
}
rollback(options, done){
let command = ['rollback'];
if(options.releaseName == null){
throw new Error("Missing parameter 'releaseName'");
}
if(options.revision == null){
throw new Error("Missing parameter 'revision'");
}
command.push(options.releaseName);
command.push(options.revision);
this.executeCommandByArguments(options, command, done);
}
};
function callbackHandler(done, isJsonSupportedCommand) {
return function (err, data) {
if (err) {
console.error(err);
done(err, data);
}
else {
done(null, isJsonSupportedCommand ? data : helperMethods.parseResponseToJson(data));
}
};
}