forked from jenkinsci/azure-container-agents-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPodTemplateBuilder.java
More file actions
109 lines (100 loc) · 5.29 KB
/
Copy pathPodTemplateBuilder.java
File metadata and controls
109 lines (100 loc) · 5.29 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
package com.microsoft.jenkins.containeragents.builders;
import com.microsoft.jenkins.containeragents.PodTemplate;
import com.microsoft.jenkins.containeragents.remote.LaunchMethodTypeContent;
import com.microsoft.jenkins.containeragents.strategy.ContainerIdleRetentionStrategy;
import com.microsoft.jenkins.containeragents.util.Constants;
public class PodTemplateBuilder extends PodTemplateFluent<PodTemplateBuilder> {
private PodTemplateFluent<?> fluent;
public PodTemplateBuilder() {
this.fluent = this;
}
public PodTemplateBuilder(PodTemplate template) {
this.fluent = this;
this.fluent.withName(template.getName());
this.fluent.withDescription(template.getDescription());
this.fluent.withImage(template.getImage());
this.fluent.withCommand(template.getCommand());
this.fluent.withArgs(template.getArgs());
this.fluent.withLabel(template.getLabel());
this.fluent.withRootFs(template.getRootFs());
if (template.getRetentionStrategy() instanceof ContainerIdleRetentionStrategy) {
this.fluent.withIdleRetentionStrategy(((ContainerIdleRetentionStrategy) template.getRetentionStrategy())
.getIdleMinutes());
} else {
this.fluent.withOnceRetentionStrategy();
}
this.fluent.withPrivileged(template.getPrivileged());
this.fluent.withSpecifyNode(template.getSpecifyNode());
this.fluent.withRequestCpu(template.getRequestCpu());
this.fluent.withRequestMemory(template.getRequestMemory());
this.fluent.withLimitCpu(template.getLimitCpu());
this.fluent.withLimitMemory(template.getLimitMemory());
this.fluent.withEnvVars(template.getEnvVars());
this.fluent.withVolumes(template.getVolumes());
this.fluent.withImagePullSecrets(template.getImagePullSecrets());
this.fluent.withPrivateRegistryCredentials(template.getPrivateRegistryCredentials());
if (template.getLaunchMethodType().equals(Constants.LAUNCH_METHOD_JNLP)) {
this.fluent.withJNLPLaunchMethod();
} else {
this.fluent.withSSHLaunchMethod(template.getSshCredentialsId(), template.getSshPort());
}
}
public PodTemplateBuilder(PodTemplateFluent<?> fluent) {
this.fluent = fluent;
}
public PodTemplateBuilder(PodTemplateFluent<?> fluent, PodTemplate template) {
this.fluent = fluent;
this.fluent.withName(template.getName());
this.fluent.withDescription(template.getDescription());
this.fluent.withImage(template.getImage());
this.fluent.withCommand(template.getCommand());
this.fluent.withArgs(template.getArgs());
this.fluent.withLabel(template.getLabel());
this.fluent.withRootFs(template.getRootFs());
if (template.getRetentionStrategy() instanceof ContainerIdleRetentionStrategy) {
this.fluent.withIdleRetentionStrategy(((ContainerIdleRetentionStrategy) template.getRetentionStrategy())
.getIdleMinutes());
} else {
this.fluent.withOnceRetentionStrategy();
}
this.fluent.withPrivileged(template.getPrivileged());
this.fluent.withSpecifyNode(template.getSpecifyNode());
this.fluent.withRequestCpu(template.getRequestCpu());
this.fluent.withRequestMemory(template.getRequestMemory());
this.fluent.withLimitCpu(template.getLimitCpu());
this.fluent.withLimitMemory(template.getLimitMemory());
this.fluent.withEnvVars(template.getEnvVars());
this.fluent.withVolumes(template.getVolumes());
this.fluent.withImagePullSecrets(template.getImagePullSecrets());
this.fluent.withPrivateRegistryCredentials(template.getPrivateRegistryCredentials());
if (template.getLaunchMethodType().equals(Constants.LAUNCH_METHOD_JNLP)) {
this.fluent.withJNLPLaunchMethod();
} else {
this.fluent.withSSHLaunchMethod(template.getSshCredentialsId(), template.getSshPort());
}
}
public PodTemplate build() {
PodTemplate podTemplate = new PodTemplate();
podTemplate.setName(fluent.getName());
podTemplate.setLabel(fluent.getLabel());
podTemplate.setImage(fluent.getImage());
podTemplate.setImagePullSecrets(fluent.getImagePullSecrets());
podTemplate.setPrivateRegistryCredentials(fluent.getPrivateRegistryCredentials());
podTemplate.setCommand(fluent.getCommand());
podTemplate.setArgs(fluent.getArgs());
podTemplate.setRootFs(fluent.getRootFs());
podTemplate.setEnvVars(fluent.getEnvVars());
podTemplate.setVolumes(fluent.getVolumes());
podTemplate.setRetentionStrategy(fluent.getRetentionStrategy());
podTemplate.setSpecifyNode(fluent.getSpecifyNode());
podTemplate.setPrivileged(fluent.isPrivileged());
podTemplate.setRequestCpu(fluent.getRequestCpu());
podTemplate.setRequestMemory(fluent.getRequestMemory());
podTemplate.setLimitCpu(fluent.getLimitCpu());
podTemplate.setLimitMemory(fluent.getLimitMemory());
podTemplate.setLaunchMethodType(fluent.getLaunchMethodType());
podTemplate.setLaunchMethodTypeContent(new LaunchMethodTypeContent(fluent.getSshCredentialsId(),
fluent.getSshPort()));
return podTemplate;
}
}