Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[castai-db-optimizer] allow full api url #546

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/castai-db-optimizer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: castai-db-optimizer
description: CAST AI database cache deployment.
type: application
version: 0.1.3
version: 0.1.4
30 changes: 30 additions & 0 deletions charts/castai-db-optimizer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,33 @@ app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
helm.sh/chart: {{ include "chart" . }}
{{- end }}


{{- define "extractUrlComponents" -}}
{{- $url := . -}}
{{- $protocol := "unknown" -}}
{{- $host := "" -}}
{{- $port := "" -}}
{{- $tls := false -}}

{{- if hasPrefix "https://" $url -}}
{{- $protocol = "https" -}}
{{- $url = trimPrefix "https://" $url -}}
{{- $port = 443 -}}
{{- $tls = true -}}
{{- else if hasPrefix "http://" $url -}}
{{- $protocol = "http" -}}
{{- $url = trimPrefix "http://" $url -}}
{{- $port = 80 -}}
{{- end -}}

{{- $urlParts := split ":" $url -}}
{{- $host = index $urlParts "_0" -}}

{{- if gt (len $urlParts) 1 -}}
{{- $port = index $urlParts "_1" -}}
{{- end -}}

{{- $result := dict "url" . "protocol" $protocol "host" $host "port" $port "tls" $tls -}}
{{ $result | toYaml}}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/castai-db-optimizer/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spec:
- name: LOG_LEVEL
value: {{ required "log level must be provided" .Values.queryProcessor.logLevel }}
- name: API_URL
value: {{ required "apiURL must be provided" .Values.apiURL | printf "https://%s" }}
value: {{ required "apiURL must be provided" .Values.apiURL }}
- name: API_KEY
value: {{ .Values.apiKey | quote }}
- name: PROXY_METRICS_PORT
Expand Down
17 changes: 11 additions & 6 deletions charts/castai-db-optimizer/templates/envoy_config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{ $apiURL := (include "extractUrlComponents" .Values.apiURL | fromYaml) }}

apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -6,6 +8,7 @@ metadata:
{{- include "labels" . | nindent 4 }}
app.kubernetes.io/name: {{ include "name" . }}
data:

envoy-config.yaml: |-
node:
cluster: castai
Expand Down Expand Up @@ -35,7 +38,7 @@ data:
typed_config:
"@type": type.googleapis.com/castai.cluster_control.v1.ClusterControlConfig
path: /v1/dbo/cache-groups/{{ .Values.cacheGroupID | required ".Values.cacheGroupID is required." }}/cache-configurations
hostname: {{ .Values.apiURL }}
hostname: {{ $apiURL.host }}
api_key: {{ .Values.apiKey | quote }}
- name: "castai.grpc.services"
typed_config:
Expand Down Expand Up @@ -117,18 +120,19 @@ data:
address: 127.0.0.1
port_value: 1234

- name: {{ .Values.apiURL }}
- name: {{ $apiURL.host }}
type: LOGICAL_DNS
connect_timeout: 2s
load_assignment:
cluster_name: {{ .Values.apiURL }}
cluster_name: {{ $apiURL.host }}
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{ .Values.apiURL }}
port_value: 443
address: {{ $apiURL.host }}
port_value: {{ $apiURL.port }}
{{ if $apiURL.tls }}
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand All @@ -141,7 +145,8 @@ data:
filename: cert.pem
private_key:
filename: key.pem
sni: {{ .Values.apiURL }}
sni: {{ $apiURL.host }}
{{ end }}

- name: query_processor_service
type: LOGICAL_DNS
Expand Down
2 changes: 1 addition & 1 deletion charts/castai-db-optimizer/values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
replicas: 2

# apiURL -- URL to the CAST AI API server.
apiURL: "api.cast.ai"
apiURL: "https://api.cast.ai"

# apiKey -- Token to be used for authorizing access to the CAST AI API.
#
Expand Down
Loading