From 68ca7bcbc98e77dc2fcca53f864d93bb4ace4bdd Mon Sep 17 00:00:00 2001 From: Bird Date: Sun, 16 Apr 2023 12:55:58 +0800 Subject: [PATCH] feat: remove svc/endpoint of datasource and use bare ip:port && use urlOverride to fully custom jdbc url (#30) * feat: remove svc/endpoint of datasource and use bare ip:port Signed-off-by: Bird * feat: use urlOverride to fully custom jdbc url Signed-off-by: Bird --------- Signed-off-by: Bird --- charts/shenyu/Chart.yaml | 2 +- charts/shenyu/templates/ConfigMap.yaml | 8 +- charts/shenyu/templates/_helpers.tpl | 33 ++++++++ .../shenyu/templates/shenyu-datasource.yaml | 84 ------------------- charts/shenyu/values.yaml | 8 ++ 5 files changed, 46 insertions(+), 89 deletions(-) delete mode 100644 charts/shenyu/templates/shenyu-datasource.yaml diff --git a/charts/shenyu/Chart.yaml b/charts/shenyu/Chart.yaml index ea0d050..64b3dc3 100644 --- a/charts/shenyu/Chart.yaml +++ b/charts/shenyu/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: shenyu description: Helm Chart for deploying Apache ShenYu in Kubernetes type: application -version: 0.6.0 +version: 0.6.1 appVersion: "2.5.1" icon: https://shenyu.apache.org/img/logo.png maintainers: diff --git a/charts/shenyu/templates/ConfigMap.yaml b/charts/shenyu/templates/ConfigMap.yaml index 9dd59cd..cfcc946 100644 --- a/charts/shenyu/templates/ConfigMap.yaml +++ b/charts/shenyu/templates/ConfigMap.yaml @@ -25,7 +25,7 @@ data: init_enable: {{ .Values.dataSource.initEnabled }} spring: datasource: - url: jdbc:h2:mem:~/shenyu;DB_CLOSE_DELAY=-1;MODE=MySQL; + url: {{ template "shenyu.h2.url" . }} username: {{ required ".dataSource.h2.username is required" .Values.dataSource.h2.username }} password: {{ required ".dataSource.h2.password is required" .Values.dataSource.h2.password }} driver-class-name: org.h2.Driver @@ -38,7 +38,7 @@ data: init_enable: {{ .Values.dataSource.initEnabled }} spring: datasource: - url: jdbc:mysql://{{ template "common.names.fullname" . }}-mysql.{{.Release.Namespace}}.svc.cluster.local:3306/{{ required "" .Values.dataSource.mysql.database | default "shenyu" }}?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull + url: {{ template "shenyu.mysql.url" . }} username: {{ required ".dataSource.mysql.username is required" .Values.dataSource.mysql.username }} password: {{ required "`dataSource.mysql.password` is required" .Values.dataSource.mysql.password }} driver-class-name: {{ .Values.dataSource.mysql.driverClass }} @@ -52,7 +52,7 @@ data: spring: datasource: - url: jdbc:postgresql://{{ template "common.names.fullname" . }}-pg.{{.Release.Namespace}}.svc.cluster.local:5432/{{ .Values.dataSource.pg.database | default "shenyu" }} + url: {{ template "shenyu.pg.url" . }} username: {{ required ".dataSource.pg.username is required" .Values.dataSource.pg.username }} password: {{ required "`dataSource.pg.password` is required" .Values.dataSource.pg.password }} driver-class-name: {{ .Values.dataSource.pg.driverClass }} @@ -69,7 +69,7 @@ data: spring: datasource: - url: jdbc:oracle:thin:@{{ template "common.names.fullname" . }}-oracle.{{.Release.Namespace}}.svc.cluster.local:1521/{{ .Values.dataSource.oracle.serviceName | default "shenyu" }} + url: {{ template "shenyu.oracle.url" . }} username: {{ required ".dataSource.oracle.username is required" .Values.dataSource.oracle.username }} password: {{ required "`dataSource.oracle.password` is required" .Values.dataSource.oracle.password }} driver-class-name: oracle.jdbc.OracleDriver diff --git a/charts/shenyu/templates/_helpers.tpl b/charts/shenyu/templates/_helpers.tpl index e69de29..6a9e01e 100644 --- a/charts/shenyu/templates/_helpers.tpl +++ b/charts/shenyu/templates/_helpers.tpl @@ -0,0 +1,33 @@ +{{- define "shenyu.h2.url" }} + {{- .Values.dataSource.h2.url | default "jdbc:h2:mem:~/shenyu;DB_CLOSE_DELAY=-1;MODE=MySQL;" }} +{{- end -}} + +{{- define "shenyu.mysql.url" -}} +{{- with .Values.dataSource.mysql -}} + {{- if .urlOverride -}} + {{- .urlOverride | quote -}} + {{- else -}} + jdbc:mysql://{{ required ".dataSource.mysql.ip is required" .ip }}:{{ .port }}/{{ required "" .database | default "shenyu" }}?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull + {{- end }} +{{- end }} +{{- end -}} + +{{- define "shenyu.pg.url" -}} +{{- with .Values.dataSource.pg -}} + {{- if .urlOverride -}} + {{- .urlOverride -}} + {{- else -}} + jdbc:postgresql://{{ .ip }}:{{ .port }}/{{ .database | default "shenyu" }} + {{- end }} +{{- end }} +{{- end -}} + +{{- define "shenyu.oracle.url" -}} +{{- with .Values.dataSource.oracle -}} + {{- if .urlOverride -}} + {{- .urlOverride -}} + {{- else -}} + jdbc:oracle:thin:@{{ .ip }}:{{ .port }}/{{ .serviceName | default "shenyu" }} + {{- end }} +{{- end }} +{{- end -}} diff --git a/charts/shenyu/templates/shenyu-datasource.yaml b/charts/shenyu/templates/shenyu-datasource.yaml deleted file mode 100644 index 605c065..0000000 --- a/charts/shenyu/templates/shenyu-datasource.yaml +++ /dev/null @@ -1,84 +0,0 @@ -{{- if .Values.admin.enabled -}} -{{ if eq .Values.dataSource.active "mysql" -}} -############# MySQL Begin ############# -kind: Service -apiVersion: v1 -metadata: - name: {{ template "common.names.fullname" . }}-mysql - namespace: {{ .Release.Namespace }} -spec: - ports: - - port: 3306 - name: mysql - targetPort: {{ required "database.mysql.port is required" .Values.dataSource.mysql.port }} ---- -kind: Endpoints -apiVersion: v1 -metadata: - name: {{ template "common.names.fullname" . }}-mysql - namespace: {{ .Release.Namespace }} -subsets: -- addresses: - - ip: {{ required "database.mysql.ip is required" .Values.dataSource.mysql.ip }} - ports: - - port: {{ required "database.mysql.port is required" .Values.dataSource.mysql.port }} - name: mysql -{{ end -}} - ---- - -{{ if eq .Values.dataSource.active "pg" -}} -############# PostgreSQL Begin ############# -kind: Service -apiVersion: v1 -metadata: - name: {{ template "common.names.fullname" . }}-pg - namespace: {{ .Release.Namespace }} -spec: - ports: - - port: 5432 - name: pg - targetPort: {{ required "database.pg.port is required" .Values.dataSource.pg.port }} ---- -kind: Endpoints -apiVersion: v1 -metadata: - name: {{ template "common.names.fullname" . }}-pg - namespace: {{ .Release.Namespace }} -subsets: - - addresses: - - ip: {{ required "database.pg.ip is required" .Values.dataSource.pg.ip }} - ports: - - port: {{ required "database.pg.port is required" .Values.dataSource.pg.port }} - name: pg -{{ end -}} - ---- - -{{ if eq .Values.dataSource.active "oracle" -}} -############# Oracle Begin ############# -kind: Service -apiVersion: v1 -metadata: - name: {{ template "common.names.fullname" . }}-oracle - namespace: {{ .Release.Namespace }} -spec: - ports: - - port: 1521 - name: oracle - targetPort: {{ required "database.oracle.port is required" .Values.dataSource.oracle.port }} ---- -kind: Endpoints -apiVersion: v1 -metadata: - name: {{ template "common.names.fullname" . }}-oracle - namespace: {{ .Release.Namespace }} -subsets: -- addresses: - - ip: {{ required "database.oracle.ip is required" .Values.dataSource.oracle.ip }} - ports: - - port: {{ required "database.oracle.port is required" .Values.dataSource.oracle.port }} - name: oracle -{{ end -}} - -{{- end -}} diff --git a/charts/shenyu/values.yaml b/charts/shenyu/values.yaml index 2aadd58..a128001 100644 --- a/charts/shenyu/values.yaml +++ b/charts/shenyu/values.yaml @@ -96,9 +96,13 @@ dataSource: # init database and tables initEnabled: true h2: + # use custom datasource url, default is jdbc:h2:mem:~/shenyu;DB_CLOSE_DELAY=-1;MODE=MySQL; + url: "" username: sa password: sa mysql: + # use custom datasource url and ignore other configs, the format is jdbc:mysql://xxxxxxx + urlOverride: "" ip: port: 3306 username: root @@ -110,6 +114,8 @@ dataSource: driverClass: com.mysql.cj.jdbc.Driver connectorVersion: 8.0.23 pg: + # use custom datasource url and ignore other configs, the format is jdbc:postgresql://xxxxxxx + urlOverride: "" ip: port: 5432 username: postgres @@ -119,6 +125,8 @@ dataSource: driverClass: org.postgresql.Driver connectorVersion: 42.5.0 oracle: + # use custom datasource url and ignore other configs, the format is jdbc:oracle:xxxxxx + urlOverride: "" ip: port: 1521 username: root