ソースを参照

Merge pull request #1377 from brenton/bz1302970

Bug 1302970 - update script does not patch router if name is differen…
Brenton Leanhardt 9 年 前
コミット
ceda016241

+ 28 - 0
filter_plugins/oo_filters.py

@@ -670,6 +670,33 @@ class FilterModule(object):
 
         return rpms_31
 
+    @staticmethod
+    def oo_pods_match_component(pods, deployment_type, component):
+        """ Filters a list of Pods and returns the ones matching the deployment_type and component
+        """
+        if not isinstance(pods, list):
+            raise errors.AnsibleFilterError("failed expects to filter on a list")
+        if not isinstance(deployment_type, basestring):
+            raise errors.AnsibleFilterError("failed expects deployment_type to be a string")
+        if not isinstance(component, basestring):
+            raise errors.AnsibleFilterError("failed expects component to be a string")
+
+        image_prefix = 'openshift/origin-'
+        if deployment_type in ['enterprise', 'online', 'openshift-enterprise']:
+            image_prefix = 'openshift3/ose-'
+        elif deployment_type == 'atomic-enterprise':
+            image_prefix = 'aep3_beta/aep-'
+
+        matching_pods = []
+        image_regex = image_prefix + component + r'.*'
+        for pod in pods:
+            for container in pod['spec']['containers']:
+                if re.search(image_regex, container['image']):
+                    matching_pods.append(pod)
+                    break # stop here, don't add a pod more than once
+
+        return matching_pods
+
     def filters(self):
         """ returns a mapping of filters to methods """
         return {
@@ -696,4 +723,5 @@ class FilterModule(object):
             "oo_persistent_volumes": self.oo_persistent_volumes,
             "oo_persistent_volume_claims": self.oo_persistent_volume_claims,
             "oo_31_rpm_rename_conversion": self.oo_31_rpm_rename_conversion,
+            "oo_pods_match_component": self.oo_pods_match_component,
         }

+ 25 - 11
playbooks/common/openshift-cluster/upgrades/v3_0_to_v3_1/upgrade.yml

@@ -74,6 +74,11 @@
 
   - set_fact:
       g_new_version: "{{ g_aos_versions.curr_version.split('-', 1).0 if g_aos_versions.avail_version is none else g_aos_versions.avail_version.split('-', 1).0 }}"
+    when: openshift_pkg_version is not defined
+
+  - set_fact:
+      g_new_version: "{{ openshift_pkg_version | replace('-','') }}"
+    when: openshift_pkg_version is defined
 
   - fail:
       msg: This playbook requires Origin 1.0.6 or later
@@ -567,46 +572,55 @@
   - role: openshift_examples
     openshift_examples_import_command: replace
   pre_tasks:
-  - name: Check for default router
+  - name: Collect all routers
     command: >
-      {{ oc_cmd }} get -n default dc/router
-    register: _default_router
+      {{ oc_cmd }} get pods --all-namespaces -l 'router' -o json
+    register: all_routers
     failed_when: false
     changed_when: false
 
+  - set_fact: haproxy_routers="{{ (all_routers.stdout | from_json)['items'] | oo_pods_match_component(openshift_deployment_type, 'haproxy-router') | oo_select_keys_from_list(['metadata']) }}"
+    when: all_routers.rc == 0
+
+  - set_fact: haproxy_routers=[]
+    when: all_routers.rc != 0
+
   - name: Check for allowHostNetwork and allowHostPorts
-    when: _default_router.rc == 0
+    when: all_routers.rc == 0
     shell: >
       {{ oc_cmd }} get -o yaml scc/privileged | /usr/bin/grep -e allowHostPorts -e allowHostNetwork
     register: _scc
 
   - name: Grant allowHostNetwork and allowHostPorts
     when:
-    - _default_router.rc == 0
+    - all_routers.rc == 0
     - "'false' in _scc.stdout"
     command: >
       {{ oc_cmd }} patch scc/privileged -p
       '{"allowHostPorts":true,"allowHostNetwork":true}' --api-version=v1
 
   - name: Update deployment config to 1.0.4/3.0.1 spec
