background jobs fix: ensure bucket is parsed correctly (#1359)

Follow-up to #1321 
- correctly parse the endpoint_url into prefix and bucket path
- also add region and s3 provider type to storage secrets
This commit is contained in:
Ilya Kreymer 2023-11-08 15:08:23 -08:00 committed by GitHub
parent ea5650f173
commit d2d7240455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 11 deletions

View File

@ -3,6 +3,8 @@ from datetime import datetime
from typing import Optional, Tuple, Union, List, Dict, TYPE_CHECKING, cast from typing import Optional, Tuple, Union, List, Dict, TYPE_CHECKING, cast
from uuid import UUID from uuid import UUID
from urllib.parse import urlsplit
from fastapi import APIRouter, Depends, HTTPException from fastapi import APIRouter, Depends, HTTPException
from .storages import StorageOps from .storages import StorageOps
@ -63,9 +65,9 @@ class BackgroundJobOps:
self.profile_ops = profile_ops self.profile_ops = profile_ops
def strip_bucket(self, endpoint_url: str) -> tuple[str, str]: def strip_bucket(self, endpoint_url: str) -> tuple[str, str]:
"""strip the last path segment (bucket) and return rest of endpoint""" """split the endpoint_url into the origin and return rest of endpoint as bucket path"""
inx = endpoint_url.rfind("/", 0, -1) + 1 parts = urlsplit(endpoint_url)
return endpoint_url[0:inx], endpoint_url[inx:] return parts.scheme + "://" + parts.netloc + "/", parts.path[1:]
async def handle_replica_job_finished(self, job: CreateReplicaJob) -> None: async def handle_replica_job_finished(self, job: CreateReplicaJob) -> None:
"""Update replicas in corresponding file objects, based on type""" """Update replicas in corresponding file objects, based on type"""

View File

@ -42,12 +42,21 @@ spec:
name: "{{ primary_secret_name }}" name: "{{ primary_secret_name }}"
key: STORE_SECRET_KEY key: STORE_SECRET_KEY
- name: RCLONE_CONFIG_PRIMARY_REGION
valueFrom:
secretKeyRef:
name: "{{ primary_secret_name }}"
key: STORE_REGION
- name: RCLONE_CONFIG_PRIMARY_PROVIDER
valueFrom:
secretKeyRef:
name: "{{ primary_secret_name }}"
key: STORE_S3_PROVIDER
- name: RCLONE_CONFIG_PRIMARY_ENDPOINT - name: RCLONE_CONFIG_PRIMARY_ENDPOINT
value: "{{ primary_endpoint }}" value: "{{ primary_endpoint }}"
#valueFrom:
# secretKeyRef:
# name: "{{ primary_secret_name }}"
# key: STORE_ENDPOINT_URL
{% endif %} {% endif %}
- name: RCLONE_CONFIG_REPLICA_TYPE - name: RCLONE_CONFIG_REPLICA_TYPE
@ -65,12 +74,20 @@ spec:
name: "{{ replica_secret_name }}" name: "{{ replica_secret_name }}"
key: STORE_SECRET_KEY key: STORE_SECRET_KEY
- name: RCLONE_CONFIG_REPLICA_REGION
valueFrom:
secretKeyRef:
name: "{{ replica_secret_name }}"
key: STORE_REGION
- name: RCLONE_CONFIG_REPLICA_PROVIDER
valueFrom:
secretKeyRef:
name: "{{ replica_secret_name }}"
key: STORE_S3_PROVIDER
- name: RCLONE_CONFIG_REPLICA_ENDPOINT - name: RCLONE_CONFIG_REPLICA_ENDPOINT
value: "{{ replica_endpoint }}" value: "{{ replica_endpoint }}"
#valueFrom:
# secretKeyRef:
# name: "{{ replica_secret_name }}"
# key: STORE_ENDPOINT_URL
{% if job_type == BgJobType.CREATE_REPLICA %} {% if job_type == BgJobType.CREATE_REPLICA %}
command: ["rclone", "-vv", "copyto", "--checksum", "primary:{{ primary_file_path }}", "replica:{{ replica_file_path }}"] command: ["rclone", "-vv", "copyto", "--checksum", "primary:{{ primary_file_path }}", "replica:{{ replica_file_path }}"]

View File

@ -67,5 +67,8 @@ stringData:
{{- end }} {{- end }}
STORE_ENDPOINT_NO_BUCKET_URL: "{{ $storage.endpoint_url }}" STORE_ENDPOINT_NO_BUCKET_URL: "{{ $storage.endpoint_url }}"
STORE_REGION: "{{ $storage.region }}"
STORE_S3_PROVIDER: {{ $storage.s3_provider | default "Other" }}
{{- end }} {{- end }}