mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-03 14:37:44 +01:00
Fix the bug: upgrade failed in VIC if replication policies exist
This commit is contained in:
parent
30152b19c1
commit
5f58c01e4a
@ -27,6 +27,7 @@ depends_on = None
|
|||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
from db_meta import *
|
from db_meta import *
|
||||||
|
import os
|
||||||
|
|
||||||
from sqlalchemy.dialects import mysql
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
@ -53,6 +54,15 @@ def upgrade():
|
|||||||
unenabled_policies = session.query(ReplicationPolicy).filter(ReplicationPolicy.enabled == 0)
|
unenabled_policies = session.query(ReplicationPolicy).filter(ReplicationPolicy.enabled == 0)
|
||||||
enabled_policies = session.query(ReplicationPolicy).filter(ReplicationPolicy.enabled == 1)
|
enabled_policies = session.query(ReplicationPolicy).filter(ReplicationPolicy.enabled == 1)
|
||||||
|
|
||||||
|
# As projects aren't stored in database of Harbor, migrate all replication
|
||||||
|
# policies with manual trigger
|
||||||
|
if os.getenv('WITH_ADMIRAL', '') == 'true':
|
||||||
|
print ("deployed with admiral, migrating all replication policies with manual trigger")
|
||||||
|
enabled_policies.update({
|
||||||
|
ReplicationPolicy.enabled: 1,
|
||||||
|
ReplicationPolicy.cron_str: '{"kind":"Manual"}'
|
||||||
|
})
|
||||||
|
else:
|
||||||
# migrate enabeld policies
|
# migrate enabeld policies
|
||||||
enabled_policies.update({
|
enabled_policies.update({
|
||||||
ReplicationPolicy.cron_str: '{"kind":"Immediate"}'
|
ReplicationPolicy.cron_str: '{"kind":"Immediate"}'
|
||||||
|
@ -6,6 +6,14 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
if sys.version_info[:3][0] == 2:
|
||||||
|
import ConfigParser as ConfigParser
|
||||||
|
import StringIO as StringIO
|
||||||
|
|
||||||
|
if sys.version_info[:3][0] == 3:
|
||||||
|
import configparser as ConfigParser
|
||||||
|
import io as StringIO
|
||||||
|
|
||||||
RC_VALIDATE = 101
|
RC_VALIDATE = 101
|
||||||
RC_UP = 102
|
RC_UP = 102
|
||||||
RC_DOWN = 103
|
RC_DOWN = 103
|
||||||
@ -17,8 +25,22 @@ RC_GEN = 110
|
|||||||
class DBMigrator():
|
class DBMigrator():
|
||||||
|
|
||||||
def __init__(self, target):
|
def __init__(self, target):
|
||||||
|
path = "/harbor-migration/harbor-cfg/harbor.cfg"
|
||||||
|
env = ""
|
||||||
|
if os.path.exists(path):
|
||||||
|
temp_section = "configuration"
|
||||||
|
conf = StringIO.StringIO()
|
||||||
|
conf.write("[%s]\n" % temp_section)
|
||||||
|
conf.write(open(path).read())
|
||||||
|
conf.seek(0, os.SEEK_SET)
|
||||||
|
rcp = ConfigParser.RawConfigParser()
|
||||||
|
rcp.readfp(conf)
|
||||||
|
if rcp.get(temp_section, "admiral_url") != "NA":
|
||||||
|
env = "WITH_ADMIRAL=true"
|
||||||
|
else:
|
||||||
|
print("harbor.cfg not found, WITH_ADMIRAL will not be set to true")
|
||||||
self.target = target
|
self.target = target
|
||||||
self.script = "./db/run.sh"
|
self.script = env + " ./db/run.sh"
|
||||||
|
|
||||||
def backup(self):
|
def backup(self):
|
||||||
return run_cmd(self.script + " backup") == 0
|
return run_cmd(self.script + " backup") == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user