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

Add agent readreplica resources #2258

Merged
merged 60 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3767c8b
Implement sample read replica rotation logic
ykadowak Nov 10, 2023
1e4a070
Add external-snapshotter in go.mod
ykadowak Nov 16, 2023
82c4d11
Add readreplica initial implementation
ykadowak Nov 16, 2023
875ce3b
Add service implementation of readreplica rotator
ykadowak Nov 20, 2023
9336760
Add readreplica rotate config
ykadowak Nov 20, 2023
747cf92
Refactor to read labels
ykadowak Nov 21, 2023
57812e2
replace id to _MY_TARGET_REPLICA_ID_
ykadowak Nov 22, 2023
4a48422
Add snapshot k8s client
ykadowak Nov 22, 2023
45cc8e4
Format
ykadowak Nov 22, 2023
bb14dab
Fix snapshot client initialization
ykadowak Nov 22, 2023
162a786
Add Apache License to main.go
ykadowak Nov 22, 2023
9a93754
Use GetConfigOrDie
ykadowak Nov 22, 2023
eed7522
Use internal/k8s client
ykadowak Nov 22, 2023
1fdd3d2
Refactor
ykadowak Nov 22, 2023
b6f93f2
Use controller-runtime for CRUD in readreplica
ykadowak Nov 24, 2023
b6d4580
Remove snapshot client and use controller-runtime
ykadowak Nov 24, 2023
945fe76
Move LabelSelector into internal/k8s
ykadowak Nov 24, 2023
79f7de5
Report error to span
ykadowak Nov 24, 2023
1c982ca
Merge branch 'main' into feature/example/readreplica
ykadowak Nov 24, 2023
167e704
Update go modules
ykadowak Nov 24, 2023
b4051ae
Remove old example
ykadowak Nov 24, 2023
2a5d358
Refactor
ykadowak Nov 24, 2023
7b3f428
Disable exhaustruct for now
ykadowak Nov 24, 2023
55e9b6a
Fix predeclared
ykadowak Nov 24, 2023
bebb04c
Fix stylecheck
ykadowak Nov 24, 2023
3e6f179
nolint:gomnd
ykadowak Nov 24, 2023
f212824
Add test template
ykadowak Nov 24, 2023
b5897c2
Add test for getNewBaseName
ykadowak Nov 24, 2023
cebb8c6
Add readreplica-rotate build scripts
ykadowak Nov 27, 2023
228a4a5
Add service account and clusterroles for read replica rotator
ykadowak Nov 28, 2023
484bb39
Merge branch 'main' into feature/readreplica/job
ykadowak Nov 28, 2023
21e93a2
Update charts
ykadowak Nov 28, 2023
d967ef6
Update comment
ykadowak Nov 28, 2023
b1c8eee
Add readreplica deployment templates
ykadowak Nov 28, 2023
c8b9760
Merge branch 'main' into feature/readreplica/job
ykadowak Nov 29, 2023
c3aec7f
Merge branch 'feature/readreplica/job' into feature/readreplica/deplo…
ykadowak Nov 29, 2023
03a1272
Add readreplica deployment template
ykadowak Dec 1, 2023
c433bd2
Add svc for readreplica
ykadowak Dec 1, 2023
c2dd64e
Merge branch 'main' into feature/readreplica/deployments
ykadowak Dec 4, 2023
fbe2e83
Update valdrelease
ykadowak Dec 4, 2023
4b6dcb6
Add podAntiAffinity for readreplica
ykadowak Dec 4, 2023
192f417
Add security context for readreplica
ykadowak Dec 4, 2023
374bf5c
Update valdrelease
ykadowak Dec 4, 2023
ff17dc2
Update valdrelease scheme
ykadowak Dec 4, 2023
1928481
Fix component name of readreplica so that svc can find it well
ykadowak Dec 4, 2023
4613818
Merge branch 'main' into feature/readreplica/deployments
ykadowak Dec 5, 2023
e08f67d
Change readreplica svc component name
ykadowak Dec 5, 2023
e65201e
Change headless to normal ClusterIP to do loadbalancing for readreplica
ykadowak Dec 5, 2023
08dbc73
Fix comment
ykadowak Dec 6, 2023
cd191e3
Parametarize some field in configmap
ykadowak Dec 6, 2023
960a5c8
Merge branch 'main' into feature/readreplica/deployments
ykadowak Dec 6, 2023
1d33eea
remove sidecar related things from readreplica deployment
ykadowak Dec 6, 2023
a5dd88a
Fix readreplica svc type to ClusterIP
ykadowak Dec 6, 2023
ec810fd
Update README.md
ykadowak Dec 6, 2023
74325da
Add networkpolicy
ykadowak Dec 7, 2023
4a5ecd4
Update docs
ykadowak Dec 7, 2023
a5ea4df
Update network policy selector label
ykadowak Dec 7, 2023
692ce67
Merge branch 'main' into feature/readreplica/deployments
ykadowak Dec 7, 2023
8abde31
Apply format
ykadowak Dec 7, 2023
3b9bb09
Merge branch 'main' into feature/readreplica/deployments
ykadowak Dec 7, 2023
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: 2 additions & 0 deletions Makefile.d/k8s.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ k8s/vald/deploy:
@echo "Permitting error because there's some cases nothing to apply"
kubectl apply -f $(TEMP_DIR)/vald/templates/manager/index || true
kubectl apply -f $(TEMP_DIR)/vald/templates/agent || true
kubectl apply -f $(TEMP_DIR)/vald/templates/agent/readreplica || true
kubectl apply -f $(TEMP_DIR)/vald/templates/discoverer || true
kubectl apply -f $(TEMP_DIR)/vald/templates/gateway/lb || true
kubectl apply -f $(TEMP_DIR)/vald/templates/index/job/correction || true
Expand Down Expand Up @@ -116,6 +117,7 @@ k8s/vald/delete:
kubectl delete -f $(TEMP_DIR)/vald/templates/gateway/lb
kubectl delete -f $(TEMP_DIR)/vald/templates/manager/index
kubectl delete -f $(TEMP_DIR)/vald/templates/discoverer
kubectl delete -f $(TEMP_DIR)/vald/templates/agent/readreplica || true
kubectl delete -f $(TEMP_DIR)/vald/templates/agent
rm -rf $(TEMP_DIR)

