Skip to content

Agent Mesh

fix(helm): gate router/console startup on control-plane readiness

Antonio Ojea71a5115add81
diff --git a/charts/sam-mesh/templates/bootstrap-job.yaml b/charts/sam-mesh/templates/bootstrap-job.yaml
index aac41560..b49f3238 100644
--- a/charts/sam-mesh/templates/bootstrap-job.yaml
+++ b/charts/sam-mesh/templates/bootstrap-job.yaml
@@ -69,7 +69,7 @@ spec:
set -e
CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
K8S_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
- CP_URL="http://{{ include "sam-mesh.fullname" . }}-control-plane:8080"
+ CP_URL="http://{{ include "sam-mesh.fullname" . }}-control-plane:{{ .Values.controlPlane.service.port }}"
echo "Waiting for Control Plane to be ready..."
until curl -sf "${CP_URL}/info" > /dev/null; do
@@ -110,7 +110,7 @@ spec:
-d '{"role": "sam:role:router", "max_usages": 999999}' \
"${CP_URL}/admin/bootstrap-tokens")
- ROUTER_TOKEN=$(echo "${TOKEN_RESP}" | grep -o '"token":"[^"]*' | cut -d'"' -f4)
+ ROUTER_TOKEN=$(echo "${TOKEN_RESP}" | sed -n 's/.*"token"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')
if [ -z "${ROUTER_TOKEN}" ]; then
echo "Failed to extract router token from response: ${TOKEN_RESP}"
exit 1
diff --git a/charts/sam-mesh/templates/console-deployment.yaml b/charts/sam-mesh/templates/console-deployment.yaml
index 2887150b..3f5c2011 100644
--- a/charts/sam-mesh/templates/console-deployment.yaml
+++ b/charts/sam-mesh/templates/console-deployment.yaml
@@ -15,6 +15,19 @@ spec:
labels:
app: {{ include "sam-mesh.fullname" . }}-console
spec:
+ initContainers:
+ - name: wait-control-plane
+ image: curlimages/curl:8.6.0
+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}
+ command: ["/bin/sh", "-c"]
+ args:
+ - |
+ set -e
+ CP_URL="http://{{ include "sam-mesh.fullname" . }}-control-plane:{{ .Values.controlPlane.service.port }}"
+ until curl -sf "${CP_URL}/info" > /dev/null; do
+ echo "Control plane not ready yet, sleeping..."
+ sleep 2
+ done
containers:
- name: sam-console
image: "{{ .Values.console.image.repository }}:{{ .Values.global.imageTag }}"
diff --git a/charts/sam-mesh/templates/router-statefulset.yaml b/charts/sam-mesh/templates/router-statefulset.yaml
index 94c675c8..1176fb13 100644
--- a/charts/sam-mesh/templates/router-statefulset.yaml
+++ b/charts/sam-mesh/templates/router-statefulset.yaml
@@ -24,6 +24,19 @@ spec:
app: {{ include "sam-mesh.fullname" . }}-router
spec:
serviceAccountName: {{ include "sam-mesh.fullname" . }}-router-sa
+ initContainers:
+ - name: wait-control-plane
+ image: curlimages/curl:8.6.0
+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}
+ command: ["/bin/sh", "-c"]
+ args:
+ - |
+ set -e
+ CP_URL="http://{{ include "sam-mesh.fullname" . }}-control-plane:{{ .Values.controlPlane.service.port }}"
+ until curl -sf "${CP_URL}/info" > /dev/null; do
+ echo "Control plane not ready yet, sleeping..."
+ sleep 2
+ done
containers:
- name: sam-router
image: "{{ .Values.router.image.repository }}:{{ .Values.global.imageTag }}"
@@ -50,7 +63,7 @@ spec:
key: token
{{- end }}
args:
- - "--control-plane=http://{{ include "sam-mesh.fullname" . }}-control-plane:8080"
+ - "--control-plane=http://{{ include "sam-mesh.fullname" . }}-control-plane:{{ .Values.controlPlane.service.port }}"
- "--listen=/ip4/0.0.0.0/tcp/4501"
- "--listen=/ip4/0.0.0.0/udp/4501/quic-v1"
{{- if .Values.router.externalAddrs }}