From b4621483d5b5f0f1b84fbc960dcb3675a8f78bb4 Mon Sep 17 00:00:00 2001 From: "Bai, Changhe" Date: Thu, 4 Apr 2024 16:38:53 -0400 Subject: [PATCH 1/5] multi-port service support for prefect-server --- .../prefect-server/templates/deployment.yaml | 10 +++---- charts/prefect-server/templates/ingress.yaml | 4 +-- charts/prefect-server/templates/service.yaml | 15 ++++++---- .../prefect-server/templates/target-port.yaml | 14 ++++++++++ charts/prefect-server/values.schema.json | 28 +++++++++++++++---- charts/prefect-server/values.yaml | 20 +++++++++---- 6 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 charts/prefect-server/templates/target-port.yaml diff --git a/charts/prefect-server/templates/deployment.yaml b/charts/prefect-server/templates/deployment.yaml index 592d4b6e..0e5670ae 100644 --- a/charts/prefect-server/templates/deployment.yaml +++ b/charts/prefect-server/templates/deployment.yaml @@ -65,13 +65,13 @@ spec: - server - start - --port - - {{ .Values.service.targetPort | quote }} + - {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") | quote }} {{- range .Values.server.extraArgs }} - {{ . | toString }} {{- end }} workingDir: /home/prefect ports: - - containerPort: {{ int .Values.service.targetPort }} + - containerPort: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }} env: - name: HOME value: /home/prefect @@ -84,7 +84,7 @@ spec: - name: PREFECT_SERVER_API_HOST value: {{ .Values.server.prefectApiHost | quote }} - name: PREFECT_SERVER_API_PORT - value: {{ .Values.service.targetPort | quote }} + value: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") | quote }} - name: PREFECT_UI_ENABLED value: {{ .Values.server.uiConfig.enabled | quote }} {{- if .Values.server.uiConfig.prefectUiApiUrl }} @@ -126,14 +126,14 @@ spec: livenessProbe: httpGet: path: /api/health - port: {{ .Values.service.targetPort }} + port: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }} {{- toYaml .Values.server.livenessProbe.config | nindent 12 }} {{- end }} {{- if .Values.server.readinessProbe.enabled }} readinessProbe: httpGet: path: /api/ready - port: {{ .Values.service.targetPort }} + port: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }} {{- toYaml .Values.server.readinessProbe.config | nindent 12 }} {{- end }} volumeMounts: diff --git a/charts/prefect-server/templates/ingress.yaml b/charts/prefect-server/templates/ingress.yaml index c269b871..73f6361d 100644 --- a/charts/prefect-server/templates/ingress.yaml +++ b/charts/prefect-server/templates/ingress.yaml @@ -35,7 +35,7 @@ spec: {{- if eq "true" (include "common.ingress.supportsPathType" .) }} pathType: {{ .Values.ingress.host.pathType }} {{- end }} - backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" .) "servicePort" "server-svc-port" "context" $) | nindent 14 }} + backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" .) "servicePort" .Values.ingress.servicePort "context" $) | nindent 14 }} {{- end }} {{- range .Values.ingress.extraHosts }} - host: {{ .name | quote }} @@ -45,7 +45,7 @@ spec: {{- if eq "true" (include "common.ingress.supportsPathType" $) }} pathType: {{ default "ImplementationSpecific" .pathType }} {{- end }} - backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" $) "servicePort" "server-svc-port" "context" $) | nindent 14 }} + backend: {{- include "common.ingress.backend" (dict "serviceName" (include "common.names.fullname" $) "servicePort" .Values.ingress.servicePort "context" $) | nindent 14 }} {{- end }} {{- if .Values.ingress.extraRules }} {{- include "common.tplvalues.render" (dict "value" .Values.ingress.extraRules "context" $) | nindent 4 }} diff --git a/charts/prefect-server/templates/service.yaml b/charts/prefect-server/templates/service.yaml index 9a2305e5..a64aa704 100644 --- a/charts/prefect-server/templates/service.yaml +++ b/charts/prefect-server/templates/service.yaml @@ -26,15 +26,18 @@ spec: {{- if eq .Values.service.type "NodePort" }} externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy | quote }} {{- end }} + {{- $serviceType := .Values.service.type }} ports: - - name: server-svc-port - port: {{ .Values.service.port }} + {{- range .Values.service.ports }} + - name: {{ .name }} protocol: TCP - targetPort: {{ .Values.service.targetPort }} - {{- if and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort)) }} - nodePort: {{ .Values.service.nodePort }} - {{- else if eq .Values.service.type "ClusterIP" }} + port: {{ .port }} + targetPort: {{ .targetPort }} + {{- if and (eq $serviceType "NodePort") (not (empty .nodePort)) }} + nodePort: {{ .nodePort }} + {{- else if eq $serviceType "ClusterIP" }} nodePort: null {{- end }} + {{- end }} selector: {{- include "common.labels.matchLabels" . | nindent 4 }} app.kubernetes.io/component: server diff --git a/charts/prefect-server/templates/target-port.yaml b/charts/prefect-server/templates/target-port.yaml new file mode 100644 index 00000000..08635832 --- /dev/null +++ b/charts/prefect-server/templates/target-port.yaml @@ -0,0 +1,14 @@ +{{- define "target-port" }} +{{- $ports := .ports }} +{{- $targetPortName := .name }} +{{- $targetPortNumber := 0 }} + +{{- range $ports }} + {{- if eq .name $targetPortName }} + {{- $targetPortNumber = .targetPort }} + {{- end }} +{{- end }} + +{{- $targetPortNumber }} + +{{- end }} diff --git a/charts/prefect-server/values.schema.json b/charts/prefect-server/values.schema.json index a91f8a9d..28cdfabf 100644 --- a/charts/prefect-server/values.schema.json +++ b/charts/prefect-server/values.schema.json @@ -524,11 +524,23 @@ "description": "service type", "form": true }, - "port": { - "type": "integer", - "title": "Port", - "description": "service port", - "form": true + "ports": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "port": { + "type": "integer" + }, + "targetPort": { + "type": "integer" + } + }, + "required": ["name", "port", "targetPort"] + } }, "clusterIP": { "type": "string", @@ -575,6 +587,12 @@ "description": "enable ingress record generation for server", "form": true }, + "servicePort": { + "type": "string", + "title": "Service Port Name", + "description": "service port name", + "form": true + }, "className": { "type": "string", "title": "Class Name", diff --git a/charts/prefect-server/values.yaml b/charts/prefect-server/values.yaml index fc1d788e..ae90834c 100644 --- a/charts/prefect-server/values.yaml +++ b/charts/prefect-server/values.yaml @@ -185,16 +185,20 @@ serviceAccount: ## Service configuration service: + ports: + - name: server-svc-port + # -- service port + port: 4200 + # -- target port of the server pod; also sets PREFECT_SERVER_API_PORT + targetPort: 4200 + # -- service port if defining service as type nodeport + nodePort: "" + # -- service type type: ClusterIP - # -- service port - port: 4200 - # -- target port of the server pod; also sets PREFECT_SERVER_API_PORT - targetPort: 4200 # -- service Cluster IP clusterIP: "" - # -- service port if defining service as type nodeport - nodePort: "" + ## ref http://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip # -- service external traffic policy @@ -206,6 +210,10 @@ service: ingress: # -- enable ingress record generation for server enabled: false + + # -- port for the ingress' main path + servicePort: server-svc-port + ## This is supported in Kubernetes 1.18+ and required if you have more than one IngressClass marked as the default for your cluster . ## ref: https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/ # -- IngressClass that will be used to implement the Ingress (Kubernetes 1.18+) From 567aa3ca5539999016710bd74b892872f7cd37f3 Mon Sep 17 00:00:00 2001 From: "Bai, Changhe" Date: Mon, 29 Apr 2024 11:51:16 -0400 Subject: [PATCH 2/5] extraPorts implementation --- .../prefect-server/templates/deployment.yaml | 10 ++++---- charts/prefect-server/templates/service.yaml | 11 ++++++++- .../prefect-server/templates/target-port.yaml | 14 ----------- charts/prefect-server/values.schema.json | 8 ++++++- charts/prefect-server/values.yaml | 24 ++++++++++++------- 5 files changed, 38 insertions(+), 29 deletions(-) delete mode 100644 charts/prefect-server/templates/target-port.yaml diff --git a/charts/prefect-server/templates/deployment.yaml b/charts/prefect-server/templates/deployment.yaml index 0e5670ae..592d4b6e 100644 --- a/charts/prefect-server/templates/deployment.yaml +++ b/charts/prefect-server/templates/deployment.yaml @@ -65,13 +65,13 @@ spec: - server - start - --port - - {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") | quote }} + - {{ .Values.service.targetPort | quote }} {{- range .Values.server.extraArgs }} - {{ . | toString }} {{- end }} workingDir: /home/prefect ports: - - containerPort: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }} + - containerPort: {{ int .Values.service.targetPort }} env: - name: HOME value: /home/prefect @@ -84,7 +84,7 @@ spec: - name: PREFECT_SERVER_API_HOST value: {{ .Values.server.prefectApiHost | quote }} - name: PREFECT_SERVER_API_PORT - value: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") | quote }} + value: {{ .Values.service.targetPort | quote }} - name: PREFECT_UI_ENABLED value: {{ .Values.server.uiConfig.enabled | quote }} {{- if .Values.server.uiConfig.prefectUiApiUrl }} @@ -126,14 +126,14 @@ spec: livenessProbe: httpGet: path: /api/health - port: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }} + port: {{ .Values.service.targetPort }} {{- toYaml .Values.server.livenessProbe.config | nindent 12 }} {{- end }} {{- if .Values.server.readinessProbe.enabled }} readinessProbe: httpGet: path: /api/ready - port: {{ include "target-port" (dict "ports" .Values.service.ports "name" "server-svc-port") }} + port: {{ .Values.service.targetPort }} {{- toYaml .Values.server.readinessProbe.config | nindent 12 }} {{- end }} volumeMounts: diff --git a/charts/prefect-server/templates/service.yaml b/charts/prefect-server/templates/service.yaml index a64aa704..22c30e8d 100644 --- a/charts/prefect-server/templates/service.yaml +++ b/charts/prefect-server/templates/service.yaml @@ -28,7 +28,16 @@ spec: {{- end }} {{- $serviceType := .Values.service.type }} ports: - {{- range .Values.service.ports }} + - name: server-svc-port + port: {{ .Values.service.port }} + protocol: TCP + targetPort: {{ .Values.service.targetPort }} + {{- if and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort)) }} + nodePort: {{ .Values.service.nodePort }} + {{- else if eq .Values.service.type "ClusterIP" }} + nodePort: null + {{- end }} + {{- range .Values.service.extraPorts }} - name: {{ .name }} protocol: TCP port: {{ .port }} diff --git a/charts/prefect-server/templates/target-port.yaml b/charts/prefect-server/templates/target-port.yaml deleted file mode 100644 index 08635832..00000000 --- a/charts/prefect-server/templates/target-port.yaml +++ /dev/null @@ -1,14 +0,0 @@ -{{- define "target-port" }} -{{- $ports := .ports }} -{{- $targetPortName := .name }} -{{- $targetPortNumber := 0 }} - -{{- range $ports }} - {{- if eq .name $targetPortName }} - {{- $targetPortNumber = .targetPort }} - {{- end }} -{{- end }} - -{{- $targetPortNumber }} - -{{- end }} diff --git a/charts/prefect-server/values.schema.json b/charts/prefect-server/values.schema.json index 28cdfabf..97f02673 100644 --- a/charts/prefect-server/values.schema.json +++ b/charts/prefect-server/values.schema.json @@ -524,7 +524,13 @@ "description": "service type", "form": true }, - "ports": { + "port": { + "type": "integer", + "title": "Port", + "description": "service port", + "form": true + }, + "extraPorts": { "type": "array", "items": { "type": "object", diff --git a/charts/prefect-server/values.yaml b/charts/prefect-server/values.yaml index ae90834c..348cee48 100644 --- a/charts/prefect-server/values.yaml +++ b/charts/prefect-server/values.yaml @@ -185,14 +185,22 @@ serviceAccount: ## Service configuration service: - ports: - - name: server-svc-port - # -- service port - port: 4200 - # -- target port of the server pod; also sets PREFECT_SERVER_API_PORT - targetPort: 4200 - # -- service port if defining service as type nodeport - nodePort: "" + # -- service port + port: 4200 + # -- target port of the server pod; also sets PREFECT_SERVER_API_PORT + targetPort: 4200 + # -- service port if defining service as type nodeport + nodePort: "" + + extraPorts: + # # example extra ports + # - name: sample-svc-port + # # -- service port + # port: 8080 + # # -- target port + # targetPort: 8080 + # # -- service port if defining service as type nodeport + # nodePort: "" # -- service type type: ClusterIP From 05e6576b31c3d6f019deebf5c2f53ee86e035502 Mon Sep 17 00:00:00 2001 From: "Bai, Changhe" Date: Mon, 6 May 2024 11:09:08 -0400 Subject: [PATCH 3/5] extraPorts default to an empty array --- charts/prefect-server/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/prefect-server/values.yaml b/charts/prefect-server/values.yaml index 348cee48..800d3db4 100644 --- a/charts/prefect-server/values.yaml +++ b/charts/prefect-server/values.yaml @@ -192,7 +192,7 @@ service: # -- service port if defining service as type nodeport nodePort: "" - extraPorts: + extraPorts: [] # # example extra ports # - name: sample-svc-port # # -- service port From f3e737b2ec1f7111689ab6b88eac241a7b43ab37 Mon Sep 17 00:00:00 2001 From: "Bai, Changhe" Date: Thu, 16 May 2024 17:02:36 -0400 Subject: [PATCH 4/5] fix lint errors and helm docs update --- charts/prefect-agent/README.md | 2 ++ charts/prefect-server/README.md | 4 ++++ charts/prefect-server/values.yaml | 6 +++--- charts/prefect-worker/README.md | 2 ++ charts/prometheus-prefect-exporter/README.md | 2 ++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/charts/prefect-agent/README.md b/charts/prefect-agent/README.md index 2388edf4..7f4b455e 100644 --- a/charts/prefect-agent/README.md +++ b/charts/prefect-agent/README.md @@ -80,3 +80,5 @@ Prefect Agent application bundle | serviceAccount.create | bool | `true` | specifies whether a ServiceAccount should be created | | serviceAccount.name | string | `""` | the name of the ServiceAccount to use. if not set and create is true, a name is generated using the common.names.fullname template | +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1) diff --git a/charts/prefect-server/README.md b/charts/prefect-server/README.md index 5e17788a..c98dce05 100644 --- a/charts/prefect-server/README.md +++ b/charts/prefect-server/README.md @@ -117,6 +117,7 @@ No secrets are created when providing an existing secret. | ingress.host.path | string | `"/"` | default path for the ingress record | | ingress.host.pathType | string | `"ImplementationSpecific"` | ingress path type | | ingress.selfSigned | bool | `false` | create a TLS secret for this ingress record using self-signed certificates generated by Helm | +| ingress.servicePort | string | `"server-svc-port"` | port for the ingress' main path | | ingress.tls | bool | `false` | enable TLS configuration for the host defined at `ingress.host.hostname` parameter | | nameOverride | string | `""` | partially overrides common.names.name | | namespaceOverride | string | `""` | fully override common.names.namespace | @@ -188,6 +189,7 @@ No secrets are created when providing an existing secret. | service.annotations | object | `{}` | | | service.clusterIP | string | `""` | service Cluster IP | | service.externalTrafficPolicy | string | `"Cluster"` | service external traffic policy | +| service.extraPorts | list | `[]` | | | service.nodePort | string | `""` | service port if defining service as type nodeport | | service.port | int | `4200` | service port | | service.targetPort | int | `4200` | target port of the server pod; also sets PREFECT_SERVER_API_PORT | @@ -196,3 +198,5 @@ No secrets are created when providing an existing secret. | serviceAccount.create | bool | `true` | specifies whether a ServiceAccount should be created | | serviceAccount.name | string | `""` | the name of the ServiceAccount to use. if not set and create is true, a name is generated using the common.names.fullname template | +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1) diff --git a/charts/prefect-server/values.yaml b/charts/prefect-server/values.yaml index 800d3db4..62aad932 100644 --- a/charts/prefect-server/values.yaml +++ b/charts/prefect-server/values.yaml @@ -201,12 +201,12 @@ service: # targetPort: 8080 # # -- service port if defining service as type nodeport # nodePort: "" - + # -- service type type: ClusterIP # -- service Cluster IP clusterIP: "" - + ## ref http://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip # -- service external traffic policy @@ -219,7 +219,7 @@ ingress: # -- enable ingress record generation for server enabled: false - # -- port for the ingress' main path + # -- port for the ingress' main path servicePort: server-svc-port ## This is supported in Kubernetes 1.18+ and required if you have more than one IngressClass marked as the default for your cluster . diff --git a/charts/prefect-worker/README.md b/charts/prefect-worker/README.md index b3c7fb0d..848532f7 100644 --- a/charts/prefect-worker/README.md +++ b/charts/prefect-worker/README.md @@ -302,3 +302,5 @@ helm install prefect-worker prefect/prefect-worker -f values.yaml --set-file wor | worker.serverApiConfig.uiUrl | string | `"http://localhost:4200"` | prefect UI url | | worker.tolerations | list | `[]` | tolerations for worker pods assignment | +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1) diff --git a/charts/prometheus-prefect-exporter/README.md b/charts/prometheus-prefect-exporter/README.md index 423de37a..bf3a8a5e 100644 --- a/charts/prometheus-prefect-exporter/README.md +++ b/charts/prometheus-prefect-exporter/README.md @@ -89,3 +89,5 @@ Shoutout to @ialejandro for the original work on this chart! | serviceMonitor.enabled | bool | `false` | Enable or disable | | tolerations | list | `[]` | Tolerations for pod assignment | +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1) From 3a8f969230893f826bd9c087ea3fb749f0eca0e0 Mon Sep 17 00:00:00 2001 From: "Bai, Changhe" Date: Wed, 22 May 2024 16:20:21 -0400 Subject: [PATCH 5/5] no need to create a serviceType variable --- charts/prefect-server/templates/service.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/charts/prefect-server/templates/service.yaml b/charts/prefect-server/templates/service.yaml index 22c30e8d..dc092cb0 100644 --- a/charts/prefect-server/templates/service.yaml +++ b/charts/prefect-server/templates/service.yaml @@ -26,7 +26,6 @@ spec: {{- if eq .Values.service.type "NodePort" }} externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy | quote }} {{- end }} - {{- $serviceType := .Values.service.type }} ports: - name: server-svc-port port: {{ .Values.service.port }} @@ -42,9 +41,9 @@ spec: protocol: TCP port: {{ .port }} targetPort: {{ .targetPort }} - {{- if and (eq $serviceType "NodePort") (not (empty .nodePort)) }} + {{- if and (eq $.Values.service.type "NodePort") (not (empty .nodePort)) }} nodePort: {{ .nodePort }} - {{- else if eq $serviceType "ClusterIP" }} + {{- else if eq $.Values.service.type "ClusterIP" }} nodePort: null {{- end }} {{- end }}