-    when: _default_router.rc == 0
+    when: all_routers.rc == 0
     command: >
-      {{ oc_cmd }} patch dc/router -p
+      {{ oc_cmd }} patch dc/{{ item['labels']['deploymentconfig'] }} -p
       '{"spec":{"strategy":{"rollingParams":{"updatePercent":-10},"spec":{"serviceAccount":"router","serviceAccountName":"router"}}}}'
       --api-version=v1
+    with_items: haproxy_routers
 
   - name: Switch to hostNetwork=true
-    when: _default_router.rc == 0
+    when: all_routers.rc == 0
     command: >
-      {{ oc_cmd }} patch dc/router -p '{"spec":{"template":{"spec":{"hostNetwork":true}}}}'
+      {{ oc_cmd }} patch dc/{{ item['labels']['deploymentconfig'] }} -p '{"spec":{"template":{"spec":{"hostNetwork":true}}}}'
       --api-version=v1
+    with_items: haproxy_routers
 
   - name: Update router image to current version
-    when: _default_router.rc == 0
+    when: all_routers.rc == 0
     command: >
-      {{ oc_cmd }} patch dc/router -p
+      {{ oc_cmd }} patch dc/{{ item['labels']['deploymentconfig'] }} -p
       '{"spec":{"template":{"spec":{"containers":[{"name":"router","image":"{{ router_image }}"}]}}}}'
       --api-version=v1
+    with_items: haproxy_routers
 
   - name: Check for default registry
     command: >

+ 17 - 10
playbooks/common/openshift-cluster/upgrades/v3_1_minor/post.yml

@@ -20,13 +20,27 @@
   - role: openshift_examples
     openshift_examples_import_command: replace
   pre_tasks:
-  - name: Check for default router
+  - name: Collect all routers
     command: >
-      {{ oc_cmd }} get -n default dc/router
-    register: _default_router
+      {{ oc_cmd }} get pods --all-namespaces -l 'router' -o json
+    register: all_routers
     failed_when: false
     changed_when: false
 
+  - set_fact: haproxy_routers="{{ (all_routers.stdout | from_json)['items'] | oo_pods_match_component(openshift_deployment_type, 'haproxy-router') | oo_select_keys_from_list(['metadata']) }}"
+    when: all_routers.rc == 0
+
+  - set_fact: haproxy_routers=[]
+    when: all_routers.rc != 0
+
+  - name: Update router image to current version
+    when: all_routers.rc == 0
+    command: >
+      {{ oc_cmd }} patch dc/{{ item['labels']['deploymentconfig'] }} -p
+      '{"spec":{"template":{"spec":{"containers":[{"name":"router","image":"{{ router_image }}"}]}}}}'
+      --api-version=v1
+    with_items: haproxy_routers
+
   - name: Check for default registry
     command: >
       {{ oc_cmd }} get -n default dc/docker-registry
@@ -34,13 +48,6 @@
     failed_when: false
     changed_when: false
 
-  - name: Update router image to current version
-    when: _default_router.rc == 0
-    command: >
-      {{ oc_cmd }} patch dc/router -p
-      '{"spec":{"template":{"spec":{"containers":[{"name":"router","image":"{{ router_image }}"}]}}}}'
-      --api-version=v1
-
   - name: Update registry image to current version
     when: _default_registry.rc == 0
     command: >

+ 1 - 1
playbooks/common/openshift-cluster/upgrades/v3_1_minor/pre.yml

@@ -41,7 +41,7 @@
       g_new_service_name: "{{ 'origin' if deployment_type =='origin' else 'atomic-openshift' }}"
 
   - name: Determine available versions
-    script: ../files/versions.sh {{ g_new_service_name }} openshift
+    script: ../files/versions.sh {{ g_new_service_name }}
     register: g_versions_result
 
   - set_fact: