Skip to content

Commit

Permalink
[castai-db-optimizer] multiple endpoints poc (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorasm authored Feb 27, 2025
1 parent 99f0362 commit 2df7402
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ $(addprefix docs-, $(CHART_NAMES)): docs-%: charts/%

# Add documentation for the dynamic docs targets to the help.
docs-<chart_name>: ## Generate helm docs for a specific chart, e.g., 'make docs-castai-agent'

gen-dbo: docs-castai-db-optimizer
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.16.1
version: 0.17.0
12 changes: 9 additions & 3 deletions charts/castai-db-optimizer/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# castai-db-optimizer

![Version: 0.16.1](https://img.shields.io/badge/Version-0.16.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![Version: 0.17.0](https://img.shields.io/badge/Version-0.17.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

CAST AI database cache deployment.

Expand All @@ -15,6 +15,12 @@ CAST AI database cache deployment.
| cacheGroupID | string | `""` | ID of the cache group for which cache configuration should be pulled. |
| commonAnnotations | object | `{}` | Annotations to add to all resources. |
| commonLabels | object | `{}` | Labels to add to all resources. |
| endpoints | list | `[{"hostname":"sample-db-hostname","name":null,"port":5433,"servicePort":5432,"targetPort":5432}]` | A list of upstream database endpoints |
| endpoints[0].hostname | string | `"sample-db-hostname"` | Hostname of the upstream database instance. |
| endpoints[0].name | string | `nil` | Name of the service. If this value is not empty, then additional cluster IP service will be deployed, using provided name as a suffix |
| endpoints[0].port | int | `5433` | Port for the endpoint on DBO pod. |
| endpoints[0].servicePort | int | `5432` | Port of the named service |
| endpoints[0].targetPort | int | `5432` | Port of the upstream database instance. |
| nodeSelector | object | `{}` | Pod node selector rules. Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ |
| podAnnotations | object | `{}` | Extra annotations to add to the pod. |
| podLabels | object | `{}` | Extra labels to add to the pod. |
Expand Down Expand Up @@ -50,8 +56,8 @@ CAST AI database cache deployment.
| resources.queryProcessor.cpu | string | `"2"` | |
| resources.queryProcessor.memory | string | `"1Gi"` | |
| tolerations | object | `{}` | Pod toleration rules. Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ |
| upstreamPostgresHostname | string | `""` | Hostname of the upstream Postgres instance. |
| upstreamPostgresPort | int | `5432` | Port of the upstream Postgres instance. |
| upstreamPostgresHostname | string | `""` | deprecated: Hostname of the upstream Postgres instance. |
| upstreamPostgresPort | int | `5432` | deprecated: Port of the upstream Postgres instance. |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
2 changes: 2 additions & 0 deletions charts/castai-db-optimizer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Define common labels.
{{- end }}
{{- end }}
app.kubernetes.io/managed-by: Helm
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/name: {{ include "name" . }}
helm.sh/chart: {{ include "chart" . }}
{{- end }}
Expand Down
14 changes: 11 additions & 3 deletions charts/castai-db-optimizer/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ spec:
- name: grpc
containerPort: 9050
protocol: TCP
- name: postgres
containerPort: 5432
protocol: TCP
- name: metrics
containerPort: 2112
protocol: TCP
Expand Down Expand Up @@ -141,6 +138,17 @@ spec:
exec:
command: ["sleep", {{ .Values.proxy.drainTimeSeconds | quote }} ]
{{- end}}
ports:
{{- if .Values.upstreamPostgresHostname }}
- name: postgres
containerPort: 5432
protocol: TCP
{{- end }}

{{- range $index, $endpoint := .Values.endpoints}}
- containerPort: {{$endpoint.port}}
protocol: TCP
{{- end }}
{{- if .Values.proxy.readinessProbeEnabled }}
readinessProbe:
periodSeconds: 3
Expand Down
99 changes: 99 additions & 0 deletions charts/castai-db-optimizer/templates/envoy_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ data:
static_resources:
listeners:
{{- if .Values.upstreamPostgresHostname}}
- name: castai_postgres_listener
address:
socket_address:
Expand Down Expand Up @@ -116,7 +117,75 @@ data:
name: 6 # the TCP_KEEPCNT parameter - The maximum number of keepalive probes TCP should send before dropping the connection
int_value: 2 # number of failed probes
state: STATE_PREBIND
{{- end}}
{{- range $index, $endpoint := .Values.endpoints}}
- name: endpoint_listener_{{$index}}
address:
socket_address:
address: 0.0.0.0
port_value: {{ $endpoint.port }}
filter_chains:
- filters:
{{- if $.Values.proxy.networkDebug | default false }}
- name: castai.filters.dump
typed_config:
"@type": type.googleapis.com/castai.filters.dump.v1.Dump
name: frontend_{{ $index }}
{{- end }}
- name: castai.filters.postgres
typed_config:
"@type": type.googleapis.com/castai.filters.postgres.v1.PostgresConfig
common:
stat_prefix: postgres
{{- if $.Values.proxy.networkDebug | default false }}
- name: castai.filters.dump
typed_config:
"@type": type.googleapis.com/castai.filters.dump.v1.Dump
name: backend_{{ $index }}
{{- end }}
- name: castai.filters.router
typed_config:
"@type": type.googleapis.com/castai.filters.router.v1.RouterConfig
tcp_proxy_config:
stat_prefix: proxy_egress_{{ $index }}
cluster: endpoint_upstream_{{ $index }}
idle_timeout: 0s
transport_socket:
name: envoy.transport_sockets.starttls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.starttls.v3.StartTlsConfig
tls_socket_config:
common_tls_context:
tls_certificates:
- certificate_chain:
filename: "cert.pem"
private_key:
filename: "key.pem"
socket_options:
- description: "enable keep-alive"
level: 1 # means socket level options
name: 9 # means the keep-alive parameter
int_value: 1 # a nonzero value means "yes"
state: STATE_PREBIND
- description: "idle time before first keep-alive probe is sent"
level: 6 # IPPROTO_TCP
name: 4 # TCP_KEEPIDLE parameter - The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes
int_value: 60 # seconds
state: STATE_PREBIND
- description: "keep-alive interval"
level: 6 # IPPROTO_TCP
name: 5 # the TCP_KEEPINTVL parameter - The time (in seconds) between individual keepalive probes.
int_value: 20 # seconds
state: STATE_PREBIND
- description: "keep-alive probes count"
level: 6 # IPPROTO_TCP
name: 6 # the TCP_KEEPCNT parameter - The maximum number of keepalive probes TCP should send before dropping the connection
int_value: 2 # number of failed probes
state: STATE_PREBIND
{{- end }}
clusters:
{{- if .Values.upstreamPostgresHostname}}
- name: postgres_upstream
type: LOGICAL_DNS
dns_lookup_family: ALL
Expand All @@ -143,6 +212,36 @@ data:
name: castai.upstream.pool
typed_config:
"@type": type.googleapis.com/castai.upstream.v1.CastaiConnectionPoolProto
{{- end }}
{{- range $index, $endpoint := .Values.endpoints}}
- name: endpoint_upstream_{{ $index }}
type: LOGICAL_DNS
dns_lookup_family: ALL
connect_timeout: 1s
load_assignment:
cluster_name: endpoint_upstream_{{ $index }}
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{ required "endpoint hostname must be provided" $endpoint.hostname }}
port_value: {{ required "endpoint targetPort is required" $endpoint.targetPort }}
transport_socket:
name: envoy.transport_sockets.start_tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.starttls.v3.UpstreamStartTlsConfig
tls_socket_config:
sni: {{ required "endpoint hostname must be provided" $endpoint.hostname }}
common_tls_context:
tls_params:
tls_maximum_protocol_version: TLSv1_3
upstream_config:
name: castai.upstream.pool
typed_config:
"@type": type.googleapis.com/castai.upstream.v1.CastaiConnectionPoolProto
{{- end }}
- name: {{ .Values.apiURL }}
type: LOGICAL_DNS
Expand Down
6 changes: 3 additions & 3 deletions charts/castai-db-optimizer/templates/headless-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ metadata:
spec:
clusterIP: None
ports:
- name: postgres
port: 5432
targetPort: postgres
- name: grpc
port: 9050
targetPort: grpc
protocol: TCP
selector:
{{- include "selectorLabels" . | nindent 4 }}
36 changes: 36 additions & 0 deletions charts/castai-db-optimizer/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ metadata:
{{- include "annotations" . | nindent 4 }}
spec:
ports:
{{- if .Values.upstreamPostgresHostname }}
- name: postgres
port: 5432
targetPort: postgres
protocol: TCP
{{- end}}
{{- range $index, $endpoint := .Values.endpoints}}
{{- if empty $endpoint.name }}
- name: endpoint-{{$index}}
port: {{$endpoint.port}}
targetPort: {{$endpoint.port}}
protocol: TCP
{{- end }}
{{- end }}
- name: grpc
port: 9050
targetPort: grpc
Expand All @@ -22,3 +32,29 @@ spec:
protocol: TCP
selector:
{{- include "selectorLabels" . | nindent 4 }}


# for each named port, define a named service
{{- range $index, $endpoint := .Values.endpoints}}
{{- if not ( empty $endpoint.name ) }}
---

apiVersion: v1
kind: Service
metadata:
name: {{ include "name" $ }}-{{$endpoint.name}}
labels:
{{- include "labels" $ | nindent 4 }}
annotations:
{{- include "annotations" $ | nindent 4 }}
spec:
ports:
- name: endpoint
port: {{$endpoint.servicePort}}
targetPort: {{$endpoint.port}}
protocol: TCP
selector:
{{- include "selectorLabels" $ | nindent 4 }}

{{- end }}
{{- end }}
19 changes: 17 additions & 2 deletions charts/castai-db-optimizer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,26 @@ resources:
cpu: "2"
memory: "1Gi"

# -- Hostname of the upstream Postgres instance.
# -- deprecated: Hostname of the upstream Postgres instance.
upstreamPostgresHostname: ""
# -- Port of the upstream Postgres instance.
# -- deprecated: Port of the upstream Postgres instance.
upstreamPostgresPort: 5432


# -- A list of upstream database endpoints
endpoints:
-
# -- Hostname of the upstream database instance.
hostname: sample-db-hostname
# -- Port for the endpoint on DBO pod.
port: 5433
# -- Port of the upstream database instance.
targetPort: 5432
# -- Name of the service. If this value is not empty, then additional cluster IP service will be deployed, using provided name as a suffix
name:
# -- Port of the named service
servicePort: 5432

proxy:
# -- Default proxy log level.
logLevel: "filter:info"
Expand Down

0 comments on commit 2df7402

Please sign in to comment.