Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
refactor: unify services definition structure
Browse files Browse the repository at this point in the history
  • Loading branch information
YkeLit committed Mar 8, 2024
1 parent e35b20b commit f128348
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ A Helm chart template for byzanteam application
| nameOverride | string | `""` | |
| replicaCount | int | `1` | |
| restartPolicy | string | `"Always"` | |
| service[].name | string | `"http"` | |
| service[].port | int | `80` | |
| service[].protocol | string | `TCP` | |
| serviceType | string | `"ClusterIP"` | |
| services.ports[].name | string | `"http"` | |
| services.ports[].port | int | `80` | |
| services.ports[].protocol | string | `TCP` | |
| services.type | string | `"ClusterIP"` | |
| volumeMounts | list | `[]` | |
| volumes | list | `[]` | |
| nodeSelector | object | `{}` | |
Expand Down Expand Up @@ -79,7 +79,7 @@ appIngressroute:
path: /example-path
servicePortIndex: 0
```
> 注: `servicePortIndex` 此值为 `.Values.services` 中子路径对应服务端口的索引值。值以 0 开始。
> 注: `servicePortIndex` 此值为 `.Values.services.ports` 中子路径对应服务端口的索引值。值以 0 开始。

### 5. 设置外部服务代理规则

Expand Down
8 changes: 4 additions & 4 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ spec:
containerPort: {{ .Values.service.port }}
protocol: TCP
{{- else }}
{{- range $service := .Values.services }}
- name: {{ $service.name }}
containerPort: {{ $service.port }}
protocol: {{ $service.protocol }}
{{- range .Values.services.ports }}
- name: {{ .name }}
containerPort: {{ .port }}
protocol: {{ .protocol }}
{{- end }}
{{- end }}
volumeMounts:
Expand Down
12 changes: 6 additions & 6 deletions templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ spec:
protocol: TCP
name: {{ .Values.service.name }}
{{- else }}
type: {{ .Values.serviceType }}
type: {{ .Values.services.type }}
ports:
{{- range $service := .Values.services }}
- port: {{ $service.port }}
targetPort: {{ $service.name }}
protocol: {{ $service.protocol }}
name: {{ $service.name }}
{{- range .Values.services.ports }}
- port: {{ .port }}
targetPort: {{ .name }}
protocol: {{ .protocol }}
name: {{ .name }}
{{- end }}
{{- end }}
selector:
Expand Down
4 changes: 2 additions & 2 deletions templates/traefik/ingress-route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
kind: Rule
services:
- name: {{ include "application-chart-template.fullname" $ }}
port: {{ get (index $.Values.services (int .servicePortIndex)) "port" }}
port: {{ get (index $.Values.services.ports (int .servicePortIndex)) "port" }}
middlewares:
{{- include "application-chart-template.webMiddlewares" $ | nindent 8}}
{{- end }}
Expand Down Expand Up @@ -52,7 +52,7 @@ spec:
kind: Rule
services:
- name: {{ include "application-chart-template.fullname" $ }}
port: {{ get (index $.Values.services (int .servicePortIndex)) "port" }}
port: {{ get (index $.Values.services.ports (int .servicePortIndex)) "port" }}
middlewares:
{{- include "application-chart-template.websecureMiddlewares" $ | nindent 8}}
{{- end }}
Expand Down
12 changes: 7 additions & 5 deletions tests/application_ingressroute_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ tests:
path: /example
servicePortIndex: 1
services:
- port: 80
name: product
- port: 8080
name: example
ports:
- port: 80
name: product
- port: 8080
name: example
asserts:
- hasDocuments:
count: 3
Expand Down Expand Up @@ -69,7 +70,8 @@ tests:
path: /app
port: 0
services:
- port: 80
ports:
- port: 80
asserts:
- equal:
path: spec.routes[0].middlewares[0].name
Expand Down
10 changes: 5 additions & 5 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ externalIngressroute: []

# 应用服务配置
services:
- name: http
port: 80
protocol: TCP

serviceType: ClusterIP
type: ClusterIP
ports:
- name: http
port: 80
protocol: TCP

# 覆盖 image command
command: []
Expand Down

0 comments on commit f128348

Please sign in to comment.