diff options
author | Brenton Leanhardt <bleanhar@redhat.com> | 2016-02-28 16:32:38 -0500 |
---|---|---|
committer | Brenton Leanhardt <bleanhar@redhat.com> | 2016-03-03 09:05:42 -0500 |
commit | 7d561bd252a4ddc9e204f31144fbed7fecd99bff (patch) | |
tree | 372252fd59dfa4e1f576e54977375621858281d0 /roles/openshift_facts | |
parent | 6b25d27ca4ad9458688902d0c3e7c3a9c7b9c15d (diff) | |
download | openshift-7d561bd252a4ddc9e204f31144fbed7fecd99bff.tar.gz openshift-7d561bd252a4ddc9e204f31144fbed7fecd99bff.tar.bz2 openshift-7d561bd252a4ddc9e204f31144fbed7fecd99bff.tar.xz openshift-7d561bd252a4ddc9e204f31144fbed7fecd99bff.zip |
Correctly set the image tag for containerized installs (and upgrades)
Diffstat (limited to 'roles/openshift_facts')
-rwxr-xr-x | roles/openshift_facts/library/openshift_facts.py | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index 7b2715bb0..349b50976 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -713,7 +713,7 @@ def set_version_facts_if_unset(facts): """ if 'common' in facts: deployment_type = facts['common']['deployment_type'] - facts['common']['version'] = version = get_openshift_version() + facts['common']['version'] = version = get_openshift_version(facts) if version is not None: if deployment_type == 'origin': version_gte_3_1_or_1_1 = LooseVersion(version) >= LooseVersion('1.1.0') @@ -873,22 +873,65 @@ def get_current_config(facts): return current_config -def get_openshift_version(): +def get_openshift_version(facts, cli_image=None): """ Get current version of openshift on the host + Args: + facts (dict): existing facts + optional cli_image for pulling the version number + Returns: version: the current openshift version """ version = None + # No need to run this method repeatedly on a system if we already know the + # version + if 'common' in facts: + if 'version' in facts['common'] and facts['common']['version'] is not None: + return facts['common']['version'] + if os.path.isfile('/usr/bin/openshift'): _, output, _ = module.run_command(['/usr/bin/openshift', 'version']) - versions = dict(e.split(' v') for e in output.splitlines() if ' v' in e) - version = versions.get('openshift', '') + version = parse_openshift_version(output) + + if 'is_containerized' in facts['common'] and facts['common']['is_containerized']: + container = None + if 'master' in facts: + if 'cluster_method' in facts['master']: + container = facts['common']['service_type'] + '-master-api' + else: + container = facts['common']['service_type'] + '-master' + elif 'node' in facts: + container = facts['common']['service_type'] + '-node' + + if container is not None: + exit_code, output, _ = module.run_command(['docker', 'exec', container, 'openshift', 'version']) + # if for some reason the container is installed by not running + # we'll fall back to using docker run later in this method. + if exit_code == 0: + version = parse_openshift_version(output) + + if version is None and cli_image is not None: + # Assume we haven't installed the environment yet and we need + # to query the latest image + exit_code, output, _ = module.run_command(['docker', 'run', '--rm', cli_image, 'version']) + version = parse_openshift_version(output) - #TODO: acknowledge the possility of a containerized install return version +def parse_openshift_version(output): + """ Apply provider facts to supplied facts dict + + Args: + string: output of 'openshift version' + Returns: + string: the version number + """ + versions = dict(e.split(' v') for e in output.splitlines() if ' v' in e) + return versions.get('openshift', '') + + def apply_provider_facts(facts, provider_facts): """ Apply provider facts to supplied facts dict @@ -1093,6 +1136,8 @@ def set_container_facts_if_unset(facts): if bool(strtobool(str(facts['common']['is_containerized']))): facts['common']['admin_binary'] = '/usr/local/bin/oadm' facts['common']['client_binary'] = '/usr/local/bin/oc' + base_version = get_openshift_version(facts, cli_image).split('-')[0] + facts['common']['image_tag'] = "v" + base_version return facts |