Skip to content

The Unified and Autonomous Development Platform

Able to run build on Windows node of a Kubernetes cluster

Robin Shen5abc2a4acf26
diff --git a/pom.xml b/pom.xml
index 0e647cea66..5941e12d13 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,201 +1,201 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>io.onedev</groupId>
- <artifactId>parent</artifactId>
- <version>1.0.3</version>
- </parent>
- <artifactId>server</artifactId>
- <version>3.0.1</version>
- <packaging>pom</packaging>
- <build>
- <finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-maven-plugin</artifactId>
- <version>${antlr.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>antlr4</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
- <listener>true</listener>
- <visitor>true</visitor>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>io.onedev</groupId>
- <artifactId>plugin-maven</artifactId>
- <versionRange>[2.0.0,]</versionRange>
- <goals>
- <goal>populate-resources</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <execute>
- <runOnIncremental>true</runOnIncremental>
- <runOnConfiguration>true</runOnConfiguration>
- </execute>
- </action>
- </pluginExecution>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.codehaus.gmaven</groupId>
- <artifactId>groovy-maven-plugin</artifactId>
- <versionRange>[2.0,]</versionRange>
- <goals>
- <goal>execute</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <execute>
- <runOnIncremental>true</runOnIncremental>
- <runOnConfiguration>true</runOnConfiguration>
- </execute>
- </action>
- </pluginExecution>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <versionRange>[1.0.0,]</versionRange>
- <goals>
- <goal>jar</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore/>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-jar-plugin</artifactId>
- <version>3.0.2</version>
- <executions>
- <execution>
- <id>default-jar</id>
- <phase>never</phase>
- <configuration>
- <finalName>unwanted</finalName>
- <classifier>unwanted</classifier>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>io.onedev</groupId>
- <artifactId>plugin-maven</artifactId>
- <version>2.0.1</version>
- <executions>
- <execution>
- <id>populate-resources</id>
- <phase>compile</phase>
- <goals>
- <goal>populate-resources</goal>
- </goals>
- </execution>
- <execution>
- <id>package-artifacts</id>
- <phase>package</phase>
- <goals>
- <goal>package-artifacts</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- <resources>
- <resource>
- <directory>src/main/java</directory>
- <excludes>
- <exclude>**/*.java</exclude>
- </excludes>
- </resource>
- <resource>
- <directory>src/main/resources</directory>
- </resource>
- <resource>
- <directory>target/generated-sources/antlr4</directory>
- <includes>
- <include>*.tokens</include>
- </includes>
- </resource>
- </resources>
- </build>
- <modules>
- <module>server-core</module>
- <module>server-plugin</module>
- <module>server-product</module>
- </modules>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>io.onedev</groupId>
- <artifactId>commons-launcher-loader</artifactId>
- <version>${commons.version}</version>
- </dependency>
- <dependency>
- <groupId>io.onedev</groupId>
- <artifactId>commons-launcher-loader</artifactId>
- <type>test-jar</type>
- <version>${commons.version}</version>
- </dependency>
- <dependency>
- <groupId>io.onedev</groupId>
- <artifactId>commons-codeassist</artifactId>
- <version>${commons.version}</version>
- </dependency>
- <dependency>
- <groupId>io.onedev</groupId>
- <artifactId>commons-jsymbol</artifactId>
- <version>${commons.version}</version>
- </dependency>
- <dependency>
- <groupId>io.onedev</groupId>
- <artifactId>commons-jsyntax</artifactId>
- <version>${commons.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <repositories>
- <repository>
- <id>pmeaseRepo</id>
- <url>http://artifact.pmease.com/artifactory/pmeaseRepo</url>
- <releases>
- <enabled>true</enabled>
- <updatePolicy>never</updatePolicy>
- <checksumPolicy>fail</checksumPolicy>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- <updatePolicy>always</updatePolicy>
- <checksumPolicy>fail</checksumPolicy>
- </snapshots>
- </repository>
- </repositories>
- <properties>
- <commons.version>1.1.8</commons.version>
- <antlr.version>4.7.2</antlr.version>
- </properties>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>io.onedev</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0.3</version>
+ </parent>
+ <artifactId>server</artifactId>
+ <version>3.0.1</version>
+ <packaging>pom</packaging>
+ <build>
+ <finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-maven-plugin</artifactId>
+ <version>${antlr.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>antlr4</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
+ <listener>true</listener>
+ <visitor>true</visitor>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>io.onedev</groupId>
+ <artifactId>plugin-maven</artifactId>
+ <versionRange>[2.0.0,]</versionRange>
+ <goals>
+ <goal>populate-resources</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <execute>
+ <runOnIncremental>true</runOnIncremental>
+ <runOnConfiguration>true</runOnConfiguration>
+ </execute>
+ </action>
+ </pluginExecution>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.codehaus.gmaven</groupId>
+ <artifactId>groovy-maven-plugin</artifactId>
+ <versionRange>[2.0,]</versionRange>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <execute>
+ <runOnIncremental>true</runOnIncremental>
+ <runOnConfiguration>true</runOnConfiguration>
+ </execute>
+ </action>
+ </pluginExecution>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <versionRange>[1.0.0,]</versionRange>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore/>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ <executions>
+ <execution>
+ <id>default-jar</id>
+ <phase>never</phase>
+ <configuration>
+ <finalName>unwanted</finalName>
+ <classifier>unwanted</classifier>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>io.onedev</groupId>
+ <artifactId>plugin-maven</artifactId>
+ <version>2.0.1</version>
+ <executions>
+ <execution>
+ <id>populate-resources</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>populate-resources</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>package-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>package-artifacts</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ <resource>
+ <directory>target/generated-sources/antlr4</directory>
+ <includes>
+ <include>*.tokens</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+ <modules>
+ <module>server-core</module>
+ <module>server-plugin</module>
+ <module>server-product</module>
+ </modules>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>io.onedev</groupId>
+ <artifactId>commons-launcher-loader</artifactId>
+ <version>${commons.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.onedev</groupId>
+ <artifactId>commons-launcher-loader</artifactId>
+ <type>test-jar</type>
+ <version>${commons.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.onedev</groupId>
+ <artifactId>commons-codeassist</artifactId>
+ <version>${commons.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.onedev</groupId>
+ <artifactId>commons-jsymbol</artifactId>
+ <version>${commons.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.onedev</groupId>
+ <artifactId>commons-jsyntax</artifactId>
+ <version>${commons.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <repositories>
+ <repository>
+ <id>pmeaseRepo</id>
+ <url>http://artifact.pmease.com/artifactory/pmeaseRepo</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ <checksumPolicy>fail</checksumPolicy>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>always</updatePolicy>
+ <checksumPolicy>fail</checksumPolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+ <properties>
+ <commons.version>1.1.9</commons.version>
+ <antlr.version>4.7.2</antlr.version>
+ </properties>
+</project>
diff --git a/server-core/pom.xml b/server-core/pom.xml
index 8685842e9c..d046166d9b 100644
--- a/server-core/pom.xml
+++ b/server-core/pom.xml
@@ -393,7 +393,7 @@
<dependency>
<groupId>io.onedev</groupId>
<artifactId>k8s-helper</artifactId>
- <version>1.0.6</version>
+ <version>1.0.7</version>
</dependency>
</dependencies>
<properties>
@@ -410,4 +410,4 @@
<jetty.version>9.3.27.v20190418</jetty.version>
<servlet.version>3.1.0</servlet.version>
</properties>
-</project>
\ No newline at end of file
+</project>
diff --git a/server-core/src/main/java/io/onedev/server/web/component/taskbutton/TaskButton.java b/server-core/src/main/java/io/onedev/server/web/component/taskbutton/TaskButton.java
index 39235b2551..454d458692 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/taskbutton/TaskButton.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/taskbutton/TaskButton.java
@@ -90,7 +90,7 @@ public abstract class TaskButton extends AjaxButton {
})));
} catch (Exception e) {
- logger.debug("Error " + title, e);
+ logger.error("Error " + title, e);
String suggestedSolution = ExceptionUtils.suggestSolution(e);
if (suggestedSolution != null)
logger.warn("!!! " + suggestedSolution);
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/editable.css b/server-core/src/main/java/io/onedev/server/web/editable/editable.css
index 6949ca285e..e1fe57ae51 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/editable.css
+++ b/server-core/src/main/java/io/onedev/server/web/editable/editable.css
@@ -14,7 +14,6 @@
background: #F5F5F5;
padding: 4px 8px;
margin-bottom: 12px;
- text-align: right;
border-radius: 4px;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/admin/jobexecutor/JobExecutorPage.java b/server-core/src/main/java/io/onedev/server/web/page/admin/jobexecutor/JobExecutorPage.java
index 7f8798458b..c579e378ae 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/admin/jobexecutor/JobExecutorPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/admin/jobexecutor/JobExecutorPage.java
@@ -84,7 +84,7 @@ public class JobExecutorPage extends AdministrationPage {
target.add(container);
}
- }.items("li.executor"));
+ }.items("li.executor").handle(".panel-heading"));
container.add(newAddNewFrag());
}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/base/base.css b/server-core/src/main/java/io/onedev/server/web/page/base/base.css
index c328ccf8bb..50993a6ae7 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/base/base.css
+++ b/server-core/src/main/java/io/onedev/server/web/page/base/base.css
@@ -643,6 +643,7 @@ td.ellipsis {
border-color: #ADADAD;
}
-.panel-list .disabled .panel {
+.panel-list .disabled .panel, .panel-list .disabled .panel span, .panel-list .disabled .panel a {
color: #999;
}
+
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/setting/branchprotection/BranchProtectionPage.java b/server-core/src/main/java/io/onedev/server/web/page/project/setting/branchprotection/BranchProtectionPage.java
index 4af7d2d3dc..8faeeac999 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/setting/branchprotection/BranchProtectionPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/setting/branchprotection/BranchProtectionPage.java
@@ -77,7 +77,7 @@ public class BranchProtectionPage extends ProjectSettingPage {
target.add(container);
}
- }.items("li.protection"));
+ }.items("li.protection").handle(".panel-heading"));
container.add(newAddNewFrag());
}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/setting/tagprotection/TagProtectionPage.java b/server-core/src/main/java/io/onedev/server/web/page/project/setting/tagprotection/TagProtectionPage.java
index d0bfdc5a3c..2e6be54059 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/setting/tagprotection/TagProtectionPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/setting/tagprotection/TagProtectionPage.java
@@ -77,7 +77,7 @@ public class TagProtectionPage extends ProjectSettingPage {
target.add(container);
}
- }.items("li.protection"));
+ }.items("li.protection").handle(".panel-heading"));
container.add(newAddNewFrag());
}
diff --git a/server-plugin/server-plugin-kubernetes/src/main/java/io/onedev/server/plugin/kubernetes/KubernetesExecutor.java b/server-plugin/server-plugin-kubernetes/src/main/java/io/onedev/server/plugin/kubernetes/KubernetesExecutor.java
index 1f6c98f2c0..3589192a25 100644
--- a/server-plugin/server-plugin-kubernetes/src/main/java/io/onedev/server/plugin/kubernetes/KubernetesExecutor.java
+++ b/server-plugin/server-plugin-kubernetes/src/main/java/io/onedev/server/plugin/kubernetes/KubernetesExecutor.java
@@ -1,8 +1,12 @@
package io.onedev.server.plugin.kubernetes;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
+import java.time.Instant;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -26,6 +30,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@@ -68,48 +73,33 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
private static final int LABEL_UPDATE_BATCH = 100;
- private String configFile;
+ private List<NodeSelectorEntry> nodeSelector = new ArrayList<>();
- private String kubeCtlPath;
-
private String namespace = "onedev-ci";
- private List<NodeSelectorEntry> nodeSelector = new ArrayList<>();
+ private String serviceAccount;
private List<RegistryLogin> registryLogins = new ArrayList<>();
- private String serviceAccount;
+ private String configFile;
+ private String kubeCtlPath;
+
private String cpuRequest = "500m";
private String memoryRequest = "128m";
- @Editable(name="Kubectl Config File", order=100, description=
- "Specify absolute path to the config file used by kubectl to access the "
- + "cluster. Leave empty to have kubectl determining cluster access "
- + "information automatically")
- @NameOfEmptyValue("Use default")
- public String getConfigFile() {
- return configFile;
- }
-
- public void setConfigFile(String configFile) {
- this.configFile = configFile;
- }
-
- @Editable(name="Path to kubectl", order=200, description=
- "Specify absolute path to the kubectl utility, for instance: <i>/usr/bin/kubectl</i>. "
- + "If left empty, OneDev will try to find the utility from system path")
- @NameOfEmptyValue("Use default")
- public String getKubeCtlPath() {
- return kubeCtlPath;
+ @Editable(order=20, description="Optionally specify node selectors of the "
+ + "job pods created by this executor")
+ public List<NodeSelectorEntry> getNodeSelector() {
+ return nodeSelector;
}
- public void setKubeCtlPath(String kubeCtlPath) {
- this.kubeCtlPath = kubeCtlPath;
+ public void setNodeSelector(List<NodeSelectorEntry> nodeSelector) {
+ this.nodeSelector = nodeSelector;
}
- @Editable(order=20000, group="More Settings", description="Specify namespace to run the job pods")
+ @Editable(order=30, description="Specify namespace to run the job pods")
@NotEmpty
public String getNamespace() {
return namespace;
@@ -119,7 +109,7 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
this.namespace = namespace;
}
- @Editable(order=20500, group="More Settings", description="Optionally specify a service account in above namespace to run the job "
+ @Editable(order=40, description="Optionally specify a service account in above namespace to run the job "
+ "pod. Refer to <a href='https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/'>"
+ "kubernetes documentation</a> on how to set up service accounts")
public String getServiceAccount() {
@@ -130,17 +120,7 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
this.serviceAccount = serviceAccount;
}
- @Editable(order=21000, group="More Settings", description="Optionally specify node selectors of the "
- + "job pods created by this executor")
- public List<NodeSelectorEntry> getNodeSelector() {
- return nodeSelector;
- }
-
- public void setNodeSelector(List<NodeSelectorEntry> nodeSelector) {
- this.nodeSelector = nodeSelector;
- }
-
- @Editable(order=22000, group="More Settings", description="Specify login information of docker registries if necessary. These "
+ @Editable(order=200, description="Specify login information of docker registries if necessary. These "
+ "logins will be used to create image pull secrets of the job pods")
public List<RegistryLogin> getRegistryLogins() {
return registryLogins;
@@ -174,6 +154,31 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
this.memoryRequest = memoryRequest;
}
+ @Editable(name="Kubectl Config File", order=26000, group="More Settings", description=
+ "Specify absolute path to the config file used by kubectl to access the "
+ + "cluster. Leave empty to have kubectl determining cluster access "
+ + "information automatically")
+ @NameOfEmptyValue("Use default")
+ public String getConfigFile() {
+ return configFile;
+ }
+
+ public void setConfigFile(String configFile) {
+ this.configFile = configFile;
+ }
+
+ @Editable(name="Path to kubectl", order=27000, group="More Settings", description=
+ "Specify absolute path to the kubectl utility, for instance: <i>/usr/bin/kubectl</i>. "
+ + "If left empty, OneDev will try to find the utility from system path")
+ @NameOfEmptyValue("Use default")
+ public String getKubeCtlPath() {
+ return kubeCtlPath;
+ }
+
+ public void setKubeCtlPath(String kubeCtlPath) {
+ this.kubeCtlPath = kubeCtlPath;
+ }
+
@Override
public void execute(String jobToken, JobContext jobContext) {
execute(jobContext.getEnvironment(), jobToken, jobContext.getLogger(), jobContext);
@@ -346,22 +351,17 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
return null;
}
- private String getOSName(JobLogger logger) {
+ private OsInfo getJobOsInfo(JobLogger logger) {
logger.log("Checking working node operating system...");
Commandline kubectl = newKubeCtl();
- kubectl.addArgs("get", "nodes", "-o", "jsonpath={range .items[*]}{.status.nodeInfo.operatingSystem}{'\\n'}{end}");
+ kubectl.addArgs("get", "nodes", "-o", "jsonpath={range .items[*]}{.status.nodeInfo.operatingSystem} {.status.nodeInfo.kernelVersion} {.spec.unschedulable}{'|'}{end}");
for (NodeSelectorEntry entry: getNodeSelector())
kubectl.addArgs("-l", entry.getLabelName() + "=" + entry.getLabelValue());
- AtomicReference<String> osNameRef = new AtomicReference<>(null);
- kubectl.execute(new LineConsumer() {
+ Collection<OsInfo> osInfos = new ArrayList<>();
- @Override
- public void consume(String line) {
- osNameRef.set(line);
- }
-
- }, new LineConsumer() {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ kubectl.execute(baos, new LineConsumer() {
@Override
public void consume(String line) {
@@ -370,10 +370,15 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
}).checkReturnCode();
- String osName = osNameRef.get();
- if (osName != null) {
- logger.log(String.format("Working node is running on %s", osName));
- return osName;
+ for (String osInfoString: Splitter.on('|').trimResults().omitEmptyStrings().splitToList(baos.toString())) {
+ osInfoString = osInfoString.replace('\n', ' ').replace('\r', ' ');
+ List<String> fields = Splitter.on(' ').omitEmptyStrings().trimResults().splitToList(osInfoString);
+ if (fields.size() == 2 || fields.get(2).equals("false"))
+ osInfos.add(new OsInfo(fields.get(0), fields.get(1)));
+ }
+
+ if (!osInfos.isEmpty()) {
+ return OsInfo.getBaseline(osInfos);
} else {
throw new OneException("No applicable working nodes found");
}
@@ -396,13 +401,6 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
return secretEnvs;
}
- private String getCacheHome(String osName) {
- if (osName.equalsIgnoreCase("linux"))
- return "/var/cache/onedev-ci";
- else
- return "C:\\ProgramData\\onedev-ci\\cache";
- }
-
@Nullable
private String createImagePullSecret(JobLogger logger) {
if (!getRegistryLogins().isEmpty()) {
@@ -477,7 +475,7 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
imagePullSecretName = createImagePullSecret(logger);
trustCertsConfigMapName = createTrustCertsConfigMap(logger);
- String osName = getOSName(logger);
+ OsInfo osInfo = getJobOsInfo(logger);
Map<String, Object> podSpec = new LinkedHashMap<>();
@@ -490,7 +488,7 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
String containerCacheHome;
String trustCertsHome;
String dockerSock;
- if (osName.equalsIgnoreCase("linux")) {
+ if (osInfo.isLinux()) {
containerCIHome = "/onedev-ci";
containerCacheHome = containerCIHome + "/cache";
trustCertsHome = containerCIHome + "/trust-certs";
@@ -548,15 +546,34 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
}
mainContainerSpec.put("env", envs);
- List<String> sidecarArgs = Lists.newArrayList("-classpath", k8sHelperClassPath, "io.onedev.k8shelper.SideCar");
- List<String> initArgs = Lists.newArrayList("-classpath", k8sHelperClassPath, "io.onedev.k8shelper.Init");
+ List<String> sidecarArgs = Lists.newArrayList(
+ "-classpath", k8sHelperClassPath,
+ "io.onedev.k8shelper.SideCar");
+ List<String> initArgs = Lists.newArrayList(
+ "-classpath", k8sHelperClassPath,
+ "io.onedev.k8shelper.Init");
if (jobContext == null) {
sidecarArgs.add("test");
initArgs.add("test");
}
+
+ String helperImageVersion;
+ /*
+ try (InputStream is = KubernetesExecutor.class.getClassLoader().getResourceAsStream("k8s-helper-version.properties")) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IOUtils.copy(is, baos);
+ helperImageVersion = baos.toString();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ */
+
+ // TODO: uncomment above for production code
+ helperImageVersion = "latest";
+
Map<Object, Object> sidecarContainerSpec = Maps.newHashMap(
"name", "sidecar",
- "image", "1dev/k8s-helper",
+ "image", "1dev/k8s-helper-" + osInfo.getHelperImageSuffix() + ":" + helperImageVersion,
"command", Lists.newArrayList("java"),
"args", sidecarArgs,
"env", envs,
@@ -564,7 +581,7 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
Map<Object, Object> initContainerSpec = Maps.newHashMap(
"name", "init",
- "image", "1dev/k8s-helper",
+ "image", "1dev/k8s-helper-" + osInfo.getHelperImageSuffix() + ":" + helperImageVersion,
"command", Lists.newArrayList("java"),
"args", initArgs,
"env", envs,
@@ -589,7 +606,7 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
Map<Object, Object> cacheHomeVolume = Maps.newLinkedHashMap(
"name", "cache-home",
"hostPath", Maps.newLinkedHashMap(
- "path", getCacheHome(osName),
+ "path", osInfo.getCacheHome(),
"type", "DirectoryOrCreate"));
List<Object> volumes = Lists.<Object>newArrayList(ciHomeVolume, cacheHomeVolume);
if (trustCertsConfigMapName != null) {
@@ -1089,28 +1106,49 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
}
private void collectContainerLog(String podName, String containerName, JobLogger logger) {
- Commandline kubectl = newKubeCtl();
- kubectl.addArgs("logs", podName, "-c", containerName, "-n", getNamespace(), "--follow");
- kubectl.execute(new LineConsumer() {
-
- @Override
- public void consume(String line) {
- if (line.contains("rpc error:") && line.contains("No such container:")
- || line.contains("Unable to retrieve container logs for")) {
- KubernetesExecutor.logger.debug(line);
- } else {
- logger.log(line);
- }
- }
+ AtomicReference<Instant> lastInstantRef = new AtomicReference<>(null);
+ AtomicBoolean endOfLogSeenRef = new AtomicBoolean(false);
+
+ while (!endOfLogSeenRef.get()) {
+ Commandline kubectl = newKubeCtl();
+ kubectl.addArgs("logs", podName, "-c", containerName, "-n", getNamespace(), "--follow", "--timestamps=true");
+ if (lastInstantRef.get() != null)
+ kubectl.addArgs("--since-time=" + DateTimeFormatter.ISO_INSTANT.format(lastInstantRef.get()));
- }, new LineConsumer() {
+ LineConsumer logConsumer = new LineConsumer() {
- @Override
- public void consume(String line) {
- logger.log(line);
- }
+ @Override
+ public void consume(String line) {
+ if (line.contains("rpc error:") && line.contains("No such container:")
+ || line.contains("Unable to retrieve container logs for")) {
+ KubernetesExecutor.logger.debug(line);
+ } else if (line.contains(KubernetesHelper.LOG_END_MESSAGE)) {
+ endOfLogSeenRef.set(true);
+ } else if (line.contains(" ")) {
+ String timestamp = StringUtils.substringBefore(line, " ");
+ try {
+ Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(timestamp));
+ if (lastInstantRef.get() == null || lastInstantRef.get().isBefore(instant))
+ lastInstantRef.set(instant);
+ logger.log(StringUtils.substringAfter(line, " "));
+ } catch (DateTimeParseException e) {
+ logger.log(line);
+ }
+ } else {
+ logger.log(line);
+ }
+ }
+
+ };
- }).checkReturnCode();
+ kubectl.execute(logConsumer, logConsumer).checkReturnCode();
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
@Editable
@@ -1183,4 +1221,81 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
}
+ private static class OsInfo {
+
+ private static final Map<String, Integer> WINDOWS_VERSIONS = new LinkedHashMap<>();
+
+ static {
+ // update this according to
+ // https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility
+ 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);
+ }
+
+ private final String osName;
+
+ private final String kernelVersion;
+
+ public OsInfo(String osName, String kernelVersion) {
+ this.osName = osName;
+ this.kernelVersion = kernelVersion;
+ }
+
+ public boolean isLinux() {
+ return osName.equalsIgnoreCase("linux");
+ }
+
+ public boolean isWindows() {
+ return osName.equalsIgnoreCase("windows");
+ }
+
+ public String getCacheHome() {
+ if (osName.equalsIgnoreCase("linux"))
+ return "/var/cache/onedev-ci";
+ else
+ return "C:\\ProgramData\\onedev-ci\\cache";
+ }
+
+ public static OsInfo getBaseline(Collection<OsInfo> osInfos) {
+ if (osInfos.iterator().next().isLinux()) {
+ for (OsInfo osInfo: osInfos) {
+ if (!osInfo.isLinux())
+ throw new OneException("Linux and non-linux nodes should not be included in same executor");
+ }
+ return osInfos.iterator().next();
+ } else if (osInfos.iterator().next().isWindows()) {
+ OsInfo baseline = null;
+ for (OsInfo osInfo: osInfos) {
+ if (!osInfo.isWindows())
+ throw new OneException("Windows and non-windows nodes should not be included in same executor");
+ if (baseline == null || baseline.getWindowsVersion() > osInfo.getWindowsVersion())
+ baseline = osInfo;
+ }
+ return baseline;
+ } else {
+ throw new OneException("Either Windows or Linux nodes can be included in an executor");
+ }
+ }
+
+ 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 RuntimeException("Unsupported windows kernel version: " + kernelVersion);
+ }
+
+ public String getHelperImageSuffix() {
+ if (isLinux())
+ return "linux";
+ else
+ return "windows-" + getWindowsVersion();
+ }
+
+ }
+
}
\ No newline at end of file
diff --git a/server-product/k8s/base/deployments.yaml b/server-product/k8s/base/deployments.yaml
index 84b2e9cd8c..5d34beb205 100644
--- a/server-product/k8s/base/deployments.yaml
+++ b/server-product/k8s/base/deployments.yaml
@@ -47,6 +47,8 @@ spec:
persistentVolumeClaim:
claimName: onedev
serviceAccountName: onedev
+ nodeSelector:
+ kubernetes.io/os: linux
---
apiVersion: apps/v1
kind: Deployment
@@ -102,3 +104,5 @@ spec:
- name: mysql
persistentVolumeClaim:
claimName: mysql
+ nodeSelector:
+ kubernetes.io/os: linux
diff --git a/server-product/k8s/production/kustomization.yaml b/server-product/k8s/production/kustomization.yaml
index ab18c96988..e859dc8d1e 100644
--- a/server-product/k8s/production/kustomization.yaml
+++ b/server-product/k8s/production/kustomization.yaml
@@ -4,6 +4,7 @@ bases:
commonLabels:
app: onedev
patchesStrategicMerge:
+- node-selectors.yaml
- cpu-settings.yaml
- memory-settings.yaml
- disk-settings.yaml
diff --git a/server-product/k8s/production/node-selectors.yaml b/server-product/k8s/production/node-selectors.yaml
new file mode 100644
index 0000000000..700083cadb
--- /dev/null
+++ b/server-product/k8s/production/node-selectors.yaml
@@ -0,0 +1,19 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: onedev
+spec:
+ template:
+ spec:
+ nodeSelector:
+ kubernetes.io/os: linux
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: onedev
+spec:
+ template:
+ spec:
+ nodeSelector:
+ kubernetes.io/os: linux