Expand Down
27 changes: 27 additions & 0 deletions charts/vald-helm-operator/crds/valdrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,27 @@ spec:
x-kubernetes-preserve-unknown-fields: true
progressDeadlineSeconds:
type: integer
readreplica:
type: object
properties:
enabled:
type: boolean
label_key:
type: string
name:
type: string
replica:
type: integer
service:
type: object
properties:
annotations:
type: object
x-kubernetes-preserve-unknown-fields: true
snapshot_classname:
type: string
volume_name:
type: string
resources:
type: object
properties:
Expand Down Expand Up @@ -8647,8 +8668,14 @@ spec:
properties:
enabled:
type: boolean
podSecurityContext:
type: object
x-kubernetes-preserve-unknown-fields: true
read_replica_id:
type: string
securityContext:
type: object
x-kubernetes-preserve-unknown-fields: true
server_config:
type: object
properties:
Expand Down
1,592 changes: 802 additions & 790 deletions charts/vald/README.md

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions charts/vald/templates/agent/readreplica/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
{{- $agent := .Values.agent -}}
{{- $readreplica := .Values.agent.readreplica -}}
{{- $defaults := .Values.defaults -}}
{{- $release := .Release -}}
{{- $chart := .Chart -}}
{{- $valdname := include "vald.name" . -}}
{{- $valdchart := include "vald.chart" . -}}
# if agent.enabled is true and agent.kind is StatefulSet and readreplica.enabled is true
# then create StatefulSet for agent and readreplica
{{- if and $agent.enabled (eq .Values.agent.kind "StatefulSet") $readreplica.enabled }}
{{ range $id := until (int $agent.minReplicas) }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $readreplica.name }}-{{ $id }}
labels:
app: {{ $readreplica.name }}-{{ $id }}
app.kubernetes.io/name: {{ $valdname }}
helm.sh/chart: {{ $valdchart }}
app.kubernetes.io/managed-by: {{ $release.Service }}
app.kubernetes.io/instance: {{ $release.Name }}
app.kubernetes.io/version: {{ $chart.Version }}
app.kubernetes.io/component: {{ $readreplica.component_name }}
{{ $readreplica.label_key }}: "{{ $id }}"
{{- if $agent.annotations }}
annotations:
{{- toYaml $agent.annotations | nindent 4 }}
{{- end }}
spec:
{{- if not $agent.hpa.enabled }}
replicas: {{ $readreplica.replica }}
{{- end }}
revisionHistoryLimit: {{ $agent.revisionHistoryLimit }}
selector:
matchLabels:
app: {{ $readreplica.name }}-{{ $id }}
template:
metadata:
creationTimestamp: null
labels:
app: {{ $readreplica.name }}-{{ $id }}
app.kubernetes.io/name: {{ $valdname }}
app.kubernetes.io/instance: {{ $release.Name }}
app.kubernetes.io/component: {{ $readreplica.component_name }}
{{- $pprof := default $defaults.server_config.metrics.pprof $agent.server_config.metrics.pprof }}
spec:
{{- if $agent.initContainers }}
initContainers:
{{- if $agent.initContainers }}
{{- $initContainers := dict "initContainers" $agent.initContainers "Values" .Values "namespace" .Release.Namespace -}}
{{- include "vald.initContainers" $initContainers | trim | nindent 8 }}
{{- end }}
{{- end }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- {{ $readreplica.name }}-{{ $id }}
topologyKey: kubernetes.io/hostname
weight: 100
{{- if $agent.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml $agent.topologySpreadConstraints | nindent 8 }}
{{- end }}
containers:
- name: {{ $agent.name }}
image: "{{ $agent.image.repository }}:{{ default $defaults.image.tag $agent.image.tag }}"
imagePullPolicy: {{ $agent.image.pullPolicy }}
{{- $servers := dict "Values" $agent.server_config "default" $defaults.server_config -}}
{{- include "vald.containerPorts" $servers | trim | nindent 10 }}
resources:
{{- toYaml $agent.resources | nindent 12 }}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
{{- if $agent.securityContext }}
securityContext:
{{- toYaml $agent.securityContext | nindent 12 }}
{{- end }}
{{- if $agent.env }}
env:
{{- toYaml $agent.env | nindent 12 }}
{{- end }}
volumeMounts:
- name: {{ $agent.name }}-config
mountPath: /etc/server/
{{- if not $agent.ngt.enable_in_memory_mode }}
{{- if $agent.ngt.index_path }}
{{- if $agent.persistentVolume.enabled }}
- name: {{ $readreplica.volume_name }}
mountPath: {{ dir $agent.ngt.index_path }}
mountPropagation: {{ $agent.persistentVolume.mountPropagation }}
{{- else }}
- name: {{ $agent.name }}-local
mountPath: {{ dir $agent.ngt.index_path }}
{{- end }}
{{- end }}
{{- end }}
{{- if $agent.volumeMounts }}
{{- toYaml $agent.volumeMounts | nindent 12 }}
{{- end }}
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
{{- if $agent.podSecurityContext }}
securityContext:
{{- toYaml $agent.podSecurityContext | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: {{ $agent.terminationGracePeriodSeconds }}
volumes:
- name: {{ $agent.name }}-config
configMap:
defaultMode: 420
name: {{ $agent.name }}-config
- name: {{ $readreplica.volume_name }}
persistentVolumeClaim:
claimName: {{ $readreplica.name }}-pvc-{{ $id }}
{{- if $agent.nodeName }}
nodeName: {{ $agent.nodeName }}
{{- end }}
{{- if $agent.nodeSelector }}
nodeSelector:
{{- toYaml $agent.nodeSelector | nindent 8 }}
{{- end }}
{{- if $agent.tolerations }}
tolerations:
{{- toYaml $agent.tolerations | nindent 8 }}
{{- end }}
{{- if $agent.podPriority }}
{{- if $agent.podPriority.enabled }}
priorityClassName: {{ $release.Namespace }}-{{ $agent.name }}-priority
{{- end }}
{{- end }}
{{- end }}
{{- end }}
79 changes: 79 additions & 0 deletions charts/vald/templates/agent/readreplica/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

{{- $agent := .Values.agent -}}
{{- $readreplica := .Values.agent.readreplica -}}
{{- $lb := .Values.gateway.lb -}}
{{- $index := .Values.manager.index -}}
{{- $corrector := .Values.manager.index.corrector -}}
{{- $creator := .Values.manager.index.creator -}}
{{- $saver := .Values.manager.index.saver -}}
{{- if .Values.defaults.networkPolicy.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: agent-readreplica-allow
spec:
podSelector:
matchLabels:
app.kubernetes.io/component: {{ $readreplica.component_name }}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Release.Namespace }}
podSelector:
matchLabels:
app: {{ $lb.name }}
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Release.Namespace }}
podSelector:
matchLabels:
app: {{ $index.name }}
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Release.Namespace }}
podSelector:
matchLabels:
app: {{ $corrector.name }}
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Release.Namespace }}
podSelector:
matchLabels:
app: {{ $creator.name }}
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Release.Namespace }}
podSelector:
matchLabels:
app: {{ $saver.name }}
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
39 changes: 39 additions & 0 deletions charts/vald/templates/agent/readreplica/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

{{- $agent := .Values.agent -}}
{{- $readreplica := .Values.agent.readreplica -}}
{{- if $readreplica.enabled }}
{{ range $id := until (int $agent.minReplicas) }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ $readreplica.name }}-pvc-{{ $id }}
labels:
{{ $readreplica.label_key }}: "{{ $id }}"
spec:
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 1Gi
dataSource:
name: {{ $readreplica.name }}-snapshot-{{ $id }}
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
{{- end }}
{{- end }}
33 changes: 33 additions & 0 deletions charts/vald/templates/agent/readreplica/snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
{{- $agent := .Values.agent -}}
{{- $readreplica := .Values.agent.readreplica -}}
{{- if $readreplica.enabled }}
{{ range $id := until (int $agent.minReplicas) }}
---
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
labels:
{{ $readreplica.label_key }}: "{{ $id }}"
name: {{ $readreplica.name }}-snapshot-{{ $id }}
spec:
volumeSnapshotClassName: csi-hostpath-snapclass
source:
# Specify the PVCs for which you want to take snapshots
persistentVolumeClaimName: {{ $agent.name }}-pvc-{{ $agent.name }}-{{ $id }}
{{- end }}
{{- end }}
Loading
Loading