Browse Source

Merge pull request #11624 from mtnbikenc/check-version

Install openshift RPMs based on cluster version
OpenShift Merge Robot 5 năm trước cách đây
mục cha
commit
933174a3b9

+ 3 - 0
images/installer/root/usr/local/bin/entrypoint-provider

@@ -24,6 +24,9 @@ if ! whoami &>/dev/null; then
   echo "${USER:-default}:x:$(id -u):$(id -g):Default User:$HOME:/sbin/nologin" >> /etc/passwd
 fi
 
+mkdir -p "${WORK}/inventory/dynamic/${TYPE}/group_vars/all"
+# Override cluster version check when running in CI
+echo "ci_version_override: true" > "${WORK}/inventory/dynamic/${TYPE}/group_vars/all/ci_version_override.yml"
 # Add any injected variable files into the group vars directory
 find "${FILES}" \( -name '*.yml' -or -name '*.yaml' -or -name vars \) -print0 | xargs -0 -L1 -I {} ln -fs {} "${WORK}/inventory/dynamic/${TYPE}/group_vars/all"
 # Avoid sudo when running locally - nothing in the image requires it.

+ 2 - 3
roles/openshift_node/defaults/main.yml

@@ -8,11 +8,10 @@ openshift_node_bootstrap_port: 22623
 openshift_node_bootstrap_server: "{{ openshift_node_kubeconfig.clusters.0.cluster.server.split(':')[0:-1] | join(':') }}:{{ openshift_node_bootstrap_port }}"
 openshift_node_bootstrap_endpoint: "{{ openshift_node_bootstrap_server }}/config/{{ openshift_node_machineconfigpool }}"
 
-openshift_node_package_state: present
 openshift_node_packages:
   - cri-o
-  - openshift-clients
-  - openshift-hyperkube
+  - openshift-clients{{ l_cluster_version }}
+  - openshift-hyperkube{{ l_cluster_version }}
 
 openshift_node_support_packages:
   # Packages from redhat-coreos.git manifest-base.yaml

+ 40 - 9
roles/openshift_node/tasks/install.yml

@@ -15,16 +15,47 @@
     group: root
     mode: 0755
   loop:
-    - /var/lib/cni/bin
-    - /etc/kubernetes/cni/net.d/
-    - /opt/cni/bin/
+  - /var/lib/cni/bin
+  - /etc/kubernetes/cni/net.d/
+  - /opt/cni/bin/
 
-- name: Install openshift packages
-  package:
-    name: "{{ openshift_node_packages | join(',') }}"
-    state: "{{ openshift_node_package_state }}"
-  async: 3600
-  poll: 30
+- name: Get cluster version
+  command: >
+    oc get clusterversion
+    --config={{ openshift_node_kubeconfig_path }}
+    --output=jsonpath='{.items[0].status.desired.version}'
+  delegate_to: localhost
+  register: oc_get
+  until:
+  - oc_get.stdout is defined
+  - oc_get.stdout != ''
+  retries: 36
+  delay: 5
+
+- name: Set fact l_cluster_version
+  set_fact:
+    l_cluster_version: "-{{ oc_get.stdout | regex_search('^\\d+\\.\\d+\\.\\d+') }}"
+
+- name: Override version when running CI
+  set_fact:
+    l_cluster_version: ""
+  when: ci_version_override | default(False) | bool == True
+
+- block:
+  - name: Install openshift packages
+    package:
+      name: "{{ openshift_node_packages | join(',') }}"
+      state: present
+    async: 3600
+    poll: 30
+
+  rescue:
+  - name: Package install failure message
+    fail:
+      msg: >
+        Unable to install {{ openshift_node_packages | join(', ') }}.
+        Please ensure repos are configured properly to provide these packages
+        and indicated versions.
 
 - name: Enable the CRI-O service
   systemd:

+ 0 - 2
roles/openshift_node/tasks/upgrade.yml

@@ -29,8 +29,6 @@
 
 # Upgrade Node Packages
 - import_tasks: install.yml
-  vars:
-    openshift_node_package_state: latest
 
 # Apply machine config
 - import_tasks: apply_machine_config.yml