Skip to content

Commit 8b79bff

Browse files
committed
added tests of mixed privileged falgs in container
1 parent ec92b7f commit 8b79bff

File tree

2 files changed

+258
-5
lines changed
  • src/test
    • java/org/csanchez/jenkins/plugins/kubernetes
    • resources/org/csanchez/jenkins/plugins/kubernetes/KubernetesTest/mixedPrivivilegedPodTemplates

2 files changed

+258
-5
lines changed

src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public void upgradeFrom_1_15_9_invalid() {
123123
assertEquals("blah", template.getYaml());
124124
assertEquals(Collections.singletonList("blah"), template.getYamls());
125125
assertNull(template._getYamls());
126-
log.getMessages().stream().anyMatch(msg -> msg.contains("Found several persisted YAML fragments in pod template java"));
126+
log.getMessages().stream()
127+
.anyMatch(msg -> msg.contains("Found several persisted YAML fragments in pod template java"));
127128
}
128129

129130
@Test
@@ -183,7 +184,7 @@ public void upgradeFrom_0_12() throws Exception {
183184
public void upgradeFrom_0_10() throws Exception {
184185
List<PodTemplate> templates = cloud.getTemplates();
185186
PodTemplate template = templates.get(0);
186-
DescribableList<NodeProperty<?>,NodePropertyDescriptor> nodeProperties = template.getNodeProperties();
187+
DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = template.getNodeProperties();
187188
assertEquals(1, nodeProperties.size());
188189
ToolLocationNodeProperty property = (ToolLocationNodeProperty) nodeProperties.get(0);
189190
assertEquals(1, property.getLocations().size());
@@ -202,11 +203,24 @@ public void upgradeFrom_0_8() throws Exception {
202203
assertEquals(cloud.DEFAULT_WAIT_FOR_POD_SEC, cloud.getWaitForPodSec());
203204
}
204205

205-
private void assertPodTemplates(List<PodTemplate> templates) {
206-
assertEquals(1, templates.size());
206+
@Test
207+
@LocalData()
208+
@Issue("JENKINS-70287")
209+
public void mixedPrivivilegedPodTemplates() throws Exception {
210+
List<PodTemplate> templates = cloud.getTemplates();
211+
assertPodTemplates(templates, 2, 2);
212+
PodTemplate template = templates.get(0);
213+
assertEquals(true, template.getContainers().get(0).isPrivileged());
214+
assertEquals(false, template.getContainers().get(1).isPrivileged());
215+
assertEquals(Collections.emptyList(), template.getYamls());
216+
assertNull(template.getYaml());
217+
}
218+
219+
private void assertPodTemplates(List<PodTemplate> templates, Integer... numbers) {
220+
assertEquals(numbers.length > 0 ? numbers[0] : 1, templates.size());
207221
PodTemplate podTemplate = templates.get(0);
208222
assertEquals(Integer.MAX_VALUE, podTemplate.getInstanceCap());
209-
assertEquals(1, podTemplate.getContainers().size());
223+
assertEquals(numbers.length > 1 ? numbers[1] : 1, podTemplate.getContainers().size());
210224
ContainerTemplate containerTemplate = podTemplate.getContainers().get(0);
211225
assertEquals("jenkins/inbound-agent", containerTemplate.getImage());
212226
assertEquals("jnlp", containerTemplate.getName());
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
<?xml version='1.1' encoding='UTF-8'?>
2+
<hudson>
3+
<disabledAdministrativeMonitors/>
4+
<version>2.235.2</version>
5+
<installStateName>DEVELOPMENT</installStateName>
6+
<numExecutors>2</numExecutors>
7+
<mode>NORMAL</mode>
8+
<useSecurity>true</useSecurity>
9+
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/>
10+
<securityRealm class="hudson.security.SecurityRealm$None"/>
11+
<disableRememberMe>false</disableRememberMe>
12+
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
13+
<workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULLNAME}</workspaceDir>
14+
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
15+
<jdks/>
16+
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
17+
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
18+
<clouds>
19+
<org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud plugin="[email protected]">
20+
<name>kubernetes</name>
21+
<defaultsProviderTemplate>jnlp-base</defaultsProviderTemplate>
22+
<templates>
23+
<org.csanchez.jenkins.plugins.kubernetes.PodTemplate>
24+
<inheritFrom>jnlp-base</inheritFrom>
25+
<name>java</name>
26+
<privileged>false</privileged>
27+
<capOnlyOnAlivePods>false</capOnlyOnAlivePods>
28+
<alwaysPullImage>true</alwaysPullImage>
29+
<instanceCap>2147483647</instanceCap>
30+
<slaveConnectTimeout>100</slaveConnectTimeout>
31+
<idleMinutes>0</idleMinutes>
32+
<activeDeadlineSeconds>0</activeDeadlineSeconds>
33+
<label>java</label>
34+
<nodeSelector></nodeSelector>
35+
<nodeUsageMode>NORMAL</nodeUsageMode>
36+
<customWorkspaceVolumeEnabled>false</customWorkspaceVolumeEnabled>
37+
<workspaceVolume class="org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume">
38+
<memory>false</memory>
39+
</workspaceVolume>
40+
<volumes>
41+
<org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume>
42+
<mountPath>/mnt</mountPath>
43+
<memory>false</memory>
44+
</org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume>
45+
<org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume>
46+
<mountPath>/host</mountPath>
47+
<hostPath>/mnt/host</hostPath>
48+
</org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume>
49+
</volumes>
50+
<containers>
51+
<org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate>
52+
<name>jnlp</name>
53+
<image>jenkins/inbound-agent</image>
54+
<privileged>true</privileged>
55+
<alwaysPullImage>true</alwaysPullImage>
56+
<workingDir>/home/jenkins</workingDir>
57+
<command></command>
58+
<args>${computer.jnlpmac} ${computer.name}</args>
59+
<ttyEnabled>true</ttyEnabled>
60+
<resourceRequestCpu>500m</resourceRequestCpu>
61+
<resourceRequestMemory>250Mi</resourceRequestMemory>
62+
<resourceLimitCpu>500m</resourceLimitCpu>
63+
<resourceLimitMemory>250Mi</resourceLimitMemory>
64+
<envVars>
65+
<org.csanchez.jenkins.plugins.kubernetes.PodEnvVar>
66+
<key>a</key>
67+
<value>b</value>
68+
</org.csanchez.jenkins.plugins.kubernetes.PodEnvVar>
69+
<org.csanchez.jenkins.plugins.kubernetes.PodEnvVar>
70+
<key>c</key>
71+
<value>d</value>
72+
</org.csanchez.jenkins.plugins.kubernetes.PodEnvVar>
73+
</envVars>
74+
<ports/>
75+
<livenessProbe>
76+
<execArgs></execArgs>
77+
<timeoutSeconds>0</timeoutSeconds>
78+
<initialDelaySeconds>0</initialDelaySeconds>
79+
<failureThreshold>0</failureThreshold>
80+
<periodSeconds>0</periodSeconds>
81+
<successThreshold>0</successThreshold>
82+
</livenessProbe>
83+
</org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate>
84+
<org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate>
85+
<name>busybox</name>
86+
<image>busybox</image>
87+
<privileged>false</privileged>
88+
<runAsUser>600002</runAsUser>
89+
<runAsGroup>1000</runAsGroup>
90+
<alwaysPullImage>true</alwaysPullImage>
91+
<workingDir>/home/jenkins</workingDir>
92+
<command>cat</command>
93+
<args></args>
94+
<ttyEnabled>true</ttyEnabled>
95+
<resourceRequestCpu>500m</resourceRequestCpu>
96+
<resourceRequestMemory>250Mi</resourceRequestMemory>
97+
<resourceLimitCpu>500m</resourceLimitCpu>
98+
<resourceLimitMemory>250Mi</resourceLimitMemory>
99+
<envVars/>
100+
<ports/>
101+
<livenessProbe>
102+
<execArgs></execArgs>
103+
<timeoutSeconds>0</timeoutSeconds>
104+
<initialDelaySeconds>0</initialDelaySeconds>
105+
<failureThreshold>0</failureThreshold>
106+
<periodSeconds>0</periodSeconds>
107+
<successThreshold>0</successThreshold>
108+
</livenessProbe>
109+
</org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate>
110+
</containers>
111+
<envVars>
112+
<org.csanchez.jenkins.plugins.kubernetes.PodEnvVar>
113+
<key>a</key>
114+
<value>b</value>
115+
</org.csanchez.jenkins.plugins.kubernetes.PodEnvVar>
116+
<org.csanchez.jenkins.plugins.kubernetes.PodEnvVar>
117+
<key>c</key>
118+
<value>d</value>
119+
</org.csanchez.jenkins.plugins.kubernetes.PodEnvVar>
120+
</envVars>
121+
<annotations>
122+
<org.csanchez.jenkins.plugins.kubernetes.PodAnnotation>
123+
<key>aa</key>
124+
<value>bb</value>
125+
</org.csanchez.jenkins.plugins.kubernetes.PodAnnotation>
126+
</annotations>
127+
<imagePullSecrets>
128+
<org.csanchez.jenkins.plugins.kubernetes.PodImagePullSecret>
129+
<name></name>
130+
</org.csanchez.jenkins.plugins.kubernetes.PodImagePullSecret>
131+
</imagePullSecrets>
132+
<yamls>
133+
<string></string>
134+
</yamls>
135+
<podRetention class="org.csanchez.jenkins.plugins.kubernetes.pod.retention.Default"/>
136+
<yamlMergeStrategy class="org.csanchez.jenkins.plugins.kubernetes.pod.yaml.Overrides"/>
137+
<showRawYaml>true</showRawYaml>
138+
</org.csanchez.jenkins.plugins.kubernetes.PodTemplate>
139+
<org.csanchez.jenkins.plugins.kubernetes.PodTemplate>
140+
<name>jnlp-base</name>
141+
<privileged>false</privileged>
142+
<capOnlyOnAlivePods>false</capOnlyOnAlivePods>
143+
<alwaysPullImage>false</alwaysPullImage>
144+
<instanceCap>2147483647</instanceCap>
145+
<slaveConnectTimeout>100</slaveConnectTimeout>
146+
<idleMinutes>0</idleMinutes>
147+
<activeDeadlineSeconds>0</activeDeadlineSeconds>
148+
<label>jnlp-base</label>
149+
<hostNetwork>false</hostNetwork>
150+
<volumes>
151+
<org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume>
152+
<mountPath>/mnt</mountPath>
153+
<memory>false</memory>
154+
</org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume>
155+
<org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume>
156+
<mountPath>/host</mountPath>
157+
<hostPath>/mnt/host</hostPath>
158+
</org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume>
159+
</volumes>
160+
<containers>
161+
<org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate>
162+
<name>jnlp-base</name>
163+
<image>busybox</image>
164+
<privileged>true</privileged>
165+
<runAsUser>600002</runAsUser>
166+
<runAsGroup>1000</runAsGroup>
167+
<alwaysPullImage>true</alwaysPullImage>
168+
<workingDir>/home/jenkins</workingDir>
169+
<command>cat</command>
170+
<args></args>
171+
<ttyEnabled>true</ttyEnabled>
172+
<resourceRequestCpu>500m</resourceRequestCpu>
173+
<resourceRequestMemory>250Mi</resourceRequestMemory>
174+
<resourceLimitCpu>500m</resourceLimitCpu>
175+
<resourceLimitMemory>250Mi</resourceLimitMemory>
176+
<envVars/>
177+
<ports/>
178+
<livenessProbe>
179+
<execArgs></execArgs>
180+
<timeoutSeconds>0</timeoutSeconds>
181+
<initialDelaySeconds>0</initialDelaySeconds>
182+
<failureThreshold>0</failureThreshold>
183+
<periodSeconds>0</periodSeconds>
184+
<successThreshold>0</successThreshold>
185+
</livenessProbe>
186+
</org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate>
187+
</containers>
188+
<imagePullSecrets>
189+
<org.csanchez.jenkins.plugins.kubernetes.PodImagePullSecret>
190+
<name></name>
191+
</org.csanchez.jenkins.plugins.kubernetes.PodImagePullSecret>
192+
</imagePullSecrets>
193+
<podRetention class="org.csanchez.jenkins.plugins.kubernetes.pod.retention.Default"/>
194+
<yamlMergeStrategy class="org.csanchez.jenkins.plugins.kubernetes.pod.yaml.Merge"/>
195+
<showRawYaml>true</showRawYaml>
196+
</org.csanchez.jenkins.plugins.kubernetes.PodTemplate>
197+
</templates>
198+
<serverUrl>https://192.168.64.1</serverUrl>
199+
<skipTlsVerify>true</skipTlsVerify>
200+
<addMasterProxyEnvVars>false</addMasterProxyEnvVars>
201+
<capOnlyOnAlivePods>false</capOnlyOnAlivePods>
202+
<namespace>default</namespace>
203+
<containerCap>10</containerCap>
204+
<retentionTimeout>5</retentionTimeout>
205+
<connectTimeout>0</connectTimeout>
206+
<readTimeout>0</readTimeout>
207+
<labels class="linked-hash-map">
208+
<entry>
209+
<string>jenkins</string>
210+
<string>slave</string>
211+
</entry>
212+
<entry>
213+
<string>biff</string>
214+
<string>johnson</string>
215+
</entry>
216+
</labels>
217+
<usageRestricted>false</usageRestricted>
218+
<maxRequestsPerHost>32</maxRequestsPerHost>
219+
<waitForPodSec>600</waitForPodSec>
220+
<podRetention class="org.csanchez.jenkins.plugins.kubernetes.pod.retention.Never"/>
221+
</org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud>
222+
</clouds>
223+
<quietPeriod>5</quietPeriod>
224+
<scmCheckoutRetryCount>0</scmCheckoutRetryCount>
225+
<views>
226+
<hudson.model.AllView>
227+
<owner class="hudson" reference="../../.."/>
228+
<name>all</name>
229+
<filterExecutors>false</filterExecutors>
230+
<filterQueue>false</filterQueue>
231+
<properties class="hudson.model.View$PropertyList"/>
232+
</hudson.model.AllView>
233+
</views>
234+
<primaryView>all</primaryView>
235+
<slaveAgentPort>0</slaveAgentPort>
236+
<label></label>
237+
<nodeProperties/>
238+
<globalNodeProperties/>
239+
</hudson>

0 commit comments

Comments
 (0)