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

Implement index operator logic for read replica rotation #2444

Merged
merged 44 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
79b8b71
Remove job reconciler
ykadowak Mar 8, 2024
c7e9ea8
Add leader election to index operator
ykadowak Mar 8, 2024
21a20b2
Add roles for leader election
ykadowak Mar 11, 2024
6e48b76
Add operator logic for rotation
ykadowak Mar 11, 2024
ee0653c
style: format code with Gofumpt and Prettier
deepsource-autofix[bot] Mar 11, 2024
407d03a
Remove unnecesary change
ykadowak Mar 11, 2024
aa06d04
Fix build
ykadowak Mar 11, 2024
45a01b2
nits
ykadowak Mar 11, 2024
32f4146
Refactor
ykadowak Mar 12, 2024
0460448
Fix clusterrole
ykadowak Mar 12, 2024
9fefa74
Move to podv2
ykadowak Mar 12, 2024
c4d44f6
Add job concurrency check
ykadowak Mar 12, 2024
0eb0707
Refactor
ykadowak Mar 12, 2024
e520d7e
Refactor
ykadowak Mar 12, 2024
ee1ec8c
Fix heavy copying
ykadowak Mar 12, 2024
fa8cd45
Update helm schema
ykadowak Mar 13, 2024
8149674
Fix package doc
ykadowak Mar 13, 2024
d4a19aa
Remove unused code and refactor For() method
ykadowak Mar 13, 2024
27a6133
Update target read replica ID in config
ykadowak Mar 13, 2024
dfaef5a
Update internal/k8s/podv2/option.go
ykadowak Mar 13, 2024
cd595c3
Refactor
ykadowak Mar 13, 2024
ccd5d6c
rename podv2 to v2/pod
ykadowak Mar 13, 2024
e526991
Add client DI
ykadowak Mar 13, 2024
22541b6
Fix envkey helper
ykadowak Mar 13, 2024
c626435
Set namespace from values.yaml
ykadowak Mar 13, 2024
992e930
Use annotations to specify the id
ykadowak Mar 13, 2024
4ce06c2
Update schema
ykadowak Mar 13, 2024
cb0ffea
Update sample
ykadowak Mar 13, 2024
6a74c76
Update values
ykadowak Mar 14, 2024
b3828f4
Update schema
ykadowak Mar 14, 2024
0dd26f0
Fix spelling
ykadowak Mar 14, 2024
7ddeaf7
Fix package name
ykadowak Mar 14, 2024
8664492
Fix read replica e2e
ykadowak Mar 14, 2024
8f8addc
Add job templates for rotation, creation, saving, and correction
ykadowak Mar 14, 2024
01ef06b
Update config.go to decode k8s object
ykadowak Mar 14, 2024
b046705
Update sample.yaml for index operator
ykadowak Mar 14, 2024
584d1f0
Use job template from cfg
ykadowak Mar 14, 2024
e19b2fb
style: format code with Gofumpt and Prettier
deepsource-autofix[bot] Mar 14, 2024
fb37942
Fix tagalign
ykadowak Mar 14, 2024
d209db0
Fix config test
ykadowak Mar 14, 2024
1b91f24
Fix config test
ykadowak Mar 14, 2024
ec8173f
Merge branch 'main' into feature/index-operator/rotation
ykadowak Mar 15, 2024
7957c81
Disable read replica e2e for now
ykadowak Mar 15, 2024
93d0f18
Merge branch 'main' into feature/index-operator/rotation
ykadowak Mar 15, 2024
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
4 changes: 0 additions & 4 deletions .github/helm/values/values-readreplica.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,3 @@ manager:
readreplica:
rotator:
enabled: true
initContainers: []
env:
- name: MY_TARGET_REPLICA_ID
value: "0"
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ jobs:
e2e-stream-crud-with-readreplica:
name: "E2E test (Stream CRUD) with read replica"
needs: [dump-contexts-to-log]
# FIXME: This job is disabled because it is not working properly for a moment.
# Needs to fix TestE2EReadReplica not to use CronJob since there is no CronJob for read replica anymore.
if: false
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
Expand Down
7 changes: 5 additions & 2 deletions charts/vald-helm-operator/crds/valdrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10064,6 +10064,9 @@ spec:
type: string
maxUnavailable:
type: string
rotation_job_concurrency:
type: integer
minimum: 1
securityContext:
type: object
x-kubernetes-preserve-unknown-fields: true
Expand Down Expand Up @@ -10726,8 +10729,6 @@ spec:
podSecurityContext:
type: object
x-kubernetes-preserve-unknown-fields: true
read_replica_id:
type: string
securityContext:
type: object
x-kubernetes-preserve-unknown-fields: true
Expand Down Expand Up @@ -11240,6 +11241,8 @@ spec:
type: boolean
name:
type: string
target_read_replica_id_annotations_key:
type: string
ttlSecondsAfterFinished:
type: integer
version:
Expand Down
1,901 changes: 951 additions & 950 deletions charts/vald/README.md

Large diffs are not rendered by default.

