| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- ---
- - name: Include utils/controlplane tasks
- include_role:
- name: utils/controlplane
- - name: Get Current Version
- environment:
- KUBECONFIG: "{{ ENV_KUBECONFIG }}"
- shell: |
- {{ K3S_CMDLINE_PREFIX }} kubectl -n onecloud get onecloudclusters default -o=jsonpath='{.spec.version}'
- args:
- executable: /bin/bash
- register: current_oc_version
- - name: Copy clean_k8s_obj.sed script to /tmp
- copy:
- src: "clean_k8s_obj.sed"
- dest: "/tmp/clean_k8s_obj.sed"
- - name: Backup current onecloud cluster and operator resource to /opt/yunion/ocboot/_upgrade/.*
- environment:
- KUBECONFIG: "{{ ENV_KUBECONFIG }}"
- shell: |
- bk_dir=/opt/yunion/ocboot/_upgrade/`date +%Y.%m.%d-%H:%M:%S`
- mkdir -p $bk_dir
- {{ K3S_CMDLINE_PREFIX }} kubectl get deployment -n onecloud onecloud-operator -o yaml | sed -f /tmp/clean_k8s_obj.sed > $bk_dir/operator.yml
- {{ K3S_CMDLINE_PREFIX }} kubectl get oc -n onecloud default -o yaml | sed -f /tmp/clean_k8s_obj.sed > $bk_dir/oc.yml
- become: yes
- - name: Copy turn-on-operator-clear-component patch to /tmp/turn-on-operator-clear-component.patch.yml
- template:
- src: "turn-on-operator-clear-component.patch.yml.j2"
- dest: "/tmp/turn-on-operator-clear-component.patch.yml"
- vars:
- k8s_or_k3s: "{{ k8s_or_k3s | default('') }}"
- - name: Turn on operator -clear-component option
- environment:
- KUBECONFIG: "{{ ENV_KUBECONFIG }}"
- shell: |
- {{ K3S_CMDLINE_PREFIX }} kubectl patch deployment -n onecloud onecloud-operator --patch "$(cat /tmp/turn-on-operator-clear-component.patch.yml)" && rm -f /tmp/turn-on-operator-clear-component.patch.yml
- become: yes
- args:
- executable: /bin/bash
- - block:
- - name: test if version file contains cloudpods-ee image
- shell: |
- cat "{{ offline_data_path }}/versions.json" |jq '.dockers |to_entries[]' |grep -wq cloudpods-ee
- register: has_cloudpack_image
- failed_when: false
- args:
- executable: /bin/bash
- - name: patch hyper image for ee mode
- environment:
- KUBECONFIG: /etc/kubernetes/admin.conf
- shell: |
- kubectl -n onecloud patch onecloudcluster default --type='json' -p '[{"op": "replace", "path": "/spec/useHyperImage", "value": true}]'
- kubectl rollout restart deployment -n onecloud onecloud-operator
- sleep 30
- kubectl -n onecloud -o yaml get oc |grep 'useHyperImage: true'
- args:
- executable: /bin/bash
- when:
- - has_cloudpack_image.rc == 0
- retries: 10
- register: hyper_image_patch_result
- delay: 30
- ignore_errors: true
- become: yes
- until: hyper_image_patch_result.rc == 0
- when:
- - offline_data_path |default("") | length > 0
- - name: controllable upgrade
- include_tasks: controllerble.yml
- when:
- - controllable_upgrade | default(false) | bool == true
- - name: init waiter script
- include_role:
- name: utils/onecloud-waiter
- # use async task to upgrade, ref: https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html
- - name: primary master node | Upgrade version "{{ current_onecloud_version }}" to "{{ upgrade_onecloud_version }}"
- environment:
- KUBECONFIG: "{{ ENV_KUBECONFIG }}"
- PATH: /opt/yunion/bin:{{ ansible_env.PATH }}
- args:
- executable: /bin/bash
- shell: |
- edition=$(KUBECONFIG="{{ ENV_KUBECONFIG }}" {{ K3S_CMDLINE_PREFIX }} kubectl -n onecloud get oc -o jsonpath='{.items[0].metadata.annotations.onecloud\.yunion\.io/edition}' || :)
- if [[ "$edition" == "ee" ]]; then
- /opt/yunion/bin/climc-ee update-record-create --version {{ upgrade_onecloud_version }} \
- --registry {{ image_repository | default('registry.cn-beijing.aliyuncs.com/yunion')}} || :
- fi
- KUBECONFIG="{{ ENV_KUBECONFIG }}" {{ K3S_CMDLINE_PREFIX }} kubectl -n onecloud patch deployment onecloud-operator --type=json \
- -p '[
- {"op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "{{ image_repository | default('registry.cn-beijing.aliyuncs.com/yunion')}}/onecloud-operator:{{ upgrade_onecloud_version }}"},
- {"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["/bin/onecloud-controller-manager", "-disable-init-crd", "-clear-component"]} ## disable-init-cr
- ]'
- bash /opt/yunion/bin/wait-onecloud-services.sh "onecloud-operator"
- KUBECONFIG="{{ ENV_KUBECONFIG }}" {{ K3S_CMDLINE_PREFIX }} kubectl patch onecloudclusters -n onecloud default --type merge --patch '
- {
- "spec": {
- "version": "{{ upgrade_onecloud_version }}",
- "imageRepository": "{{ image_repository | default('registry.cn-beijing.aliyuncs.com/yunion')}}"
- }
- }'
- # delete annotation for autoupdate.onecloud.yunion.io/current-version
- KUBECONFIG="{{ ENV_KUBECONFIG }}" {{ K3S_CMDLINE_PREFIX }} kubectl patch onecloudclusters -n onecloud default --type merge --patch '
- {
- "metadata": {
- "annotations": {
- "autoupdate.onecloud.yunion.io/current-version": null
- }
- },
- "spec": {
- "autoupdate": {
- "tag": ""
- },
- "hostagent": {
- "tag": ""
- }
- }
- }
- '
- KUBECONFIG="{{ ENV_KUBECONFIG }}" {{ K3S_CMDLINE_PREFIX }} kubectl rollout restart deployment -n onecloud onecloud-operator
- bash /opt/yunion/bin/wait-onecloud-services.sh
- # 30 minutes timeout
- become: yes
- async: 1800
- poll: 0
- register: upgrade_status
- - name: >
- primary master node | Check upgrade async task.
- To watch upgrade process,
- SSH login host "{{ ansible_hostname }}" execute:
- kubectl get pods -n onecloud -w
- become: yes
- async_status:
- jid: "{{ upgrade_status.ansible_job_id }}"
- register: ocadm_update_result
- until: ocadm_update_result.finished
- retries: 30
- delay: 60
- - name: Copy turn-off-operator-clear-component patch to /tmp/turn-off-operator-clear-component.patch.yml
- template:
- src: "turn-off-operator-clear-component.patch.yml.j2"
- dest: "/tmp/turn-off-operator-clear-component.patch.yml"
- vars:
- k8s_or_k3s: "{{ k8s_or_k3s | default('') }}"
- - name: Turn off operator -clear-component option
- environment:
- KUBECONFIG: "{{ ENV_KUBECONFIG }}"
- shell: |
- {{ K3S_CMDLINE_PREFIX }} kubectl patch deployment -n onecloud onecloud-operator --patch "$(cat /tmp/turn-off-operator-clear-component.patch.yml)" && rm -f /tmp/turn-off-operator-clear-component.patch.yml
- become: yes
- args:
- executable: /bin/bash
- - name: copy for autoupdate hack
- copy:
- src: patch-for-autoupdate.sh
- dest: /tmp/patch-for-autoupdate.sh
- mode: 0755
- - name: apply hack
- shell: bash /tmp/patch-for-autoupdate.sh
- become: yes
- args:
- executable: /bin/bash
|