Skip to content

Commit

Permalink
Merge pull request #5621 from dannyzaken/danny-work
Browse files Browse the repository at this point in the history
changed upgrade flow to better fit kuberentes
  • Loading branch information
dannyzaken authored Jul 17, 2019
2 parents b21ea02 + ddae177 commit 6476fb1
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 346 deletions.
3 changes: 2 additions & 1 deletion frontend/src/app/reducers/system-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ function onFailCollectSystemDiagnostics(state) {
function _mapUpgrade(payload) {
const { last_upgrade } = payload.upgrade;

// DZDZ - hardcoded initiator - not relevant anymore
return {
lastUpgrade: last_upgrade && {
time:last_upgrade.timestamp,
initiator: last_upgrade.last_initiator_email
initiator: '[email protected]'
}
};
}
Expand Down
9 changes: 2 additions & 7 deletions src/api/system_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,9 @@ module.exports = {
properties: {
timestamp: {
idate: true
},
last_initiator_email: { $ref: 'common_api#/definitions/email' },
}
}
},
can_upload_upgrade_package: {
type: 'string',
enum: ['NOT_ALL_MEMBERS_UP', 'NOT_ENOUGH_SPACE', 'VERSION_MISMATCH']
},
}
},
},
cluster: {
Expand Down
51 changes: 15 additions & 36 deletions src/deploy/NVA_build/noobaa_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,20 @@ update_services_autostart() {
mv ${NOOBAA_SUPERVISOR}.tmp ${NOOBAA_SUPERVISOR}
}

handle_unmanaged_upgrade() {
#Container specific logic
if grep -q PLATFORM=docker /data/.env; then
code_version=$(grep version ${NOOBAA_PACKAGE_PATH} | awk -F'["|"]' '{print $4}')
if [ ! -f ${NOOBAA_DATA_VERSION} ]; then
#New system, update data version file
echo ${code_version} > ${NOOBAA_DATA_VERSION}
else
data_version=$(cat ${NOOBAA_DATA_VERSION})
#verify if we need to start an un-managed upgrade
if [ "${code_version}" != "${data_version}" ]; then
logger -p local0.warn -t Superd "Code version ${code_version} differs from data version ${data_version}, initiating unmanaged upgrade"

#code version differs from data version, need to initiate un-managed upgrade
update_services_autostart
cat >> ${NOOBAA_SUPERVISOR} << EOF
[program:upgrade_manager]
stopsignal=KILL
priority=1
autostart=true
directory=/root/node_modules/noobaa-core/
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/1
stderr_logfile_maxbytes=0
command=/usr/local/bin/node src/upgrade/upgrade_manager.js --old_version ${data_version} --unmanaged true
#endprogram
EOF
fi
fi
fi
## upgrade flow if version is changed
handle_server_upgrade() {
cd /root/node_modules/noobaa-core/
# env UPGRADE_SCRIPTS_DIR can be used to override the default directory that holds upgrade scripts
if [ -z ${UPGRADE_SCRIPTS_DIR} ]
then
UPGRADE_SCRIPTS_DIR=/root/node_modules/noobaa-core/src/upgrade/upgrade_scripts
fi
/usr/local/bin/node src/upgrade/upgrade_manager.js --upgrade_scripts_dir ${UPGRADE_SCRIPTS_DIR}
rc=$?
if [ ${rc} -ne 0 ]; then
echo "upgrade_manager failed with exit code ${rc}"
exit ${rc}
fi
}

fix_non_root_user() {
Expand Down Expand Up @@ -143,10 +125,7 @@ init_noobaa_server() {
extract_noobaa_in_docker
prepare_server_pvs

#commented out handle_unmanaged_upgrade since upgrade flow is depndent on mongo shell that was removed
###TODO: restore handle_unmanaged_upgrade once the upgrade script does not rely on mongo shell
#check if unmamnaged upgrade is required
# handle_unmanaged_upgrade
handle_server_upgrade
}

init_noobaa_agent() {
Expand Down
7 changes: 7 additions & 0 deletions src/deploy/NVA_build/supervisord.orig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ start() {
path="/noobaa_init_files/"
fi
${path}/noobaa_init.sh
# abort pod start if noobaa_init fails
rc=$?
if [ ${rc} -ne 0 ]; then
echo "noobaa_init failed with exit code ${rc}. aborting"
exit ${rc}
fi


if [ ! -x "$SUPERVISORD" ]; then
echo "$SUPERVISORD is not executable."
Expand Down
64 changes: 55 additions & 9 deletions src/server/system_services/schemas/system_schema.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* Copyright (C) 2016 NooBaa */
'use strict';

const SensitiveString = require('../../../util/sensitive_string');

module.exports = {
id: 'system_schema',
type: 'object',
Expand Down Expand Up @@ -156,17 +154,65 @@ module.exports = {
}
},

//Last upgrade information
last_upgrade: {

current_version: {
type: 'string'
},

//history of past upgrades
upgrade_history: {
type: 'object',
properties: {
timestamp: {
idate: true
successful_upgrades: {
type: 'array',
items: {
type: 'object',
properties: {
timestamp: {
idate: true
},
from_version: {
type: 'string'
},
to_version: {
type: 'string'
},
// upgrade scripts that were run during the upgrade process
completed_scripts: {
type: 'array',
items: {
type: 'string'
}
}
}
}

},
initiator: {
wrapper: SensitiveString
last_failure: {
type: 'object',
properties: {
timestamp: {
idate: true
},
from_version: {
type: 'string'
},
to_version: {
type: 'string'
},
// upgrade scripts that were run during the upgrade process
completed_scripts: {
type: 'array',
items: {
type: 'string'
}
},
error: {
type: 'string'
}
}
}
}
},
}
}
};
29 changes: 8 additions & 21 deletions src/server/system_services/system_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ function new_system_defaults(name, owner_account_id) {
phone_home_upgraded: false,
phone_home_notified: false,
cap_terabytes: 20
},
current_version: pkg.version,
upgrade_history: {
successful_upgrades: [],
last_failure: undefined
}
};
return system;
Expand Down Expand Up @@ -504,9 +509,8 @@ function read_system(req) {
// dbg.log0('read_system: n2n_config.stun_servers', n2n_config.stun_servers);
// }

let last_upgrade = system.last_upgrade && {
timestamp: system.last_upgrade.timestamp,
last_initiator_email: system.last_upgrade.initiator
let last_upgrade = system.upgrade_history.successful_upgrades[0] && {
timestamp: system.upgrade_history.successful_upgrades[0].timestamp
};

const stats_by_bucket = _.keyBy(buckets_stats, stats => _.get(system_store.data.get_by_id(stats._id), 'name'));
Expand Down Expand Up @@ -578,10 +582,7 @@ function read_system(req) {
system_cap: system_cap,
has_ssl_cert: has_ssl_cert,
cluster: cluster_info,
upgrade: {
last_upgrade: last_upgrade,
can_upload_upgrade_package: _get_upgrade_availability_status(cluster_info)
},
upgrade: { last_upgrade },
defaults: {
tiers: {
data_frags: config.CHUNK_CODER_EC_DATA_FRAGS,
Expand All @@ -595,20 +596,6 @@ function read_system(req) {
});
}

function _get_upgrade_availability_status(cluster_info) {
// fill cluster information if we have a cluster.
const servers = _.flatMap(cluster_info.shards, shard => shard.servers);
const not_all_member_up = servers.some(server => server.status !== 'CONNECTED'); // Must be connected
const not_enough_space = servers.some(server => server.storage.free < config.MIN_MEMORY_FOR_UPGRADE); // Must have at least 300MB free
const version_mismatch = servers.some(server => server.version !== servers[0].version); // Must be of the same version.
return (
(not_all_member_up && 'NOT_ALL_MEMBERS_UP') ||
(not_enough_space && 'NOT_ENOUGH_SPACE') ||
(version_mismatch && 'VERSION_MISMATCH') ||
undefined
);
}

function update_system(req) {
var updates = _.pick(req.rpc_params, 'name');
updates._id = req.system._id;
Expand Down
Loading

0 comments on commit 6476fb1

Please sign in to comment.