forked from jenkinsci/azure-container-agents-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPodTemplateFluent.java
More file actions
336 lines (256 loc) · 8.98 KB
/
Copy pathPodTemplateFluent.java
File metadata and controls
336 lines (256 loc) · 8.98 KB
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
package com.microsoft.jenkins.containeragents.builders;
import com.microsoft.jenkins.containeragents.PodEnvVar;
import com.microsoft.jenkins.containeragents.PodImagePullSecrets;
import com.microsoft.jenkins.containeragents.strategy.ContainerIdleRetentionStrategy;
import com.microsoft.jenkins.containeragents.strategy.ContainerOnceRetentionStrategy;
import com.microsoft.jenkins.containeragents.util.Constants;
import com.microsoft.jenkins.containeragents.volumes.AzureDiskVolume;
import com.microsoft.jenkins.containeragents.volumes.AzureFileVolume;
import com.microsoft.jenkins.containeragents.volumes.EmptyDirVolume;
import com.microsoft.jenkins.containeragents.volumes.HostPathVolume;
import com.microsoft.jenkins.containeragents.volumes.PersistentVolumeClaim;
import com.microsoft.jenkins.containeragents.volumes.PodVolume;
import com.microsoft.jenkins.containeragents.volumes.SecretVolume;
import hudson.slaves.RetentionStrategy;
import org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PodTemplateFluent<T extends PodTemplateFluent<T>> {
private String name;
private String description;
private String image;
private String command;
private String args;
private String label;
private String rootFs;
private RetentionStrategy<?> retentionStrategy;
private boolean privileged;
private String specifyNode;
private String requestCpu;
private String limitCpu;
private String requestMemory;
private String limitMemory;
private List<PodEnvVar> envVars = new ArrayList<>();
private List<PodVolume> volumes = new ArrayList<>();
private List<PodImagePullSecrets> imagePullSecrets = new ArrayList<>();
private List<DockerRegistryEndpoint> privateRegistryCredentials = new ArrayList<>();
private String launchMethodType;
private String sshCredentialsId;
private String sshPort;
public PodTemplateFluent() {
this.image = "jenkins/inbound-agent";
this.args = "-url ${rootUrl} ${secret} ${nodeName}";
this.rootFs = "/jenkins";
this.retentionStrategy = new ContainerOnceRetentionStrategy();
this.specifyNode = "";
this.launchMethodType = Constants.LAUNCH_METHOD_JNLP;
}
//CHECKSTYLE:OFF
public T withName(String name) {
this.name = name;
return (T) this;
}
public T withDescription(String description) {
this.description = description;
return (T) this;
}
public T withImage(String image) {
this.image = image;
return (T) this;
}
public T withCommand(String command) {
this.command = command;
return (T) this;
}
public T withArgs(String args) {
this.args = args;
return (T) this;
}
public T withLabel(String label) {
this.label = label;
return (T) this;
}
public T withRootFs(String rootFs) {
this.rootFs = rootFs;
return (T) this;
}
public T withOnceRetentionStrategy() {
this.retentionStrategy = new ContainerOnceRetentionStrategy();
return (T) this;
}
public T withIdleRetentionStrategy(int idle) {
this.retentionStrategy = new ContainerIdleRetentionStrategy(idle);
return (T) this;
}
public T withPrivileged(boolean privileged) {
this.privileged = privileged;
return (T) this;
}
public T withSpecifyNode(String specifyNode) {
this.specifyNode = specifyNode;
return (T) this;
}
public T withRequestCpu(String requestCpu) {
this.requestCpu = requestCpu;
return (T) this;
}
public T withLimitCpu(String limitCpu) {
this.limitCpu = limitCpu;
return (T) this;
}
public T withRequestMemory(String requestMemory) {
this.requestMemory = requestMemory;
return (T) this;
}
public T withLimitMemory(String limitMemory) {
this.limitMemory = limitMemory;
return (T) this;
}
public T withEnvVars(List<PodEnvVar> envVars) {
this.envVars.clear();
this.envVars.addAll(envVars);
return (T) this;
}
public T addToEnvVars(PodEnvVar... envVars) {
this.envVars.addAll(Arrays.asList(envVars));
return (T) this;
}
public T addNewEnvVar(String key, String value) {
this.envVars.add(new PodEnvVar(key, value));
return (T) this;
}
public T withVolumes(List<PodVolume> volumes) {
this.volumes.clear();
this.volumes.addAll(volumes);
return (T) this;
}
public T addToVolumes(PodVolume... volumes) {
this.volumes.addAll(Arrays.asList(volumes));
return (T) this;
}
public T addNewAzureDiskVolume(String mountPath, String diskName, String diskUrl) {
this.volumes.add(new AzureDiskVolume(mountPath, diskName, diskUrl));
return (T) this;
}
public T addNewAzureFileVolume(String mountPath, String secretName, String shareName, boolean readOnly) {
this.volumes.add(new AzureFileVolume(mountPath, secretName, shareName, readOnly));
return (T) this;
}
public T addNewEmptyVolume(String mountPath, boolean inMemory) {
this.volumes.add(new EmptyDirVolume(mountPath, inMemory));
return (T) this;
}
public T addNewHostPathVolume(String mountPath, String hostPath) {
this.volumes.add(new HostPathVolume(mountPath, hostPath));
return (T) this;
}
public T addNewPersistentVolumeClaim(String mountPath, String claimName, boolean readOnly) {
this.volumes.add(new PersistentVolumeClaim(mountPath, claimName, readOnly));
return (T) this;
}
public T addNewSecretVolume(String mountPath, String secretName) {
this.volumes.add(new SecretVolume(mountPath, secretName));
return (T) this;
}
public T withImagePullSecrets(List<PodImagePullSecrets> imagePullSecrets) {
this.imagePullSecrets.clear();
this.imagePullSecrets.addAll(imagePullSecrets);
return (T) this;
}
public T addToImagePullSecrets(PodImagePullSecrets... imagePullSecrets) {
this.imagePullSecrets.addAll(Arrays.asList(imagePullSecrets));
return (T) this;
}
public T addNewImagePullSecret(String secretName) {
this.imagePullSecrets.add(new PodImagePullSecrets(secretName));
return (T) this;
}
public T withPrivateRegistryCredentials(List<DockerRegistryEndpoint> privateRegistryCredentials) {
this.privateRegistryCredentials.clear();
this.privateRegistryCredentials.addAll(privateRegistryCredentials);
return (T) this;
}
public T addToPrivateRegistryCredentials(DockerRegistryEndpoint... privateRegistryCredentials) {
this.privateRegistryCredentials.addAll(Arrays.asList(privateRegistryCredentials));
return (T) this;
}
public T addNewPrivateRegistryCredential(String registryUrl, String credentialsId) {
this.privateRegistryCredentials.add(new DockerRegistryEndpoint(registryUrl, credentialsId));
return (T) this;
}
public T withJNLPLaunchMethod() {
this.launchMethodType = Constants.LAUNCH_METHOD_JNLP;
return (T) this;
}
public T withSSHLaunchMethod(String sshCredentialsId, String sshPort) {
this.launchMethodType = Constants.LAUNCH_METHOD_SSH;
this.sshCredentialsId = sshCredentialsId;
this.sshPort = sshPort;
return (T) this;
}
//CHECKSTYLE:ON
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getImage() {
return image;
}
public String getCommand() {
return command;
}
public String getArgs() {
return args;
}
public String getLabel() {
return label;
}
public String getRootFs() {
return rootFs;
}
public RetentionStrategy<?> getRetentionStrategy() {
return retentionStrategy;
}
public boolean isPrivileged() {
return privileged;
}
public String getSpecifyNode() {
return specifyNode;
}
public String getRequestCpu() {
return requestCpu;
}
public String getLimitCpu() {
return limitCpu;
}
public String getRequestMemory() {
return requestMemory;
}
public String getLimitMemory() {
return limitMemory;
}
public List<PodEnvVar> getEnvVars() {
return envVars;
}
public List<PodVolume> getVolumes() {
return volumes;
}
public List<PodImagePullSecrets> getImagePullSecrets() {
return imagePullSecrets;
}
public List<DockerRegistryEndpoint> getPrivateRegistryCredentials() {
return privateRegistryCredentials;
}
public String getLaunchMethodType() {
return launchMethodType;
}
public String getSshCredentialsId() {
return sshCredentialsId;
}
public String getSshPort() {
return sshPort;
}
}