mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-21 17:55:30 +01:00
Handle error in migrate script (#18664)
Dump the total amount of errors Signed-off-by: stonezdj <daojunz@vmware.com>
This commit is contained in:
parent
cf1af0d450
commit
44faccf01b
@ -4,9 +4,9 @@ ENV HELM_EXPERIMENTAL_OCI=1
|
||||
ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
COPY ./migrate_chart.py ./migrate_chart.sh /
|
||||
ADD https://get.helm.sh/helm-v3.2.4-linux-amd64.tar.gz /
|
||||
ADD https://get.helm.sh/helm-v3.9.1-linux-amd64.tar.gz /
|
||||
|
||||
RUN tar zxvf /helm-v3.2.4-linux-amd64.tar.gz && \
|
||||
RUN tar zxvf /helm-v3.9.1-linux-amd64.tar.gz && \
|
||||
pip install click==7.1.2 && \
|
||||
pip install requests==2.24.0 && \
|
||||
chmod +x /migrate_chart.sh ./migrate_chart.py
|
||||
|
@ -18,9 +18,12 @@ errs = []
|
||||
|
||||
def print_exist_errs():
|
||||
if errs:
|
||||
click.echo("Following errors exist", err=True)
|
||||
click.echo("There are {} errors exist".format(len(errs)), err=True)
|
||||
for e in errs:
|
||||
click.echo(e, err=True)
|
||||
# Write the error to file
|
||||
with open("/chart_storage/migration_errors.txt", "a") as f:
|
||||
f.write(e + "\n")
|
||||
|
||||
def graceful_exit(signum, frame):
|
||||
print_exist_errs()
|
||||
@ -36,14 +39,17 @@ class ChartV2:
|
||||
self.project = self.filepath.parts[-2]
|
||||
parts = self.filepath.stem.split('-')
|
||||
flag = False
|
||||
for i in range(len(parts)-1, -1, -1):
|
||||
if parts[i][0].isnumeric():
|
||||
self.name, self.version = '-'.join(parts[:i]), '-'.join(parts[i:])
|
||||
flag = True
|
||||
break
|
||||
if not flag:
|
||||
raise Exception('chart name: {} is illegal'.format('-'.join(parts)))
|
||||
|
||||
try:
|
||||
for i in range(len(parts)-1, -1, -1):
|
||||
if parts[i][0].isnumeric() or ((parts[i][0]=='v' or parts[i][0]=='v') and parts[i][1].isnumeric()) :
|
||||
self.name, self.version = '-'.join(parts[:i]), '-'.join(parts[i:])
|
||||
flag = True
|
||||
break
|
||||
if not flag:
|
||||
raise Exception('chart name: {} is illegal'.format('-'.join(parts)))
|
||||
except Exception as e:
|
||||
click.echo("Skipped chart: {} due to illegal chart name. Error: {}".format(filepath, e), err=True)
|
||||
return
|
||||
def __check_exist(self, hostname, username, password):
|
||||
return requests.get(CHART_URL_PATTERN.format(
|
||||
host=hostname,
|
||||
@ -59,11 +65,9 @@ class ChartV2:
|
||||
if res.status_code == 401:
|
||||
raise Exception(res.reason)
|
||||
|
||||
oci_ref = "{host}/{project}/{name}:{version}".format(
|
||||
oci_ref = "oci://{host}/{project}".format(
|
||||
host=hostname,
|
||||
project=self.project,
|
||||
name=self.name,
|
||||
version=self.version)
|
||||
project=self.project)
|
||||
|
||||
return subprocess.run([MIGRATE_CHART_SCRIPT, HELM_CMD, self.filepath, oci_ref],
|
||||
text=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
||||
@ -81,7 +85,7 @@ def migrate(hostname, username, password):
|
||||
raise Exception('This operation only allowed for admin')
|
||||
subprocess.run([CA_UPDATE_CMD])
|
||||
subprocess.run([HELM_CMD, 'registry', 'login', hostname, '--username', username, '--password', password])
|
||||
charts = [ChartV2(c) for p in CHART_SOURCE_DIR.iterdir() if p.is_dir() for c in p.iterdir() if c.is_file() and c.name != "index-cache.yaml"]
|
||||
charts = [ChartV2(c) for p in CHART_SOURCE_DIR.iterdir() if p.is_dir() for c in p.iterdir() if c.is_file() and c.name.endswith(".tgz")]
|
||||
with click.progressbar(charts, label="Migrating chart ...", length=len(charts),
|
||||
item_show_func=lambda x: "{}/{}:{} total errors: {}".format(x.project, x.name, x.version, len(errs)) if x else '') as bar:
|
||||
for chart in bar:
|
||||
|
4
tools/migrate_chart/migrate_chart.sh
Normal file → Executable file
4
tools/migrate_chart/migrate_chart.sh
Normal file → Executable file
@ -4,6 +4,4 @@ HELM_CMD=$1
|
||||
V2_CHART_PATH=$2
|
||||
OCI_REF=$3
|
||||
|
||||
${HELM_CMD} chart save ${V2_CHART_PATH} ${OCI_REF}
|
||||
${HELM_CMD} chart push ${OCI_REF}
|
||||
${HELM_CMD} chart remove ${OCI_REF}
|
||||
${HELM_CMD} push ${V2_CHART_PATH} ${OCI_REF}
|
||||
|
Loading…
Reference in New Issue
Block a user