-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
670 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{{- if and .Values.syncToS3.enabled .Values.serviceAccount.create }} | ||
{{- $fullName := include "op-geth.fullname" . }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: {{ include "op-geth.labels" . | nindent 4 }} | ||
rules: | ||
- apiGroups: [""] | ||
resources: | ||
- configmaps | ||
resourceNames: | ||
- {{ $fullName }}-s3-config | ||
verbs: | ||
- get | ||
- patch | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: {{ include "op-geth.labels" . | nindent 4 }} | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ $fullName }} | ||
namespace: {{ .Release.Namespace }} | ||
roleRef: | ||
kind: Role | ||
name: {{ $fullName }} | ||
apiGroup: rbac.authorization.k8s.io | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{- if or .Values.initFromS3.enabled .Values.syncToS3.enabled }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ include "op-geth.fullname" . }}-s3-config | ||
data: | ||
DATA_DIR: {{ tpl .Values.s3config.local.datadir . | quote }} | ||
INITIALIZED_FILE: {{ tpl .Values.s3config.local.initializedFile . | quote }} | ||
SYNC_TO_S3: "False" | ||
S3_BASE_URL: {{ tpl .Values.s3config.remote.baseUrl . }} | ||
FORCE_INIT: {{ ternary "True" "False" .Values.initFromS3.force | quote }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{{- if .Values.syncToS3.cronjob.enabled -}} | ||
{{- $fullName := print (include "op-geth.fullname" .) "-s3-cronjob" }} | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: {{ include "op-geth.labels" . | nindent 4 }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: {{ include "op-geth.labels" . | nindent 4 }} | ||
rules: | ||
- apiGroups: [""] | ||
resources: | ||
- pods | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- delete | ||
- apiGroups: [""] | ||
resources: | ||
- configmaps | ||
resourceNames: | ||
- {{ include "op-geth.fullname" . }}-s3-config | ||
verbs: | ||
- get | ||
- patch | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: {{ include "op-geth.labels" . | nindent 4 }} | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ $fullName }} | ||
namespace: {{ .Release.Namespace }} | ||
roleRef: | ||
kind: Role | ||
name: {{ $fullName }} | ||
apiGroup: rbac.authorization.k8s.io | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{{- if .Values.syncToS3.cronjob.enabled }} | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
name: {{ include "op-geth.fullname" . }}-sync-to-s3 | ||
labels: | ||
{{- include "op-geth.labels" . | nindent 4 }} | ||
spec: | ||
{{- with .Values.syncToS3.cronjob }} | ||
schedule: "{{ .schedule }}" | ||
concurrencyPolicy: Forbid | ||
startingDeadlineSeconds: 300 | ||
jobTemplate: | ||
metadata: | ||
name: {{ include "op-geth.fullname" $ }}-sync-to-s3 | ||
spec: | ||
activeDeadlineSeconds: 60 | ||
backoffLimit: 0 | ||
template: | ||
metadata: | ||
labels: | ||
{{- include "op-geth.labels" $ | nindent 12 }} | ||
spec: | ||
restartPolicy: OnFailure | ||
{{- with .imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 12 }} | ||
{{- end }} | ||
serviceAccountName: {{ include "op-geth.fullname" $ }}-s3-cronjob | ||
{{- with .podSecurityContext }} | ||
securityContext: | ||
{{- toYaml . | nindent 12 }} | ||
{{- end }} | ||
{{- with .nodeSelector }} | ||
nodeSelector: | ||
{{- toYaml . | nindent 12 }} | ||
{{- end }} | ||
{{- with .affinity }} | ||
affinity: | ||
{{- toYaml . | nindent 12 }} | ||
{{- end }} | ||
{{- with .tolerations }} | ||
tolerations: | ||
{{- toYaml . | nindent 12 }} | ||
{{- end }} | ||
containers: | ||
- name: enable-sync-to-s3 | ||
image: "{{ .image.repository }}:{{ .image.tag }}" | ||
imagePullPolicy: {{ .image.pullPolicy | quote }} | ||
{{- with .securityContext }} | ||
securityContext: | ||
{{- toYaml . | nindent 14 }} | ||
{{- end }} | ||
command: | ||
- /bin/sh | ||
- /scripts/s3-cron.sh | ||
- enable_sync | ||
- 5s | ||
volumeMounts: | ||
- name: scripts | ||
mountPath: /scripts | ||
{{- with .resources }} | ||
resources: | ||
{{- toYaml . | nindent 14 }} | ||
{{- end }} | ||
volumes: | ||
- name: scripts | ||
configMap: | ||
name: {{ include "op-geth.fullname" $ }}-scripts | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{- if or .Values.initFromS3.enabled .Values.syncToS3.enabled }} | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ include "op-geth.fullname" . }}-s3-secret | ||
data: | ||
{{- with .Values.s3config.remote }} | ||
{{- if .endpointUrl }} | ||
S3_ENDPOINT_URL: {{ .endpointUrl | toString | b64enc }} | ||
{{- end }} | ||
AWS_ACCESS_KEY_ID: {{ .accessKeyId | toString | b64enc }} | ||
AWS_SECRET_ACCESS_KEY: {{ .secretAccessKey | toString | b64enc }} | ||
{{- end }} | ||
{{- end }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env sh | ||
# shellcheck disable=SC2086,SC3037 | ||
|
||
set -e | ||
|
||
. /scripts/s3-env.sh | ||
|
||
process_inputs() { | ||
# download even if we are already initialized | ||
if [ "$FORCE_INIT" = "True" ]; then | ||
echo "Force init enabled, existing data will be deleted." | ||
rm -f "$INITIALIZED_FILE" | ||
fi | ||
# check for S3 credentials | ||
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then | ||
echo "S3 credentials are not provided, exiting"; exit 1 | ||
fi | ||
} | ||
|
||
progress() { | ||
remote_stats=$("$S5CMD" cat "s3://${STATS_URL}") | ||
case $1 in | ||
"start") | ||
while true; do | ||
inodes=$(df -Phi "$DATA_DIR" | tail -n 1 | awk '{print $3}') | ||
size=$(df -P -BG "$DATA_DIR" | tail -n 1 | awk '{print $3}')G | ||
echo -e "$(date -Iseconds) | SOURCE TOTAL ${remote_stats} | DST USED Inodes:\t${inodes} Size:\t${size}" | ||
sleep 2 | ||
done & | ||
progress_pid=$! ;; | ||
"stop") | ||
kill "$progress_pid" | ||
progress_pid=0 ;; | ||
"*") | ||
echo "Unknown arg" ;; | ||
esac | ||
} | ||
|
||
check_lockfile() { | ||
if "$S5CMD" cat "s3://${LOCKFILE_URL}" >/dev/null 2>&1; then | ||
echo "Found existing lockfile, snapshot might be corrupted. Aborting download.." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# stop all background tasks | ||
interrupt() { | ||
echo "Got interrupt signal, stopping..." | ||
for i in "$@"; do kill $i; done | ||
} | ||
|
||
sync() { | ||
# check if we are already initialized | ||
if [ -f "$INITIALIZED_FILE" ]; then | ||
echo "Blockchain already initialized. Exiting..." | ||
exit 0 | ||
fi | ||
# s5cmd does not support "true" sync, it does not save object's timestamps | ||
# so we cleanup local datadir on our own | ||
# https://github.com/peak/s5cmd/issues/532 | ||
echo "Cleaning up local data..." | ||
rm -rf "${DATA_DIR}" | ||
mkdir -p "${DATA_DIR}" | ||
|
||
echo "Starting download data from S3..." | ||
|
||
# handle interruption / termination | ||
trap 'interrupt ${progress_pid}' INT TERM | ||
progress start | ||
|
||
# download remote snapshot to an empty datadir | ||
time "$S5CMD" --stat --log error sync "s3://${S3_DATA_DIR}/*" "${DATA_DIR}/" | ||
progress stop | ||
|
||
# all done, mark as initialized | ||
touch "$INITIALIZED_FILE" | ||
} | ||
|
||
|
||
main() { | ||
process_inputs | ||
check_lockfile | ||
sync | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.