Skip to content

Commit

Permalink
Pass through service spec values
Browse files Browse the repository at this point in the history
  • Loading branch information
willmostly committed Dec 3, 2024
1 parent e91c024 commit 08aa1cd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
5 changes: 3 additions & 2 deletions charts/gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ A Helm chart for Trino Gateway
* `command` - list, default: `["java","-XX:MinRAMPercentage=80.0","-XX:MaxRAMPercentage=80.0","-jar","/usr/lib/trino/gateway-ha-jar-with-dependencies.jar","/etc/gateway/config.yaml"]`

Startup command for Trino Gateway process. Add additional Java options and other modifications as desired.
* `service.type` - string, default: `"ClusterIP"`
* `service.port` - int, default: `8080`
* `service` - object, default: `{"spec":{"ports":[{"name":"request","protocol":"TCP"}],"type":"ClusterIP"}}`

service for accessing the gateway. The `port` and `targetPort` of the first element of the ports list will automatically be set to the value of `config.serverConfig."http-server.http.port"`. Additional ports (for JMX or a Java Agent for example) can be configured by adding additional elements to the ports list. The selector is also automatically configured. All other values are passed through as is.
* `ingress.enabled` - bool, default: `false`
* `ingress.className` - string, default: `""`
* `ingress.annotations` - object, default: `{}`
Expand Down
20 changes: 8 additions & 12 deletions charts/gateway/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ You can get the Trino Gateway endpoints by running these commands:
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export REQUEST_NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath='{.spec.ports[?(@.name == "request")].nodePort}' services {{ include "trino-gateway.fullname" . }})
export APP_NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath='{.spec.ports[?(@.name == "app")].nodePort}' services {{ include "trino-gateway.fullname" . }})
export ADMIN_NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath='{.spec.ports[?(@.name == "admin")].nodePort}' services {{ include "trino-gateway.fullname" . }})
{{- else if contains "NodePort" .Values.service.spec.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath='{.spec.ports[0].nodePort}' services {{ include "trino-gateway.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath='{.items[0].status.addresses[0].address}')
echo http://$NODE_IP:$REQUEST_NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.spec.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "trino-gateway.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "trino-gateway.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
echo http://$SERVICE_IP:'{{ .Values.service.spec.ports | first | get "port" }}'
{{- else if contains "ClusterIP" .Values.service.spec.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "trino-gateway.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export REQUEST_PORT=$(kubectl get pod --namespace test $POD_NAME -o jsonpath='{.spec.containers[0].ports[?(@.name == "request")].containerPort}')
export APP_PORT=$(kubectl get pod --namespace test $POD_NAME -o jsonpath='{.spec.containers[0].ports[?(@.name == "app")].containerPort}')
export ADMIN_PORT=$(kubectl get pod --namespace test $POD_NAME -o jsonpath='{.spec.containers[0].ports[?(@.name == "admin")].containerPort}')
export PORT=$(kubectl get pod --namespace test $POD_NAME -o jsonpath='{.spec.containers[0].ports[0].containerPort}')
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$REQUEST_PORT
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$PORT
{{- end }}

Happy Helming!
21 changes: 13 additions & 8 deletions charts/gateway/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ metadata:
name: {{ include "trino-gateway.fullname" . }}
labels:
{{- include "trino-gateway.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ index .Values "config" "serverConfig" "http-server.http.port" }}
protocol: TCP
name: request
selector:
{{- include "trino-gateway.selectorLabels" . | nindent 4 }}
{{- $httpPort := index .Values "config" "serverConfig" "http-server.http.port" }}
{{- $portDefault := dict "port" $httpPort "targetPort" $httpPort }}
{{- $portValues := .Values.service.spec.ports | default list | first | default $portDefault}}
{{- $_0 := set $portValues "port" $httpPort}}
{{- $_1 := set $portValues "targetPort" $httpPort}}
{{- $ports := list $portValues }}
{{- $additionalPorts := .Values.service.spec.ports | default list | rest }}
{{- $allPorts := concat $ports $additionalPorts}}
{{- $spec := .Values.service.spec }}
{{- $_2 := set $spec "ports" $allPorts }}
{{- $selectorLabels := include "trino-gateway.selectorLabels" . | fromYaml }}
{{- $_3 := set $spec "selector" $selectorLabels }}
spec: {{ $spec | toYaml | nindent 2}}
11 changes: 9 additions & 2 deletions charts/gateway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,16 @@ command:
- "/usr/lib/trino/gateway-ha-jar-with-dependencies.jar"
- "/etc/gateway/config.yaml"

# -- service for accessing the gateway. The `port` and `targetPort` of the first element of the ports list will
# automatically be set to the value of `config.serverConfig."http-server.http.port"`. Additional ports (for JMX
# or a Java Agent for example) can be configured by adding additional elements to the ports list. The selector is
# also automatically configured. All other values are passed through as is.
service:
type: ClusterIP
port: 8080
spec:
type: ClusterIP
ports:
- protocol: TCP
name: request

ingress:
enabled: false
Expand Down

0 comments on commit 08aa1cd

Please sign in to comment.