Skip to content

Commit a38c8a6

Browse files
committed
Make assumeWindows/isWindows build specific
1 parent 4e3d70a commit a38c8a6

File tree

10 files changed

+29
-16
lines changed

10 files changed

+29
-16
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static java.util.logging.Level.*;
2727
import static org.junit.Assume.*;
2828

29+
import edu.umd.cs.findbugs.annotations.CheckForNull;
2930
import java.io.IOException;
3031
import java.util.Collections;
3132
import java.util.HashMap;
@@ -81,6 +82,8 @@ public class KubernetesTestUtil {
8182
public static final String CONTAINER_ENV_VAR_FROM_SECRET_VALUE = "container-pa55w0rd";
8283
public static final String POD_ENV_VAR_FROM_SECRET_VALUE = "pod-pa55w0rd";
8384

85+
public static final String WINDOWS_1809_BUILD = "10.0.17763";
86+
8487
public static KubernetesCloud setupCloud(Object test, TestName name) throws KubernetesAuthException, IOException {
8588
KubernetesCloud cloud = new KubernetesCloud("kubernetes");
8689
// unique labels per test
@@ -150,17 +153,21 @@ public static void assumeKubernetes() throws Exception {
150153
* This means that we can run tests involving Windows agent pods.
151154
* Note that running the <em>controller</em> on Windows is untested.
152155
*/
153-
public static void assumeWindows() {
154-
assumeTrue("Cluster seems to contain no Windows nodes", isWindows());
156+
public static void assumeWindows(String buildNumber) {
157+
assumeTrue("Cluster seems to contain no Windows nodes with build " + buildNumber, isWindows(buildNumber));
155158
}
156159

157-
public static boolean isWindows() {
160+
public static boolean isWindows(@CheckForNull String buildNumber) {
158161
try (KubernetesClient client = new DefaultKubernetesClient(new ConfigBuilder(Config.autoConfigure(null)).build())) {
159162
for (Node n : client.nodes().list().getItems()) {
160-
String os = n.getMetadata().getLabels().get("kubernetes.io/os");
161-
LOGGER.info(() -> "Found node " + n.getMetadata().getName() + " running OS " + os);
163+
Map<String, String> labels = n.getMetadata().getLabels();
164+
String os = labels.get("kubernetes.io/os");
165+
String windowsBuild = labels.get("node.kubernetes.io/windows-build");
166+
LOGGER.info(() -> "Found node " + n.getMetadata().getName() + " running OS " + os + " with Windows build " + windowsBuild);
162167
if ("windows".equals(os)) {
163-
return true;
168+
if (buildNumber == null || buildNumber.equals(windowsBuild)) {
169+
return true;
170+
}
164171
}
165172
}
166173
}

src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorWindowsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.io.ByteArrayOutputStream;
3838
import java.io.OutputStream;
3939
import java.nio.charset.StandardCharsets;
40-
import java.util.Collections;
4140
import java.util.HashMap;
4241
import java.util.Map;
4342
import java.util.Optional;
@@ -79,6 +78,7 @@
7978
* @author Carlos Sanchez
8079
*/
8180
public class ContainerExecDecoratorWindowsTest {
81+
public static final String WINDOWS_BUILD = "10.0.17763";
8282
@Rule
8383
public ExpectedException exception = ExpectedException.none();
8484

@@ -104,7 +104,7 @@ public class ContainerExecDecoratorWindowsTest {
104104
@BeforeClass
105105
public static void setUpClass() throws Exception {
106106
assumeKubernetes();
107-
assumeWindows();
107+
assumeWindows(WINDOWS_BUILD);
108108
}
109109

110110
@Before
@@ -113,7 +113,7 @@ public void configureCloud() throws Exception {
113113
client = cloud.connect();
114114
deletePods(client, getLabels(this, name), false);
115115

116-
String image = "mcr.microsoft.com/windows:10.0.17763.2686";
116+
String image = "mcr.microsoft.com/windows:" + WINDOWS_BUILD + ".2686";
117117
String containerName = "container";
118118
String podName = "test-command-execution-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789");
119119
pod = client.pods().create(new PodBuilder()
@@ -129,7 +129,7 @@ public void configureCloud() throws Exception {
129129
.withArgs("Start-Sleep", "2147483")
130130
.build())
131131
.addToNodeSelector("kubernetes.io/os", "windows")
132-
.addToNodeSelector("node.kubernetes.io/windows-build", "10.0.17763")
132+
.addToNodeSelector("node.kubernetes.io/windows-build", WINDOWS_BUILD)
133133
.withTerminationGracePeriodSeconds(0L)
134134
.endSpec().build());
135135

src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.CONTAINER_ENV_VAR_FROM_SECRET_VALUE;
2828
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.POD_ENV_VAR_FROM_SECRET_VALUE;
29+
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.WINDOWS_1809_BUILD;
2930
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.assumeWindows;
3031
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.deletePods;
3132
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.getLabels;
@@ -632,7 +633,7 @@ public void runInDynamicallyCreatedContainer() throws Exception {
632633
@Issue("JENKINS-57256")
633634
@Test
634635
public void basicWindows() throws Exception {
635-
assumeWindows();
636+
assumeWindows(WINDOWS_1809_BUILD);
636637
cloud.setDirectConnection(false); // not yet supported by https://github.com/jenkinsci/docker-inbound-agent/blob/517ccd68fd1ce420e7526ca6a40320c9a47a2c18/jenkins-agent.ps1
637638
r.assertBuildStatusSuccess(r.waitForCompletion(b));
638639
r.assertLogContains("Directory of C:\\home\\jenkins\\agent\\workspace\\basic Windows", b); // bat
@@ -642,7 +643,7 @@ public void basicWindows() throws Exception {
642643
@Issue("JENKINS-53500")
643644
@Test
644645
public void windowsContainer() throws Exception {
645-
assumeWindows();
646+
assumeWindows(WINDOWS_1809_BUILD);
646647
cloud.setDirectConnection(false);
647648
r.assertBuildStatusSuccess(r.waitForCompletion(b));
648649
r.assertLogContains("Directory of C:\\home\\jenkins\\agent\\workspace\\windows Container\\subdir", b);
@@ -653,7 +654,7 @@ public void windowsContainer() throws Exception {
653654
@Ignore("TODO aborts, but with “kill finished with exit code 9009” and “After 20s process did not stop” and no graceful shutdown")
654655
@Test
655656
public void interruptedPodWindows() throws Exception {
656-
assumeWindows();
657+
assumeWindows(WINDOWS_1809_BUILD);
657658
cloud.setDirectConnection(false);
658659
r.waitForMessage("starting to sleep", b);
659660
b.getExecutor().interrupt();
@@ -663,7 +664,7 @@ public void interruptedPodWindows() throws Exception {
663664

664665
@Test
665666
public void secretMaskingWindows() throws Exception {
666-
assumeWindows();
667+
assumeWindows(WINDOWS_1809_BUILD);
667668
cloud.setDirectConnection(false);
668669
r.assertBuildStatusSuccess(r.waitForCompletion(b));
669670
r.assertLogContains("INSIDE_POD_ENV_VAR_FROM_SECRET = **** or " + POD_ENV_VAR_FROM_SECRET_VALUE.toUpperCase(Locale.ROOT), b);

src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesSamplesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class KubernetesSamplesTest extends AbstractKubernetesPipelineTest {
4141

4242
@Test public void smokes() throws Exception {
4343
for (GroovySample gs : ExtensionList.lookup(GroovySample.class)) {
44-
if (gs.name().equals("kubernetes-windows") && !isWindows()) {
44+
if (gs.name().equals("kubernetes-windows") && !isWindows(null)) {
4545
System.err.println("==== Skipping " + gs.title() + " ====");
4646
continue;
4747
}

src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/RestartPipelineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void runInPodWithRestartWithLongSleep() throws Exception {
217217

218218
@Test
219219
public void windowsRestart() throws Exception {
220-
assumeWindows();
220+
assumeWindows(WINDOWS_1809_BUILD);
221221
AtomicReference<String> projectName = new AtomicReference<>();
222222
story.then(r -> {
223223
configureAgentListener();

src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/basicWindows.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ spec:
77
image: jenkins/inbound-agent:windowsservercore-1809
88
nodeSelector:
99
kubernetes.io/os: windows
10+
node.kubernetes.io/windows-build: 10.0.17763
1011
'''
1112
) {
1213
node(POD_LABEL) {

src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/interruptedPodWindows.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spec:
1414
- 999999
1515
nodeSelector:
1616
kubernetes.io/os: windows
17+
node.kubernetes.io/windows-build: 10.0.17763
1718
''') {
1819
node(POD_LABEL) {
1920
container('shell') {

src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/secretMaskingWindows.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spec:
2626
name: container-secret
2727
nodeSelector:
2828
kubernetes.io/os: windows
29+
node.kubernetes.io/windows-build: 10.0.17763
2930
''') {
3031
node(POD_LABEL) {
3132
powershell 'echo "INSIDE_POD_ENV_VAR_FROM_SECRET = $Env:POD_ENV_VAR_FROM_SECRET or $($Env:POD_ENV_VAR_FROM_SECRET.ToUpper())"'

src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/windowsContainer.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spec:
1414
- 999999
1515
nodeSelector:
1616
kubernetes.io/os: windows
17+
node.kubernetes.io/windows-build: 10.0.17763
1718
'''
1819
) {
1920
node(POD_LABEL) {

src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/windowsRestart.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spec:
1414
- 999999
1515
nodeSelector:
1616
kubernetes.io/os: windows
17+
node.kubernetes.io/windows-build: 10.0.17763
1718
''') {
1819
node(POD_LABEL) {
1920
container('shell') {

0 commit comments

Comments
 (0)