Skip to content

Commit

Permalink
Fix issue #282 - Last log without new line gets eaten on Windows node of
Browse files Browse the repository at this point in the history
Kubernetes executor
Fix issue #281 - Add support for windows 10 2004 and 20H2 in Kubernetes
executor
  • Loading branch information
robinshine committed May 9, 2021
1 parent e6cf9aa commit 64d2cc1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@
</repository>
</repositories>
<properties>
<commons.version>2.0.7</commons.version>
<k8shelper.version>2.1.0</k8shelper.version>
<commons.version>2.0.8</commons.version>
<k8shelper.version>2.1.1</k8shelper.version>
<slf4j.version>1.7.5</slf4j.version>
<logback.version>1.0.11</logback.version>
<antlr.version>4.7.2</antlr.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1376,8 +1376,10 @@ public void consume(String line) {
logger.debug(line);
} else if (logEndMessage != null && line.contains(logEndMessage)) {
endOfLogSeenRef.set(true);
String lastLogMessage = StringUtils.substringBefore(line, logEndMessage);
if (StringUtils.substringAfter(lastLogMessage, " ").length() != 0)
consume(lastLogMessage);
} else if (line.startsWith("Error from server") || line.startsWith("error:")) {
System.out.println(line);
jobLogger.log(line);
if (!abortError.get()) {
abortError.set(true);
Expand Down Expand Up @@ -1484,26 +1486,28 @@ public void setDockerImage(String dockerImage) {

private static class OsInfo {

private static final Map<String, Integer> WINDOWS_VERSIONS = new LinkedHashMap<>();
private static final Map<Integer, String> WINDOWS_VERSIONS = new LinkedHashMap<>();

static {
// update this according to
// https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility
WINDOWS_VERSIONS.put(".18363.", 1909);
WINDOWS_VERSIONS.put(".18362.", 1903);
WINDOWS_VERSIONS.put(".17763.", 1809);
WINDOWS_VERSIONS.put(".17134.", 1803);
WINDOWS_VERSIONS.put(".16299.", 1709);
WINDOWS_VERSIONS.put(".14393.", 1607);
WINDOWS_VERSIONS.put(14393, "1607");
WINDOWS_VERSIONS.put(16299, "1709");
WINDOWS_VERSIONS.put(17134, "1803");
WINDOWS_VERSIONS.put(17763, "1809");
WINDOWS_VERSIONS.put(18362, "1903");
WINDOWS_VERSIONS.put(18363, "1909");
WINDOWS_VERSIONS.put(19041, "2004");
WINDOWS_VERSIONS.put(19042, "20H2");
}

private final String osName;

private final String kernelVersion;
private final String osVersion;

public OsInfo(String osName, String kernelVersion) {
public OsInfo(String osName, String osVersion) {
this.osName = osName;
this.kernelVersion = kernelVersion;
this.osVersion = osVersion;
}

public boolean isLinux() {
Expand All @@ -1514,6 +1518,12 @@ public boolean isWindows() {
return osName.equalsIgnoreCase("windows");
}

public int getWindowsBuildNumber() {
Preconditions.checkState(isWindows());
List<String> fields = Splitter.on(".").splitToList(osVersion);
return Integer.parseInt(fields.get(fields.size()-2));
}

public String getCacheHome() {
if (osName.equalsIgnoreCase("linux"))
return "/var/cache/onedev-build";
Expand All @@ -1533,7 +1543,7 @@ public static OsInfo getBaseline(Collection<OsInfo> osInfos) {
for (OsInfo osInfo: osInfos) {
if (!osInfo.isWindows())
throw new ExplicitException("Windows and non-windows nodes should not be included in same executor");
if (baseline == null || baseline.getWindowsVersion() > osInfo.getWindowsVersion())
if (baseline == null || baseline.getWindowsBuildNumber() > osInfo.getWindowsBuildNumber())
baseline = osInfo;
}
return baseline;
Expand All @@ -1542,20 +1552,20 @@ public static OsInfo getBaseline(Collection<OsInfo> osInfos) {
}
}

public int getWindowsVersion() {
Preconditions.checkState(isWindows());
for (Map.Entry<String, Integer> entry: WINDOWS_VERSIONS.entrySet()) {
if (kernelVersion.contains(entry.getKey()))
return entry.getValue();
}
throw new ExplicitException("Unsupported windows kernel version: " + kernelVersion);
public String getWindowsVersion() {
int buildNumber = getWindowsBuildNumber();
String windowsVersion = WINDOWS_VERSIONS.get(buildNumber);
if (windowsVersion != null)
return windowsVersion;
else
throw new ExplicitException("Unsupported windows build number: " + buildNumber);
}

public String getHelperImageSuffix() {
if (isLinux())
return "linux";
else
return "windows-" + getWindowsVersion();
return "windows-" + getWindowsVersion().toLowerCase();
}

}
Expand Down

0 comments on commit 64d2cc1

Please sign in to comment.