96 changes: 90 additions & 6 deletions charts/vald/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ If release name contains chart name it will be used as a full name.
{{- end -}}
{{- end -}}

{{/*
Create a envkey for read replica target id.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "vald.target_read_replica_envkey" -}}
{{- if .Values.fullnameOverride -}}
{{- printf "%s_%s" "TARGET_READREPLICA_ID" .Values.fullnameOverride | upper | replace "-" "_" | trunc 63 -}}
{{- else -}}
{{- printf "%s_%s_%s_%s" "TARGET_READREPLICA_ID" .Release.Name .Release.Namespace .Chart.Name | upper | replace "-" "_" | trunc 63 -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
Expand All @@ -35,13 +48,17 @@ Create chart name and version as used by the chart label.
Common labels
*/}}
{{- define "vald.labels" -}}
app.kubernetes.io/name: {{ include "vald.name" . }}
helm.sh/chart: {{ include "vald.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app: {{ .Values.name }}
app.kubernetes.io/name: {{ include "vald.name" .default }}
helm.sh/chart: {{ include "vald.chart" .default }}
app.kubernetes.io/managed-by: {{ .default.Release.Service }}
app.kubernetes.io/instance: {{ .default.Release.Name }}
app.kubernetes.io/component: {{ .Values.name }}
{{- if .default.Chart.AppVersion }}
app.kubernetes.io/version: {{ .default.Chart.AppVersion | quote }}
{{- else }}
app.kubernetes.io/version: {{ .default.Chart.Version }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Expand Down Expand Up @@ -848,3 +865,70 @@ service:
fields: {}
{{- end }}
{{- end -}}

{{/*
Vald index job templates
*/}}
{{- define "vald.index_job" -}}
spec:
ttlSecondsAfterFinished: {{ .Job.ttlSecondsAfterFinished }}
template:
metadata:
labels:
{{- include "vald.labels" (dict "Values" .Job "default" .default) | nindent 8 }}
annotations:
{{- $pprof := default .default.Values.defaults.server_config.metrics.pprof .Job.server_config.metrics.pprof -}}
{{- if $pprof.enabled }}
pyroscope.io/scrape: "true"
pyroscope.io/application-name: {{ .Job.name }}
pyroscope.io/profile-cpu-enabled: "true"
pyroscope.io/profile-mem-enabled: "true"
pyroscope.io/port: {{ $pprof.port | quote }}
{{- end }}
spec:
{{- if .Job.initContainers }}
initContainers:
{{- $initContainers := dict "initContainers" .Job.initContainers "Values" .default.Values "namespace" .default.Release.Namespace -}}
{{- include "vald.initContainers" $initContainers | trim | nindent 8 }}
{{- if .Job.securityContext }}
securityContext:
{{- toYaml .Job.securityContext | nindent 12 }}
{{- end }}
{{- end }}
containers:
- name: {{ .Job.name }}
image: "{{ .Job.image.repository }}:{{ default .default.Values.defaults.image.tag .Job.image.tag }}"
imagePullPolicy: {{ .Job.image.pullPolicy }}
volumeMounts:
- name: {{ .Job.name }}-config
mountPath: /etc/server/
{{- $servers := dict "Values" .Job.server_config "default" .default.Values.defaults.server_config -}}
{{- include "vald.containerPorts" $servers | trim | nindent 10 }}
{{- if .Job.securityContext }}
securityContext:
{{- toYaml .Job.securityContext | nindent 12 }}
{{- end }}
{{- if .Job.env }}
env:
{{- toYaml .Job.env | nindent 12 }}
{{- if eq .type "rotator" }}
- name: {{ include "vald.target_read_replica_envkey" .default }}
valueFrom:
fieldRef:
fieldPath: metadata.annotations['{{ .Job.target_read_replica_id_annotations_key }}']
{{- end }}
{{- end }}
{{- if .Job.podSecurityContext }}
securityContext:
{{- toYaml .Job.podSecurityContext | nindent 8 }}
{{- end }}
restartPolicy: OnFailure
volumes:
- name: {{ .Job.name }}-config
configMap:
defaultMode: 420
name: {{ .Job.name }}-config
{{- if .Job.serviceAccount }}
serviceAccountName: {{ .Job.serviceAccount.name }}
{{- end }}
{{- end -}}
17 changes: 17 additions & 0 deletions charts/vald/templates/discoverer/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rules:
- apiGroups:
- apps
resources:
- deployments
- replicasets
verbs:
- get
Expand All @@ -47,6 +48,12 @@ rules:
- get
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- nonResourceURLs:
- /metrics
verbs:
Expand All @@ -63,8 +70,18 @@ rules:
- batch
resources:
- jobs
- cronjobs
verbs:
- get
- list
- watch
- create
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- update
- create
{{- end }}
48 changes: 2 additions & 46 deletions charts/vald/templates/index/job/correction/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,12 @@ kind: CronJob
metadata:
name: {{ $corrector.name }}
labels:
app: {{ $corrector.name }}
app.kubernetes.io/name: {{ include "vald.name" . }}
helm.sh/chart: {{ include "vald.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.Version }}
{{- include "vald.labels" (dict "Values" $corrector "default" .) | nindent 10 }}
spec:
schedule: {{ $corrector.schedule | quote }}
concurrencyPolicy: Forbid
suspend: {{ $corrector.suspend }}
startingDeadlineSeconds: {{ $corrector.startingDeadlineSeconds }}
jobTemplate:
spec:
ttlSecondsAfterFinished: {{ $corrector.ttlSecondsAfterFinished }}
template:
metadata:
labels:
app: {{ $corrector.name }}
annotations:
{{- $pprof := default .Values.defaults.server_config.metrics.pprof $corrector.server_config.metrics.pprof -}}
{{- if $pprof.enabled }}
pyroscope.io/scrape: "true"
pyroscope.io/application-name: {{ $corrector.name }}
pyroscope.io/profile-cpu-enabled: "true"
pyroscope.io/profile-mem-enabled: "true"
pyroscope.io/port: {{ $pprof.port | quote }}
{{- end }}
spec:
{{- if $corrector.initContainers }}
initContainers:
{{- $initContainers := dict "initContainers" $corrector.initContainers "Values" .Values "namespace" .Release.Namespace -}}
{{- include "vald.initContainers" $initContainers | trim | nindent 12 }}
{{- end }}
containers:
- name: {{ $corrector.name }}
image: "{{ $corrector.image.repository }}:{{ default .Values.defaults.image.tag $corrector.image.tag }}"
imagePullPolicy: {{ $corrector.image.pullPolicy }}
volumeMounts:
- name: {{ $corrector.name }}-config
mountPath: /etc/server/
{{- $servers := dict "Values" $corrector.server_config "default" .Values.defaults.server_config -}}
{{- include "vald.containerPorts" $servers | trim | nindent 14 }}
{{- if $corrector.env }}
env:
{{- toYaml $corrector.env | nindent 16 }}
{{- end }}
restartPolicy: OnFailure
volumes:
- name: {{ $corrector.name }}-config
configMap:
defaultMode: 420
name: {{ $corrector.name }}-config
{{- include "vald.index_job" (dict "Job" $corrector "default" . "type" "corrector") | nindent 10 }}
{{- end }}
51 changes: 2 additions & 49 deletions charts/vald/templates/index/job/creation/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,12 @@ kind: CronJob
metadata:
name: {{ $creator.name }}
labels:
app: {{ $creator.name }}
app.kubernetes.io/name: {{ include "vald.name" . }}
helm.sh/chart: {{ include "vald.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.Version }}
{{- include "vald.labels" (dict "Values" $creator "default" .) | nindent 10 }}
spec:
schedule: {{ $creator.schedule | quote }}
concurrencyPolicy: Forbid
suspend: {{ $creator.suspend }}
startingDeadlineSeconds: {{ $creator.startingDeadlineSeconds }}
jobTemplate:
spec:
ttlSecondsAfterFinished: {{ $creator.ttlSecondsAfterFinished }}
template:
metadata:
labels:
app: {{ $creator.name }}
app.kubernetes.io/name: {{ include "vald.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: {{ $creator.name }}
annotations:
{{- $pprof := default .Values.defaults.server_config.metrics.pprof $creator.server_config.metrics.pprof -}}
{{- if $pprof.enabled }}
pyroscope.io/scrape: "true"
pyroscope.io/application-name: {{ $creator.name }}
pyroscope.io/profile-cpu-enabled: "true"
pyroscope.io/profile-mem-enabled: "true"
pyroscope.io/port: {{ $pprof.port | quote }}
{{- end }}
spec:
{{- if $creator.initContainers }}
initContainers:
{{- $initContainers := dict "initContainers" $creator.initContainers "Values" .Values "namespace" .Release.Namespace -}}
{{- include "vald.initContainers" $initContainers | trim | nindent 12 }}
{{- end }}
containers:
- name: {{ $creator.name }}
image: "{{ $creator.image.repository }}:{{ default .Values.defaults.image.tag $creator.image.tag }}"
imagePullPolicy: {{ $creator.image.pullPolicy }}
volumeMounts:
- name: {{ $creator.name }}-config
mountPath: /etc/server/
{{- $servers := dict "Values" $creator.server_config "default" .Values.defaults.server_config -}}
{{- include "vald.containerPorts" $servers | trim | nindent 14 }}
{{- if $creator.env }}
env:
{{- toYaml $creator.env | nindent 16 }}
{{- end }}
restartPolicy: OnFailure
volumes:
- name: {{ $creator.name }}-config
configMap:
defaultMode: 420
name: {{ $creator.name }}-config
{{- include "vald.index_job" (dict "Job" $creator "default" . "type" "creator") | nindent 10 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ data:
rotator:
agent_namespace: {{ $rotator.agent_namespace | quote }}
read_replica_label_key: {{ $agent.readreplica.label_key | quote }}
read_replica_id: "_MY_TARGET_REPLICA_ID_"
target_read_replica_id: _{{ include "vald.target_read_replica_envkey" . }}_
volume_name: {{ $agent.readreplica.volume_name | quote }}
{{- end }}
Loading
Loading