Skip to content

Commit 316c788

Browse files
authored
fix(helm): derive grpcEndpoint from chart context (#1241)
* fix(helm): derive grpcEndpoint from chart context The chart hardcoded server.grpcEndpoint to https://openshell.openshell.svc.cluster.local:8080, which only matched the in-cluster Service DNS for the standard release name and namespace. A new helper now builds <scheme>://<fullname>.<namespace>.svc.cluster.local:<port> from chart context, picking the scheme from server.disableTls. An explicit server.grpcEndpoint override is passed through verbatim. * chore(scripts): validate k3d cluster name length early helm-k3s-local.sh derives the cluster name from the current branch suffix. Long branch names produced names exceeding k3d's 32-char cap and failed deep inside k3d cluster create with a confusing validation error. cmd_create now bails out before invoking docker/k3d with a copy-pasteable HELM_K3S_CLUSTER_NAME override hint. Status, start, stop, delete, and help remain unaffected so an over-long derived name does not block diagnostics.
1 parent eec949d commit 316c788

6 files changed

Lines changed: 36 additions & 6 deletions

File tree

deploy/helm/openshell/templates/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,19 @@ Namespaced Issuer (selfSigned) for cert-manager CA bootstrap.
8181
{{- define "openshell.issuerSelfSigned" -}}
8282
{{- printf "%s-selfsigned" (include "openshell.fullname" .) | trunc 63 | trimSuffix "-" }}
8383
{{- end }}
84+
85+
{{/*
86+
gRPC endpoint sandbox pods use to call back into the gateway. An explicit
87+
.Values.server.grpcEndpoint is used verbatim. Otherwise it is derived from
88+
the in-cluster Service DNS, release namespace, service port, and disableTls
89+
flag — so the default value works for any release name or namespace without
90+
override.
91+
*/}}
92+
{{- define "openshell.grpcEndpoint" -}}
93+
{{- if .Values.server.grpcEndpoint -}}
94+
{{- .Values.server.grpcEndpoint -}}
95+
{{- else -}}
96+
{{- $scheme := ternary "http" "https" (default false .Values.server.disableTls) -}}
97+
{{- printf "%s://%s.%s.svc.cluster.local:%d" $scheme (include "openshell.fullname" .) .Release.Namespace (int .Values.service.port) -}}
98+
{{- end -}}
99+
{{- end }}

deploy/helm/openshell/templates/statefulset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ spec:
7777
value: {{ .Values.supervisor.image.pullPolicy | quote }}
7878
{{- end }}
7979
- name: OPENSHELL_GRPC_ENDPOINT
80-
value: {{ if .Values.server.disableTls }}{{ .Values.server.grpcEndpoint | replace "https://" "http://" | quote }}{{ else }}{{ .Values.server.grpcEndpoint | quote }}{{ end }}
80+
value: {{ include "openshell.grpcEndpoint" . | quote }}
8181
{{- if .Values.server.sshGatewayHost }}
8282
- name: OPENSHELL_SSH_GATEWAY_HOST
8383
value: {{ .Values.server.sshGatewayHost | quote }}

deploy/helm/openshell/values.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ server:
8686
# (Always for :latest, IfNotPresent otherwise). Set to "Always" for dev
8787
# clusters so new images are picked up without manual eviction.
8888
sandboxImagePullPolicy: ""
89-
# gRPC endpoint for sandboxes to callback to OpenShell (must be reachable from pods)
90-
grpcEndpoint: "https://openshell.openshell.svc.cluster.local:8080"
89+
# gRPC endpoint sandboxes call back into the gateway. Leave empty to derive
90+
# it from the chart fullname, release namespace, service port, and
91+
# disableTls flag (i.e. <scheme>://<fullname>.<namespace>.svc.cluster.local:<port>).
92+
# Override only when sandboxes must reach the gateway via a different
93+
# hostname (e.g. an external ingress or a host alias).
94+
grpcEndpoint: ""
9195
# Public host/port returned to CLI clients for SSH proxy CONNECT requests.
9296
# For local clusters the default 127.0.0.1:8080 is correct; for remote
9397
# clusters these should be set to the externally reachable host and port.

deploy/kube/manifests/openshell-helmchart.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ spec:
3535
dbUrl: __DB_URL__
3636
sshGatewayHost: __SSH_GATEWAY_HOST__
3737
sshGatewayPort: __SSH_GATEWAY_PORT__
38-
grpcEndpoint: "https://openshell.openshell.svc.cluster.local:8080"
3938
hostGatewayIP: __HOST_GATEWAY_IP__
4039
disableGatewayAuth: __DISABLE_GATEWAY_AUTH__
4140
disableTls: __DISABLE_TLS__

examples/gateway-deploy-connect.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ kubectl create namespace openshell
1616
helm upgrade --install openshell deploy/helm/openshell \
1717
--namespace openshell \
1818
--set server.disableTls=true \
19-
--set service.type=ClusterIP \
20-
--set server.grpcEndpoint=http://openshell.openshell.svc.cluster.local:8080
19+
--set service.type=ClusterIP
2120
```
2221

2322
For local evaluation, forward the service and register the forwarded endpoint:

tasks/scripts/helm-k3s-local.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
2020
_branch="$(git -C "${ROOT}" rev-parse --abbrev-ref HEAD 2>/dev/null)" || _branch=""
2121
_suffix="$(printf '%s' "${_branch##*/}" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed 's/-*$//')"
2222
CLUSTER_NAME="${HELM_K3S_CLUSTER_NAME:-openshell-dev${_suffix:+-${_suffix}}}"
23+
# k3d caps cluster names at 32 chars; validated in cmd_create so the operator
24+
# gets an actionable hint instead of a deep-stack k3d validation error.
25+
K3D_CLUSTER_NAME_MAX=32
2326
# Host port forwarded to port 80 via the k3d load balancer.
2427
# Used by Envoy Gateway's LoadBalancer service (values-gateway.yaml).
2528
HOST_LB_PORT="${HELM_K3S_LB_HOST_PORT:-8080}"
@@ -154,6 +157,15 @@ cmd_create() {
154157
require_docker
155158
require_k3d
156159

160+
if (( ${#CLUSTER_NAME} > K3D_CLUSTER_NAME_MAX )); then
161+
cat >&2 <<EOF
162+
error: derived cluster name '${CLUSTER_NAME}' is ${#CLUSTER_NAME} chars; k3d caps at ${K3D_CLUSTER_NAME_MAX}.
163+
Set HELM_K3S_CLUSTER_NAME to a shorter name, e.g.:
164+
HELM_K3S_CLUSTER_NAME=openshell-dev-${_suffix:0:$(( K3D_CLUSTER_NAME_MAX - 14 ))} mise run helm:k3s:create
165+
EOF
166+
exit 1
167+
fi
168+
157169
local lb_port_map="${HOST_LB_PORT}:80@loadbalancer"
158170

159171
if k3d_cluster_exists; then

0 commit comments

Comments
 (0)