From c298560ff539d23f60a83876feba83c970283ce7 Mon Sep 17 00:00:00 2001 From: Brenton Leanhardt Date: Wed, 13 Apr 2016 10:36:58 -0400 Subject: The openshift_docker role must set the version facts for containerized installs QE found that for fresh installs we were basing the docker version facts of the images that could be pulled prior to configuring /etc/sysconfig/docker. This is an edge case but something we need to fix. --- .../upgrades/v3_1_to_v3_2/upgrade.yml | 15 +++++++-- roles/etcd/meta/main.yml | 1 + roles/openshift_cli/defaults/main.yml | 2 +- roles/openshift_docker/tasks/main.yml | 28 ++++++++++++++++ roles/openshift_docker_facts/defaults/main.yml | 2 ++ roles/openshift_docker_facts/tasks/main.yml | 2 +- roles/openshift_facts/library/openshift_facts.py | 38 +++++----------------- roles/openshift_master/defaults/main.yml | 2 +- roles/openshift_node/defaults/main.yml | 2 +- 9 files changed, 55 insertions(+), 37 deletions(-) create mode 100644 roles/openshift_docker/tasks/main.yml create mode 100644 roles/openshift_docker_facts/defaults/main.yml diff --git a/playbooks/common/openshift-cluster/upgrades/v3_1_to_v3_2/upgrade.yml b/playbooks/common/openshift-cluster/upgrades/v3_1_to_v3_2/upgrade.yml index eb12fcabe..8852bb8de 100644 --- a/playbooks/common/openshift-cluster/upgrades/v3_1_to_v3_2/upgrade.yml +++ b/playbooks/common/openshift-cluster/upgrades/v3_1_to_v3_2/upgrade.yml @@ -10,14 +10,23 @@ tasks: - include: docker_upgrade.yml when: not openshift.common.is_atomic | bool + - name: Set post docker install facts + openshift_facts: + role: "{{ item.role }}" + local_facts: "{{ item.local_facts }}" + with_items: + - role: docker + local_facts: + openshift_image_tag: "v{{ g_new_version }}" + openshift_version: "{{ g_new_version }}" -# The cli image is used by openshift_facts to determine the currently installed +# The cli image is used by openshift_docker_facts to determine the currently installed # version. We need to explicitly pull the latest image to handle cases where # the locally cached 'latest' tag is older the g_new_version. - name: Download cli image hosts: oo_masters_to_config:oo_nodes_to_config roles: - - openshift_facts + - { role: openshift_docker_facts } tasks: - name: Pull Images command: > @@ -124,7 +133,7 @@ - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints hosts: oo_masters_to_config roles: - - { role: openshift_cli, openshift_image_tag: "v{{ g_new_version }}" } + - { role: openshift_cli, openshift_image_tag: "v{{ g_new_version }}" } vars: origin_reconcile_bindings: "{{ deployment_type == 'origin' and g_new_version | version_compare('1.0.6', '>') }}" ent_reconcile_bindings: true diff --git a/roles/etcd/meta/main.yml b/roles/etcd/meta/main.yml index a71b36237..36906b347 100644 --- a/roles/etcd/meta/main.yml +++ b/roles/etcd/meta/main.yml @@ -16,5 +16,6 @@ galaxy_info: - cloud - system dependencies: +- { role: openshift_docker } - { role: os_firewall } - { role: etcd_common } diff --git a/roles/openshift_cli/defaults/main.yml b/roles/openshift_cli/defaults/main.yml index 4d0c87497..7baa87ab8 100644 --- a/roles/openshift_cli/defaults/main.yml +++ b/roles/openshift_cli/defaults/main.yml @@ -1,2 +1,2 @@ --- -openshift_version: "{{ openshift_image_tag | default(openshift.common.image_tag) | default('') }}" +openshift_version: "{{ openshift_image_tag | default(openshift.docker.openshift_image_tag | default('')) }}" diff --git a/roles/openshift_docker/tasks/main.yml b/roles/openshift_docker/tasks/main.yml new file mode 100644 index 000000000..e5135520f --- /dev/null +++ b/roles/openshift_docker/tasks/main.yml @@ -0,0 +1,28 @@ +--- +# It's important that we don't explicitly pull this image here. Otherwise we +# could result in upgrading a preinstalled environment. We'll have to set +# openshift_image_tag correctly for upgrades. +- name: Set version when containerized + command: > + docker run --rm {{ openshift.common.cli_image }}:latest version + register: cli_image_version + when: openshift.common.is_containerized | bool and openshift_image_tag is not defined + +- set_fact: + l_image_tag: "{{ cli_image_version.stdout_lines[0].split(' ')[1].split('-')[0] }}" + when: openshift.common.is_containerized | bool and openshift_image_tag is not defined + +- set_fact: + l_image_tag: "{{ openshift_image_tag }}" + when: openshift.common.is_containerized | bool and openshift_image_tag is defined + +- name: Set post docker install facts + openshift_facts: + role: "{{ item.role }}" + local_facts: "{{ item.local_facts }}" + with_items: + - role: docker + local_facts: + openshift_image_tag: "{{ l_image_tag }}" + openshift_version: "{{ l_image_tag if l_image_tag is defined else '' | oo_image_tag_to_rpm_version }}" + when: openshift.common.is_containerized | bool diff --git a/roles/openshift_docker_facts/defaults/main.yml b/roles/openshift_docker_facts/defaults/main.yml new file mode 100644 index 000000000..7baa87ab8 --- /dev/null +++ b/roles/openshift_docker_facts/defaults/main.yml @@ -0,0 +1,2 @@ +--- +openshift_version: "{{ openshift_image_tag | default(openshift.docker.openshift_image_tag | default('')) }}" diff --git a/roles/openshift_docker_facts/tasks/main.yml b/roles/openshift_docker_facts/tasks/main.yml index 7ea359af1..075dbc145 100644 --- a/roles/openshift_docker_facts/tasks/main.yml +++ b/roles/openshift_docker_facts/tasks/main.yml @@ -49,7 +49,7 @@ when: not openshift.common.is_containerized | bool - set_fact: - l_common_version: "{{ openshift.common.image_tag | default('0.0', True) | oo_image_tag_to_rpm_version }}" + l_common_version: "{{ openshift_version | default('0.0', True) | oo_image_tag_to_rpm_version }}" when: openshift.common.is_containerized | bool - set_fact: diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index 6de2c1496..9218e12ae 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1048,7 +1048,7 @@ def get_docker_version_info(): } return result -def get_openshift_version(facts, cli_image=None): +def get_openshift_version(facts): """ Get current version of openshift on the host Args: @@ -1070,32 +1070,14 @@ def get_openshift_version(facts, cli_image=None): _, output, _ = module.run_command(['/usr/bin/openshift', 'version']) version = parse_openshift_version(output) + # openshift_facts runs before openshift_docker_facts. However, it will be + # called again and set properly throughout the playbook run. This could be + # refactored to simply set the openshift.common.version in the + # openshift_docker_facts role but it would take reworking some assumptions + # on how get_openshift_version is called. if 'is_containerized' in facts['common'] and safe_get_bool(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' - - # Try to get the version fromthe available cli image _before_ resorting - # to exec'ing in to the running container. This is to be more fault - # tolerant in environments where the container is not running. - 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, but only if docker is installed - if 'docker' in facts and 'version' in facts['docker']: - exit_code, output, _ = module.run_command(['docker', 'run', '--rm', cli_image, 'version']) - version = parse_openshift_version(output) - - if version is None and container is not None: - exit_code, output, _ = module.run_command(['docker', 'exec', container, 'openshift', 'version']) - # if for some reason the container is installed but not running - # we'll fall back to using docker run later in this method. - if exit_code == 0: - version = parse_openshift_version(output) + if 'docker' in facts and 'openshift_version' in facts['docker']: + version = facts['docker']['openshift_version'] return version @@ -1359,10 +1341,6 @@ def set_container_facts_if_unset(facts): if safe_get_bool(facts['common']['is_containerized']): facts['common']['admin_binary'] = '/usr/local/bin/oadm' facts['common']['client_binary'] = '/usr/local/bin/oc' - openshift_version = get_openshift_version(facts, cli_image) - if openshift_version is not None and openshift_version is not "": - base_version = openshift_version.split('-')[0] - facts['common']['image_tag'] = "v" + base_version return facts diff --git a/roles/openshift_master/defaults/main.yml b/roles/openshift_master/defaults/main.yml index afc81a414..6bf28ff2b 100644 --- a/roles/openshift_master/defaults/main.yml +++ b/roles/openshift_master/defaults/main.yml @@ -29,4 +29,4 @@ os_firewall_deny: - service: former etcd peer port port: 7001/tcp -openshift_version: "{{ openshift_pkg_version | default(openshift_image_tag) | default(openshift.common.image_tag) | default('') }}" +openshift_version: "{{ openshift_pkg_version | default(openshift_image_tag | default(openshift.docker.openshift_image_tag | default(''))) }}" diff --git a/roles/openshift_node/defaults/main.yml b/roles/openshift_node/defaults/main.yml index c4f718bfb..91aed7aa3 100644 --- a/roles/openshift_node/defaults/main.yml +++ b/roles/openshift_node/defaults/main.yml @@ -13,4 +13,4 @@ os_firewall_allow: - service: OpenShift OVS sdn port: 4789/udp when: openshift.node.use_openshift_sdn | bool -openshift_version: "{{ openshift_pkg_version | default(openshift_image_tag) | default(openshift.common.image_tag) | default('') }}" +openshift_version: "{{ openshift_pkg_version | default(openshift_image_tag | default(openshift.docker.openshift_image_tag | default(''))) }}" -- cgit v1.2.3 From 2342cb2f47050d430ff7fb07e68e9e42006884eb Mon Sep 17 00:00:00 2001 From: Brenton Leanhardt Date: Wed, 13 Apr 2016 14:22:46 -0400 Subject: Support mixed RPM/container installs --- roles/openshift_docker/tasks/main.yml | 8 ++++---- roles/openshift_node/tasks/main.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/openshift_docker/tasks/main.yml b/roles/openshift_docker/tasks/main.yml index e5135520f..23613b762 100644 --- a/roles/openshift_docker/tasks/main.yml +++ b/roles/openshift_docker/tasks/main.yml @@ -6,15 +6,15 @@ command: > docker run --rm {{ openshift.common.cli_image }}:latest version register: cli_image_version - when: openshift.common.is_containerized | bool and openshift_image_tag is not defined + when: openshift.common.is_containerized is defined and openshift.common.is_containerized | bool and openshift_image_tag is not defined - set_fact: l_image_tag: "{{ cli_image_version.stdout_lines[0].split(' ')[1].split('-')[0] }}" - when: openshift.common.is_containerized | bool and openshift_image_tag is not defined + when: openshift.common.is_containerized is defined and openshift.common.is_containerized | bool and openshift_image_tag is not defined - set_fact: l_image_tag: "{{ openshift_image_tag }}" - when: openshift.common.is_containerized | bool and openshift_image_tag is defined + when: openshift.common.is_containerized is defined and openshift.common.is_containerized | bool and openshift_image_tag is defined - name: Set post docker install facts openshift_facts: @@ -25,4 +25,4 @@ local_facts: openshift_image_tag: "{{ l_image_tag }}" openshift_version: "{{ l_image_tag if l_image_tag is defined else '' | oo_image_tag_to_rpm_version }}" - when: openshift.common.is_containerized | bool + when: openshift.common.is_containerized is defined and openshift.common.is_containerized | bool diff --git a/roles/openshift_node/tasks/main.yml b/roles/openshift_node/tasks/main.yml index eca4848c1..8987e0191 100644 --- a/roles/openshift_node/tasks/main.yml +++ b/roles/openshift_node/tasks/main.yml @@ -36,11 +36,11 @@ # We have to add tuned-profiles in the same transaction otherwise we run into depsolving # problems because the rpms don't pin the version properly. This was fixed in 3.1 packaging. - name: Install Node package - action: "{{ ansible_pkg_mgr }} name={{ openshift.common.service_type }}-node{{ openshift_version }},tuned-profiles-{{ openshift.common.service_type }}-node{{ openshift_version }} state=present" + action: "{{ ansible_pkg_mgr }} name={{ openshift.common.service_type }}-node{{ openshift_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }},tuned-profiles-{{ openshift.common.service_type }}-node{{ openshift_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }} state=present" when: not openshift.common.is_containerized | bool - name: Install sdn-ovs package - action: "{{ ansible_pkg_mgr }} name={{ openshift.common.service_type }}-sdn-ovs{{ openshift_version }} state=present" + action: "{{ ansible_pkg_mgr }} name={{ openshift.common.service_type }}-sdn-ovs{{ openshift_version | oo_image_tag_to_rpm_version(include_dash=True) }} state=present" when: openshift.common.use_openshift_sdn and not openshift.common.is_containerized | bool - name: Pull node image -- cgit v1.2.3