Skip to content

The Unified and Autonomous Development Platform

Add trust certs support for helm chart

Robin Shen299bf12ec97e
diff --git a/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java b/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java
index fa685ffba6..11eb92cc81 100644
--- a/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java
+++ b/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java
@@ -619,11 +619,12 @@ public class KubernetesExecutor extends JobExecutor implements Testable<TestData
Map<String, String> configMapData = new LinkedHashMap<>();
File trustCertsDir = new File(Bootstrap.getConfDir(), "trust-certs");
if (trustCertsDir.exists()) {
+ int index = 1;
for (File file: trustCertsDir.listFiles()) {
if (file.isFile() && !file.isHidden()) {
try {
byte[] fileContent = FileUtils.readFileToByteArray(file);
- configMapData.put(file.getName(), Base64.encodeBase64String(fileContent));
+ configMapData.put((index++) + ".pem", Base64.encodeBase64String(fileContent));
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/server-product/helm/templates/configmap.yaml b/server-product/helm/templates/configmap.yaml
new file mode 100644
index 0000000000..c54b53f05e
--- /dev/null
+++ b/server-product/helm/templates/configmap.yaml
@@ -0,0 +1,8 @@
+{{- if .Values.trustCerts -}}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: {{ include "onedev.fullname" . }}-trust-certs
+binaryData:
+ cert.pem: {{ .Values.trustCerts | b64enc }}
+{{- end }}
diff --git a/server-product/helm/templates/deployment.yaml b/server-product/helm/templates/deployment.yaml
index 3e903d07ad..f851348bf7 100644
--- a/server-product/helm/templates/deployment.yaml
+++ b/server-product/helm/templates/deployment.yaml
@@ -33,8 +33,12 @@ spec:
requests:
memory: {{ .Values.resources.onedev.memory }}
volumeMounts:
- - mountPath: "/opt/onedev"
- name: onedev
+ - name: onedev
+ mountPath: "/opt/onedev"
+ {{- if .Values.trustCerts }}
+ - name: trust-certs
+ mountPath: "/opt/onedev/conf/trust-certs"
+ {{- end }}
image: "1dev/server:{{ .Chart.AppVersion }}"
ports:
- containerPort: 6610
@@ -91,6 +95,12 @@ spec:
- name: onedev
persistentVolumeClaim:
claimName: {{ include "onedev.fullname" . }}
+ {{- if .Values.trustCerts }}
+ - name: trust-certs
+ configMap:
+ name: {{ include "onedev.fullname" . }}-trust-certs
+ {{- end }}
+
---
apiVersion: apps/v1
diff --git a/server-product/helm/values.yaml b/server-product/helm/values.yaml
index bf9ced4e00..982e8b52fd 100644
--- a/server-product/helm/values.yaml
+++ b/server-product/helm/values.yaml
@@ -90,4 +90,9 @@ initial:
email: ""
## Server url will be ignored if ingress.host is specified above
serverUrl: ""
- sshRootUrl: ""
\ No newline at end of file
+ sshRootUrl: ""
+
+## Specify a local directory containing certificates to be trusted.
+## Certificate should be in PEM format starting with
+## -----BEGIN CERTIFICATE----- and ending with -----END CERTIFICATE-----
+trustCerts: ""
\ No newline at end of file