|
| 1 | +{{- $appNs := .Values.rhaiOperator.applicationsNamespace -}} |
| 2 | +{{- $tls := .Values.gateway.tls -}} |
| 3 | +{{- $maasGwNs := .Values.components.aigateway.modelsAsAService.gateway.namespace | default $appNs -}} |
| 4 | +{{- $maasGwName := .Values.components.aigateway.modelsAsAService.gateway.name -}} |
| 5 | +{{- $maasGwClass := .Values.components.aigateway.modelsAsAService.gateway.gatewayClassName -}} |
| 6 | +{{- $certSecret := "maas-gateway-cert-secret" -}} |
| 7 | +set -euo pipefail |
| 8 | +TIMEOUT=300 |
| 9 | +INTERVAL=5 |
| 10 | + |
| 11 | +APP_NAMESPACE={{ $appNs | quote }} |
| 12 | +MAAS_GW_NAMESPACE={{ $maasGwNs | quote }} |
| 13 | + |
| 14 | +wait_for() { |
| 15 | + local desc="$1"; shift |
| 16 | + local elapsed=0 |
| 17 | + echo "Waiting for ${desc}..." |
| 18 | + until "$@" >/dev/null 2>&1; do |
| 19 | + if [ "$elapsed" -ge "$TIMEOUT" ]; then |
| 20 | + echo "ERROR: Timed out waiting for ${desc} after ${TIMEOUT}s" |
| 21 | + exit 1 |
| 22 | + fi |
| 23 | + echo "${desc} not yet available, retrying in ${INTERVAL}s... (${elapsed}/${TIMEOUT}s)" |
| 24 | + sleep "$INTERVAL" |
| 25 | + elapsed=$((elapsed + INTERVAL)) |
| 26 | + done |
| 27 | + echo "${desc} is available." |
| 28 | +} |
| 29 | + |
| 30 | +maas_gw_cert_ready() { |
| 31 | + [ "$(kubectl get certificate maas-gateway-cert -n "$MAAS_GW_NAMESPACE" -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' 2>/dev/null)" = "True" ] |
| 32 | +} |
| 33 | + |
| 34 | +echo "=== MaaS Gateway Setup ===" |
| 35 | + |
| 36 | +echo "Step 1: Create MaaS gateway namespace..." |
| 37 | +kubectl create namespace "$MAAS_GW_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f - |
| 38 | + |
| 39 | +echo "Step 2: Create CA bundle ConfigMaps..." |
| 40 | +wait_for "cert-manager CA secret" kubectl get secret rhai-ca -n cert-manager |
| 41 | +kubectl get secret rhai-ca -n cert-manager -o jsonpath='{.data.ca\.crt}' | base64 -d > /tmp/ca.crt |
| 42 | +kubectl create configmap rhai-ca-bundle --from-file=ca.crt=/tmp/ca.crt -n "$APP_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f - |
| 43 | +kubectl create configmap rhai-ca-bundle --from-file=ca.crt=/tmp/ca.crt -n "$MAAS_GW_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f - |
| 44 | +echo "CA bundle ConfigMaps created." |
| 45 | + |
| 46 | +echo "Step 3: Create MaaS gateway config ConfigMap..." |
| 47 | +kubectl apply -f - <<'EOF' |
| 48 | +apiVersion: v1 |
| 49 | +kind: ConfigMap |
| 50 | +metadata: |
| 51 | + name: maas-gateway-config |
| 52 | + namespace: {{ $maasGwNs | quote }} |
| 53 | +data: |
| 54 | + deployment: | |
| 55 | + spec: |
| 56 | + template: |
| 57 | + spec: |
| 58 | + volumes: |
| 59 | + - name: rhai-ca-bundle |
| 60 | + configMap: |
| 61 | + name: rhai-ca-bundle |
| 62 | + containers: |
| 63 | + - name: istio-proxy |
| 64 | + volumeMounts: |
| 65 | + - name: rhai-ca-bundle |
| 66 | + mountPath: /var/run/secrets/opendatahub |
| 67 | + readOnly: true |
| 68 | + - name: rhai-ca-bundle |
| 69 | + mountPath: /var/run/secrets/rhai |
| 70 | + readOnly: true |
| 71 | +{{- if .Values.azure.enabled }} |
| 72 | + service: | |
| 73 | + metadata: |
| 74 | + annotations: |
| 75 | + service.beta.kubernetes.io/port_80_health-probe_protocol: tcp |
| 76 | +{{- end }} |
| 77 | +EOF |
| 78 | +echo "MaaS gateway ConfigMap created." |
| 79 | + |
| 80 | +{{- if $tls.enabled }} |
| 81 | +echo "Step 4: Create MaaS gateway TLS Certificate..." |
| 82 | +kubectl apply -f - <<'EOF' |
| 83 | +apiVersion: cert-manager.io/v1 |
| 84 | +kind: Certificate |
| 85 | +metadata: |
| 86 | + name: maas-gateway-cert |
| 87 | + namespace: {{ $maasGwNs | quote }} |
| 88 | +spec: |
| 89 | + secretName: {{ $certSecret | quote }} |
| 90 | + issuerRef: |
| 91 | + name: {{ $tls.issuerRef.name | quote }} |
| 92 | + kind: {{ $tls.issuerRef.kind | quote }} |
| 93 | + group: cert-manager.io |
| 94 | + dnsNames: |
| 95 | + - "*.{{ $maasGwNs }}.svc.cluster.local" |
| 96 | + - "*.{{ $maasGwNs }}.svc" |
| 97 | +EOF |
| 98 | +wait_for "MaaS gateway Certificate to be Ready" maas_gw_cert_ready |
| 99 | +{{- end }} |
| 100 | + |
| 101 | +echo "Step 5: Create MaaS API serving Certificate..." |
| 102 | +kubectl apply -f - <<'EOF' |
| 103 | +apiVersion: cert-manager.io/v1 |
| 104 | +kind: Certificate |
| 105 | +metadata: |
| 106 | + name: maas-api-serving-cert |
| 107 | + namespace: {{ $appNs | quote }} |
| 108 | +spec: |
| 109 | + secretName: maas-api-serving-cert |
| 110 | + issuerRef: |
| 111 | + name: {{ $tls.issuerRef.name | quote }} |
| 112 | + kind: {{ $tls.issuerRef.kind | quote }} |
| 113 | + group: cert-manager.io |
| 114 | + dnsNames: |
| 115 | + - "maas-api.{{ $appNs }}.svc" |
| 116 | + - "maas-api.{{ $appNs }}.svc.cluster.local" |
| 117 | +EOF |
| 118 | + |
| 119 | +echo "Step 6: Create MaaS Gateway..." |
| 120 | +kubectl apply -f - <<'EOF' |
| 121 | +apiVersion: gateway.networking.k8s.io/v1 |
| 122 | +kind: Gateway |
| 123 | +metadata: |
| 124 | + name: {{ $maasGwName | quote }} |
| 125 | + namespace: {{ $maasGwNs | quote }} |
| 126 | +spec: |
| 127 | + gatewayClassName: {{ $maasGwClass | quote }} |
| 128 | + listeners: |
| 129 | + - name: http |
| 130 | + port: 80 |
| 131 | + protocol: HTTP |
| 132 | +{{- if .Values.components.aigateway.modelsAsAService.gateway.allowedRoutes.namespaces.from }} |
| 133 | +{{- include "rhai-on-xks-chart.gatewayAllowedRoutes" (dict "allowedRoutes" .Values.components.aigateway.modelsAsAService.gateway.allowedRoutes) | nindent 6 }} |
| 134 | +{{- end }} |
| 135 | +{{- if $tls.enabled }} |
| 136 | + - name: https |
| 137 | + port: 443 |
| 138 | + protocol: HTTPS |
| 139 | +{{- if .Values.components.aigateway.modelsAsAService.gateway.allowedRoutes.namespaces.from }} |
| 140 | +{{- include "rhai-on-xks-chart.gatewayAllowedRoutes" (dict "allowedRoutes" .Values.components.aigateway.modelsAsAService.gateway.allowedRoutes) | nindent 6 }} |
| 141 | +{{- end }} |
| 142 | + tls: |
| 143 | + certificateRefs: |
| 144 | + - group: '' |
| 145 | + kind: Secret |
| 146 | + name: {{ $certSecret | quote }} |
| 147 | + mode: Terminate |
| 148 | +{{- end }} |
| 149 | + infrastructure: |
| 150 | + parametersRef: |
| 151 | + group: "" |
| 152 | + kind: ConfigMap |
| 153 | + name: maas-gateway-config |
| 154 | +EOF |
| 155 | +echo "MaaS Gateway created successfully." |
| 156 | + |
| 157 | +echo "Step 7: Copy pull secret to MaaS gateway namespace..." |
| 158 | +if kubectl get secret rhai-pull-secret -n "$APP_NAMESPACE" >/dev/null 2>&1; then |
| 159 | + DOCKER_CONFIG=$(kubectl get secret rhai-pull-secret -n "$APP_NAMESPACE" -o jsonpath='{.data.\.dockerconfigjson}') |
| 160 | + kubectl create secret generic rhai-pull-secret \ |
| 161 | + --from-literal=.dockerconfigjson="$(echo "$DOCKER_CONFIG" | base64 -d)" \ |
| 162 | + --type=kubernetes.io/dockerconfigjson \ |
| 163 | + -n "$MAAS_GW_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f - |
| 164 | + echo "Pull secret copied." |
| 165 | +else |
| 166 | + echo "No rhai-pull-secret found, skipping." |
| 167 | +fi |
| 168 | + |
| 169 | +echo "Step 8: Configure Authorino CA trust for MaaS API callbacks..." |
| 170 | +KUADRANT_NS="kuadrant-system" |
| 171 | +if kubectl get namespace "$KUADRANT_NS" >/dev/null 2>&1; then |
| 172 | + kubectl create configmap rhai-ca-bundle --from-file=ca.crt=/tmp/ca.crt \ |
| 173 | + -n "$KUADRANT_NS" --dry-run=client -o yaml | kubectl apply -f - |
| 174 | + |
| 175 | + kubectl patch deployment authorino -n "$KUADRANT_NS" --type=json -p='[ |
| 176 | + {"op":"add","path":"/spec/template/spec/volumes/-","value":{"name":"rhai-ca","configMap":{"name":"rhai-ca-bundle"}}}, |
| 177 | + {"op":"add","path":"/spec/template/spec/containers/0/volumeMounts/-","value":{"name":"rhai-ca","mountPath":"/etc/pki/tls/custom","readOnly":true}}, |
| 178 | + {"op":"add","path":"/spec/template/spec/containers/0/env/-","value":{"name":"SSL_CERT_FILE","value":"/etc/pki/tls/custom/ca.crt"}} |
| 179 | + ]' |
| 180 | + echo "Authorino CA trust configured." |
| 181 | +else |
| 182 | + echo "Kuadrant namespace not found, skipping Authorino CA trust." |
| 183 | +fi |
| 184 | + |
| 185 | +echo "=== MaaS Gateway setup complete ===" |
0 commit comments