|
| 1 | +{{- $appNs := .Values.rhaiOperator.applicationsNamespace -}} |
| 2 | +{{- $tls := .Values.gateway.tls -}} |
| 3 | +{{- $hostname := .Values.gateway.hostname -}} |
| 4 | +{{- $internalIssuer := eq $tls.issuerRef.name "rhai-ca-issuer" -}} |
| 5 | +{{- /* Internal secret name for the cert: created by Certificate, read by every gateway HTTPS listener. Not user-configurable. */ -}} |
| 6 | +{{- $certSecret := "inference-gateway-cert-secret" -}} |
| 7 | +set -euo pipefail |
| 8 | +TIMEOUT=300 |
| 9 | +INTERVAL=5 |
| 10 | + |
| 11 | +# Quoted once here so untrusted values can never reach the shell unquoted. |
| 12 | +APP_NAMESPACE={{ $appNs | quote }} |
| 13 | + |
| 14 | +# general wait function for resource to be ready in the cluster |
| 15 | +wait_for() { |
| 16 | + local desc="$1"; shift |
| 17 | + local elapsed=0 |
| 18 | + echo "Waiting for ${desc}..." |
| 19 | + until "$@" >/dev/null 2>&1; do |
| 20 | + if [ "$elapsed" -ge "$TIMEOUT" ]; then |
| 21 | + echo "ERROR: Timed out waiting for ${desc} after ${TIMEOUT}s" |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | + echo "${desc} not yet available, retrying in ${INTERVAL}s... (${elapsed}/${TIMEOUT}s)" |
| 25 | + sleep "$INTERVAL" |
| 26 | + elapsed=$((elapsed + INTERVAL)) |
| 27 | + done |
| 28 | + echo "${desc} is available." |
| 29 | +} |
| 30 | + |
| 31 | +# Readiness predicates for wait_for (only invoked when TLS is enabled). |
| 32 | +# ISSUER_ARGS is built in the TLS step below, before issuer_ready is called. |
| 33 | +issuer_ready() { |
| 34 | + [ "$(kubectl get "${ISSUER_ARGS[@]}" -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' 2>/dev/null)" = "True" ] |
| 35 | +} |
| 36 | +# Wait on the Certificate's Ready condition, not just Secret existence. |
| 37 | +cert_ready() { |
| 38 | + [ "$(kubectl get certificate inference-gateway-cert -n "$APP_NAMESPACE" -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' 2>/dev/null)" = "True" ] |
| 39 | +} |
| 40 | + |
| 41 | +echo "Step 1: Gateway API CRDs required by Gateway CR 'inference-gateway'..." |
| 42 | +wait_for "Gateway API CRDs" kubectl get crd gateways.gateway.networking.k8s.io |
| 43 | + |
| 44 | +echo "Step 2: cert-manager CA secret required by Gateway CR 'inference-gateway'..." |
| 45 | +wait_for "cert-manager CA secret" kubectl get secret rhai-ca -n cert-manager |
| 46 | + |
| 47 | +echo "Step 3: Creating CA bundle ConfigMap for Gateway CR 'inference-gateway'..." |
| 48 | +kubectl get secret rhai-ca -n cert-manager -o jsonpath='{.data.ca\.crt}' | base64 -d > /tmp/ca.crt |
| 49 | +kubectl create configmap rhai-ca-bundle --from-file=ca.crt=/tmp/ca.crt -n "$APP_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f - |
| 50 | +echo "CA bundle ConfigMap created." |
| 51 | + |
| 52 | +echo "Step 4: Create ConfigMap used by Gateway CR 'inference-gateway'..." |
| 53 | +kubectl apply -f - <<'EOF' |
| 54 | +apiVersion: v1 |
| 55 | +kind: ConfigMap |
| 56 | +metadata: |
| 57 | + name: inference-gateway-config |
| 58 | + namespace: {{ $appNs | quote }} |
| 59 | +data: |
| 60 | + deployment: | |
| 61 | + spec: |
| 62 | + template: |
| 63 | + spec: |
| 64 | + volumes: |
| 65 | + - name: rhai-ca-bundle |
| 66 | + configMap: |
| 67 | + name: rhai-ca-bundle |
| 68 | + containers: |
| 69 | + - name: istio-proxy |
| 70 | + volumeMounts: |
| 71 | + - name: rhai-ca-bundle |
| 72 | + mountPath: /var/run/secrets/rhai |
| 73 | + readOnly: true |
| 74 | +{{- if .Values.azure.enabled }} |
| 75 | + service: | |
| 76 | + metadata: |
| 77 | + annotations: |
| 78 | + service.beta.kubernetes.io/port_80_health-probe_protocol: tcp |
| 79 | +{{- end }} |
| 80 | +EOF |
| 81 | +echo "ConfigMap used by Gateway CR 'inference-gateway' created." |
| 82 | + |
| 83 | + |
| 84 | +{{- if $tls.enabled }} |
| 85 | +ISSUER_NAME={{ $tls.issuerRef.name | quote }} |
| 86 | +ISSUER_KIND={{ $tls.issuerRef.kind | lower | quote }} |
| 87 | +ISSUER_ARGS=("$ISSUER_KIND" "$ISSUER_NAME") |
| 88 | +{{- if eq $tls.issuerRef.kind "Issuer" }} |
| 89 | +ISSUER_ARGS+=(-n "$APP_NAMESPACE") |
| 90 | +{{- end }} |
| 91 | +wait_for "${ISSUER_KIND} ${ISSUER_NAME} to be Ready" issuer_ready |
| 92 | + |
| 93 | +{{- if and (not $internalIssuer) (not $hostname) (not $tls.additionalSANs) }} |
| 94 | +{{- fail "gateway.tls.issuerRef is non-default (external) but neither gateway.hostname nor gateway.tls.additionalSANs is set; the certificate would have no dnsNames" }} |
| 95 | +{{- end }} |
| 96 | +echo "Step 5: Creating Certificate for Gateway TLS..." |
| 97 | +{{- if and $hostname $internalIssuer }} |
| 98 | +echo "WARNING: gateway.hostname is set but issuerRef ${ISSUER_NAME} is the internal CA; the certificate is only trusted inside the cluster. Set gateway.tls.issuerRef to a public/enterprise issuer for external clients." |
| 99 | +{{- end }} |
| 100 | +kubectl apply -f - <<'EOF' |
| 101 | +apiVersion: cert-manager.io/v1 |
| 102 | +kind: Certificate |
| 103 | +metadata: |
| 104 | + name: inference-gateway-cert |
| 105 | + namespace: {{ $appNs | quote }} |
| 106 | +spec: |
| 107 | + secretName: {{ $certSecret | quote }} |
| 108 | + issuerRef: |
| 109 | + name: {{ $tls.issuerRef.name | quote }} |
| 110 | + kind: {{ $tls.issuerRef.kind | quote }} |
| 111 | + group: cert-manager.io |
| 112 | + dnsNames: |
| 113 | + {{- if $internalIssuer }} |
| 114 | + - "*.{{ $appNs }}.svc.cluster.local" |
| 115 | + - "*.{{ $appNs }}.svc" |
| 116 | + {{- end }} |
| 117 | + {{- if $hostname }} |
| 118 | + - {{ $hostname | quote }} |
| 119 | + {{- if hasPrefix "*." $hostname }} |
| 120 | + - {{ $hostname | trimPrefix "*." | quote }} |
| 121 | + {{- end }} |
| 122 | + {{- end }} |
| 123 | + {{- range $tls.additionalSANs }} |
| 124 | + - {{ . | quote }} |
| 125 | + {{- end }} |
| 126 | +EOF |
| 127 | +echo "Certificate 'inference-gateway-cert' created." |
| 128 | + |
| 129 | +wait_for "Certificate 'inference-gateway-cert' to be Ready" cert_ready |
| 130 | +{{- end }} |
| 131 | + |
| 132 | +echo "Step 6: GatewayClass 'istio' required by Gateway CR 'inference-gateway'..." |
| 133 | +wait_for "GatewayClass 'istio'" kubectl get gatewayclass istio |
| 134 | + |
| 135 | +echo "Step 7: Creating Gateway CR 'inference-gateway'..." |
| 136 | +kubectl apply -f - <<'EOF' |
| 137 | +apiVersion: gateway.networking.k8s.io/v1 |
| 138 | +kind: Gateway |
| 139 | +metadata: |
| 140 | + name: inference-gateway |
| 141 | + namespace: {{ $appNs | quote }} |
| 142 | +spec: |
| 143 | + gatewayClassName: istio |
| 144 | + listeners: |
| 145 | + - name: http |
| 146 | + port: 80 |
| 147 | + protocol: HTTP |
| 148 | +{{- if .Values.components.kserve.gateway.allowedRoutes.namespaces.from }} |
| 149 | +{{- include "rhai-on-xks-chart.gatewayAllowedRoutes" . | nindent 6 }} |
| 150 | +{{- end }} |
| 151 | +{{- if $tls.enabled }} |
| 152 | + - name: https |
| 153 | + port: 443 |
| 154 | + protocol: HTTPS |
| 155 | +{{- if .Values.components.kserve.gateway.allowedRoutes.namespaces.from }} |
| 156 | +{{- include "rhai-on-xks-chart.gatewayAllowedRoutes" . | nindent 6 }} |
| 157 | +{{- end }} |
| 158 | + tls: |
| 159 | + certificateRefs: |
| 160 | + - group: '' |
| 161 | + kind: Secret |
| 162 | + name: {{ $certSecret | quote }} |
| 163 | + mode: Terminate |
| 164 | +{{- end }} |
| 165 | + infrastructure: |
| 166 | + labels: |
| 167 | + serving.kserve.io/gateway: kserve-ingress-gateway |
| 168 | + parametersRef: |
| 169 | + group: "" |
| 170 | + kind: ConfigMap |
| 171 | + name: inference-gateway-config |
| 172 | +EOF |
| 173 | +echo "Gateway CR 'inference-gateway' created successfully." |
0 commit comments