def downgrade(upd, with_testing, exception, *args, **kwargs): # 00119 upd.print_log('Allow null in User.package_id field...') helpers.downgrade_db(revision='2c64986d76b9') # 00118 upd.print_log('Reverting package count_type column...') helpers.downgrade_db(revision='42b36be03945') # 00117 upd.print_log('Downgrade permissions...') Permission.query.delete() Resource.query.delete() add_permissions() db.session.commit() # 00116 upd.print_log('Remove system settings for CPU and Memory multipliers') for name in ('cpu_multiplier', 'memory_multiplier'): entry = SystemSettings.query.filter_by(name=name).first() if entry is not None: db.session.delete(entry) upd.print_log('Drop table "node_actions" if exists') table = Table('node_actions', db.metadata) table.drop(bind=db.engine, checkfirst=True) db.session.commit() helpers.close_all_sessions()
def do_cycle_updates(with_testing=False): """ :return: False if no errors or script name at which was error """ # TODO refactor to 'get next update' to_apply = get_available_updates() last = get_applied_updates() if last: # Start from last failed update to_apply = to_apply[to_apply.index(last[-1]) + 1:] if not to_apply: helpers.restart_service(settings.KUBERDOCK_SERVICE) helpers.set_maintenance(False) print 'There is no new upgrade scripts to apply. ' + \ SUCCESSFUL_UPDATE_MESSAGE return False is_failed = False for upd in to_apply: if not run_script(upd, with_testing): is_failed = upd print >> sys.stderr, "Update {0} has failed.".format(is_failed) break if not is_failed: helpers.close_all_sessions() print 'All update scripts are applied.' return is_failed
def upgrade(upd, with_testing, *args, **kwargs): from kubedock.pods.models import Pod upd.print_log('Changing pods name label to UUID') name_to_id_map = {(pod.name, pod.namespace): pod.id for pod in Pod.query.all()} _replace_labels(name_to_id_map, 'name', 'kuberdock-pod-uid') # to force reload of browser pages and update front-end assets helpers.close_all_sessions()
def upgrade(upd, with_testing, *args, **kwargs): # 00090_update.py upd.print_log('Update system settings scheme...') helpers.upgrade_db() redis = ConnectionPool.get_connection() billing_apps_link = SystemSettings.get_by_name('billing_apps_link') persitent_disk_max_size = SystemSettings.get_by_name('persitent_disk_max_size') # backup for downgrade if not redis.get('old_billing_apps_link'): redis.set('old_billing_apps_link', billing_apps_link or '', ex=int(timedelta(days=7).total_seconds())) if not redis.get('old_persitent_disk_max_size'): redis.set('old_persitent_disk_max_size', persitent_disk_max_size, ex=int(timedelta(days=7).total_seconds())) billing_url = (urlparse(billing_apps_link)._replace(path='', query='', params='').geturl() if billing_apps_link else None) SystemSettings.query.delete() add_system_settings() SystemSettings.set_by_name( 'persitent_disk_max_size', persitent_disk_max_size, commit=False) SystemSettings.set_by_name('billing_url', billing_url, commit=False) db.session.commit() # 00094_update.py upd.print_log('Drop table "node_missed_actions" if exists') table = Table('node_missed_actions', db.metadata) table.drop(bind=db.engine, checkfirst=True) db.session.commit() # 00095_update.py upd.print_log('Restart k8s2etcd service') upd.print_log(helpers.local('systemctl restart kuberdock-k8s2etcd')) # 00098_update.py copyfile('/var/opt/kuberdock/conf/sudoers-nginx.conf', '/etc/sudoers.d/nginx') local('chown nginx:nginx /etc/nginx/conf.d/shared-kubernetes.conf') local('chown nginx:nginx /etc/nginx/conf.d/shared-etcd.conf') helpers.close_all_sessions()
def upgrade(upd, with_testing, *args, **kwargs): upd.print_log('Upgrading DB...') helpers.upgrade_db() # 00116 upd.print_log('Add system settings for CPU and Memory multipliers') db.session.add_all([ SystemSettings(name='cpu_multiplier', value=CPU_MULTIPLIER, label='CPU multiplier', description='Cluster CPU multiplier', placeholder='Enter value for CPU multiplier'), SystemSettings(name='memory_multiplier', value=MEMORY_MULTIPLIER, label='Memory multiplier', description='Cluster Memory multiplier', placeholder='Enter value for Memory multiplier'), ]) upd.print_log('Create table for NodeAction model if not exists') NodeAction.__table__.create(bind=db.engine, checkfirst=True) db.session.commit() # 00117 upd.print_log('Update permissions...') Permission.query.delete() Resource.query.delete() add_permissions() db.session.commit() # Fix wrong pd_states if exists. wrong_states = db.session.query(PersistentDiskState).join( PersistentDisk, db.and_( PersistentDisk.name == PersistentDiskState.pd_name, PersistentDisk.owner_id == PersistentDiskState.user_id, PersistentDisk.state == PersistentDiskStatuses.DELETED)).filter( PersistentDiskState.end_time == None) for state in wrong_states: state.end_time = datetime.datetime.utcnow() db.session.commit() helpers.close_all_sessions()
def upgrade(upd, with_testing, *args, **kwargs): upgrade_db() # === 00124_update.py === # Move index file of k8s2etcd service from / to /var/lib/kuberdock try: stop_service(u124_service_name) if os.path.isfile(u124_old) and not os.path.isfile(u124_new): shutil.move(u124_old, u124_new) finally: start_service(u124_service_name) # === 00126_update.py === pod_collection = PodCollection() for pod_dict in pod_collection.get(as_json=False): pod = pod_collection._get_by_id(pod_dict['id']) db_config = get_pod_config(pod.id) cluster_ip = db_config.pop('clusterIP', None) if cluster_ip is None: service_name = db_config.get('service') if service_name is None: continue namespace = db_config.get('namespace') or pod.id service = KubeQuery().get(['services', service_name], ns=namespace) cluster_ip = service.get('spec', {}).get('clusterIP') if cluster_ip is not None: db_config['podIP'] = cluster_ip replace_pod_config(pod, db_config) # === 00127_update.py === upd.print_log('Upgrading menu...') MenuItemRole.query.delete() MenuItem.query.delete() Menu.query.delete() generate_menu() # === 00130_update.py === upd.print_log('Update permissions...') Permission.query.delete() Resource.query.delete() add_permissions() db.session.commit() # === 00135_update.py === # upd.print_log('Changing session_data schema...') # upgrade_db(revision='220dacf65cba') # === 00137_update.py === upd.print_log('Upgrading db...') # upgrade_db(revision='3c832810a33c') upd.print_log('Raise max kubes to 64') max_kubes = 'max_kubes_per_container' old_value = SystemSettings.get_by_name(max_kubes) if old_value == '10': SystemSettings.set_by_name(max_kubes, 64) upd.print_log('Update kubes') small = Kube.get_by_name('Small') standard = Kube.get_by_name('Standard') if small: small.cpu = 0.12 small.name = 'Tiny' small.memory = 64 if small.is_default and standard: small.is_default = False standard.is_default = True small.save() if standard: standard.cpu = 0.25 standard.memory = 128 standard.save() high = Kube.get_by_name('High memory') if high: high.cpu = 0.25 high.memory = 256 high.disk_space = 3 high.save() # === 00138_update.py === if not (CEPH or AWS): upgrade_localstorage_paths(upd) # === added later === secret_key = SystemSettings.query.filter( SystemSettings.name == 'sso_secret_key').first() if not secret_key.value: secret_key.value = randstr(16) secret_key.description = ( 'Used for Single sign-on. Must be shared between ' 'Kuberdock and billing system or other 3rd party ' 'application.') db.session.commit() upd.print_log('Close all sessions...') close_all_sessions()