Browse Source

Merge pull request #7364 from fabianvf/bz1548641

Automatic merge from submit-queue.

Bug 1548641- upgrade now properly sets labels and selectors

https://bugzilla.redhat.com/show_bug.cgi?id=1548641
OpenShift Merge Robot 7 years ago
parent
commit
791a6eb304

+ 13 - 0
playbooks/common/openshift-cluster/upgrades/v3_9/label_nodes.yml

@@ -0,0 +1,13 @@
+---
+
+- name: Update node labels to differentiate from (now-schedulable) masters
+  hosts: oo_first_master
+  roles:
+    - openshift_facts
+    - lib_openshift
+  tasks:
+    - import_role:
+        name: openshift_manage_node
+        tasks_from: set_default_node_role.yml
+      vars:
+        openshift_master_host: '{{ groups.oo_first_master.0 }}'

+ 3 - 0
playbooks/common/openshift-cluster/upgrades/v3_9/upgrade_control_plane.yml

@@ -115,6 +115,8 @@
   - set_fact:
       pre_upgrade_complete: True
 
+- import_playbook: label_nodes.yml
+
 - import_playbook: ../upgrade_control_plane.yml
 
 # All controllers must be stopped at the same time then restarted
@@ -135,6 +137,7 @@
       enabled: true
     when: openshift.common.rolling_restart_mode == 'system'
 
+
 - import_playbook: ../post_control_plane.yml
 
 - hosts: oo_masters

+ 23 - 0
playbooks/init/basic_facts.yml

@@ -62,12 +62,35 @@
   roles:
   - role: openshift_facts
   tasks:
+  - when: not (osm_default_node_selector is defined)
+    block:
+    - stat:
+        path: "/etc/origin/master/master-config.yaml"
+      register: master_config_path_check
+
+    - slurp:
+        src: "/etc/origin/master/master-config.yaml"
+      register: openshift_master_config_encoded_contents
+      when: master_config_path_check.stat.exists
+
+    - set_fact:
+        openshift_master_config_node_selector: "{{ l_existing_config_master_config.projectConfig.defaultNodeSelector }}"
+      vars:
+        l_existing_config_master_config: "{{ (openshift_master_config_encoded_contents.content | b64decode | from_yaml) }}"
+      when:
+      - master_config_path_check.stat.exists
+      - l_existing_config_master_config.projectConfig is defined
+      - l_existing_config_master_config.projectConfig.defaultNodeSelector is defined
+      - l_existing_config_master_config.projectConfig.defaultNodeSelector != ''
+
   - set_fact:
       # We need to setup openshift_client_binary here for special uses of delegate_to in
       # later roles and plays.
       first_master_client_binary: "{{  openshift_client_binary }}"
       #Some roles may require this to be set for first master
       openshift_client_binary: "{{ openshift_client_binary }}"
+      # we need to know if a default node selector has been manually set outside the installer
+      l_osm_default_node_selector: '{{ osm_default_node_selector | default(openshift_master_config_node_selector) | default("node-role.kubernetes.io/compute=true") }}'
 
 - name: Disable web console if required
   hosts: oo_masters_to_config

+ 2 - 0
roles/openshift_manage_node/tasks/config.yml

@@ -25,3 +25,5 @@
     l_node_labels: "{{ openshift_node_labels | default({}) }}"
     l_master_labels: "{{ openshift_manage_node_is_master | ternary(openshift_master_node_labels, {}) }}"
     l_all_labels: "{{ l_node_labels | combine(l_master_labels) }}"
+
+- import_tasks: set_default_node_role.yml

+ 20 - 0
roles/openshift_manage_node/tasks/set_default_node_role.yml

@@ -0,0 +1,20 @@
+---
+
+- delegate_to: '{{ openshift_master_host }}'
+  block:
+    - name: Retrieve non-infra, non-master nodes that are not yet labeled compute
+      oc_obj:
+        state: list
+        kind: Node
+        selector: '{{ (openshift_hosted_infra_selector | default("region=infra")) | regex_replace("=", "!=") }},node-role.kubernetes.io/master!=true,node-role.kubernetes.io/compute!=true'
+      register: non_master_non_infra_nodes_result
+
+    - name: label non-master non-infra nodes compute
+      oc_label:
+        name: '{{ item }}'
+        kind: node
+        state: add
+        labels:
+          - key: node-role.kubernetes.io/compute
+            value: 'true'
+      with_items: "{{ non_master_non_infra_nodes_result.results.results.0['items'] | map(attribute='metadata') | map(attribute='name') | list }}"

+ 0 - 1
roles/openshift_master/defaults/main.yml

@@ -22,7 +22,6 @@ system_images_registry: "{{ system_images_registry_dict[openshift_deployment_typ
 l_is_master_system_container: "{{ (openshift_use_master_system_container | default(openshift_use_system_containers | default(false)) | bool) }}"
 
 openshift_master_dns_port: 8053
-osm_default_node_selector: ''
 osm_project_request_template: ''
 osm_mcs_allocator_range: 's0:/2'
 osm_mcs_labels_per_project: 5

+ 7 - 0
roles/openshift_master/tasks/upgrade.yml

@@ -43,3 +43,10 @@
     key: 'imageConfig.format'
     value: "{{ oreg_url | default(oreg_url_master) }}"
   when: oreg_url is defined or oreg_url_master is defined
+
+- name: Change default node selector to compute=true
+  yedit:
+    path: "{{ openshift.common.config_base }}/master/master-config.yaml"
+    key: 'projectConfig.defaultNodeSelector'
+    value: '{{ hostvars[groups.oo_first_master.0].l_osm_default_node_selector }}'
+  when: openshift_upgrade_target | version_compare('3.9' '>=')

+ 1 - 1
roles/openshift_master/templates/master.yaml.v1.j2

@@ -183,7 +183,7 @@ policyConfig:
   openshiftInfrastructureNamespace: openshift-infra
   openshiftSharedResourcesNamespace: openshift
 projectConfig:
-  defaultNodeSelector: "{{ osm_default_node_selector }}"
+  defaultNodeSelector: "{{ hostvars[groups.oo_first_master.0].l_osm_default_node_selector }}"
   projectRequestMessage: "{{ osm_project_request_message }}"
   projectRequestTemplate: "{{ osm_project_request_template }}"
   securityAllocator: