|
| 1 | +name: Rancher upgrade integration |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + baseHarvesterVersion: |
| 7 | + description: 'Base Harvester Version' |
| 8 | + required: true |
| 9 | + rancherVersion: |
| 10 | + description: 'Rancher Version' |
| 11 | + required: true |
| 12 | + rke2Version: |
| 13 | + description: 'RKE2 Version' |
| 14 | + required: true |
| 15 | + |
| 16 | +env: |
| 17 | + LIBVIRT_DEFAULT_URI: "qemu:///system" |
| 18 | + |
| 19 | +jobs: |
| 20 | + main: |
| 21 | + name: Build and deploy |
| 22 | + runs-on: |
| 23 | + - self-hosted |
| 24 | + - Linux |
| 25 | + - kvm |
| 26 | + - vagrant |
| 27 | + - equinix |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Patch RKE2 Version |
| 32 | + run: | |
| 33 | + sed -i 's/^RKE2_VERSION=".*"/RKE2_VERSION="${{ github.event.inputs.rke2Version }}"/' ./scripts/version-rke2 |
| 34 | +
|
| 35 | + - name: Patch Rancher Version |
| 36 | + run: | |
| 37 | + sed -i 's/^RANCHER_VERSION=".*"/RANCHER_VERSION="${{ github.event.inputs.rke2Version }}"/' ./scripts/version-rancher |
| 38 | + sed -i 's/^ rancherImageTag: .*/ rancherImageTag: ${{ github.event.inputs.rancherVersion }}/' ./package/harvester-os/files/usr/share/rancher/rancherd/config.yaml.d/50-defaults.yaml |
| 39 | + sed -i 's|^rancherInstallerImage: .*|rancherInstallerImage: rancher/system-agent-installer-rancher:${{ github.event.inputs.rancherVersion }}|' ./package/harvester-os/files/usr/share/rancher/rancherd/config.yaml.d/50-defaults.yaml |
| 40 | +
|
| 41 | + - name: Make a commit |
| 42 | + run: | |
| 43 | + git add ./scripts/version-rke2 ./scripts/version-rancher ./package/harvester-os/files/usr/share/rancher/rancherd/config.yaml.d/50-defaults.yaml |
| 44 | + git commit -m "Update RKE2 and Rancher versions to ${{ github.event.inputs.rke2Version }} and ${{ github.event.inputs.rancherVersion }}" |
| 45 | +
|
| 46 | + - name: Build Harvester artifacts |
| 47 | + run: | |
| 48 | + make |
| 49 | +
|
| 50 | + - name: Download Base Harvester Version |
| 51 | + run: | |
| 52 | + wget https://releases.rancher.com/harvester/${{ github.event.inputs.baseHarvesterVersion }}/harvester-${{ github.event.inputs.baseHarvesterVersion }}-amd64.iso |
| 53 | + wget https://releases.rancher.com/harvester/${{ github.event.inputs.baseHarvesterVersion }}/harvester-${{ github.event.inputs.baseHarvesterVersion }}-vmlinuz-amd64 |
| 54 | + wget https://releases.rancher.com/harvester/${{ github.event.inputs.baseHarvesterVersion }}/harvester-${{ github.event.inputs.baseHarvesterVersion }}-initrd-amd64 |
| 55 | + wget https://releases.rancher.com/harvester/${{ github.event.inputs.baseHarvesterVersion }}/harvester-${{ github.event.inputs.baseHarvesterVersion }}-rootfs-amd64.squashfs |
| 56 | + - name: Clone and checkout ipxe-examples |
| 57 | + id: ipxe |
| 58 | + run: | |
| 59 | + cd $HOME |
| 60 | + if [ ! -d ipxe-examples ]; then |
| 61 | + git clone https://github.com/harvester/ipxe-examples.git |
| 62 | + fi |
| 63 | +
|
| 64 | + cd ipxe-examples |
| 65 | + git reset && git checkout . |
| 66 | + git clean -fd |
| 67 | + git pull |
| 68 | + echo "VAGRANT_HOME=$HOME/ipxe-examples/vagrant-pxe-harvester" >> $GITHUB_OUTPUT |
| 69 | + - name: Clean up previous vagrant deployment |
| 70 | + working-directory: ${{ steps.ipxe.outputs.VAGRANT_HOME }} |
| 71 | + run: | |
| 72 | + vagrant destroy -f |
| 73 | + - name: Remove OVMF.fd line if needed |
| 74 | + working-directory: ${{ steps.ipxe.outputs.VAGRANT_HOME }} |
| 75 | + run: | |
| 76 | + if [ ! -f /usr/share/qemu/OVMF.fd ]; then |
| 77 | + echo "Remove libvirt loader: can't find UEFI firmware" |
| 78 | + sed 's/libvirt.loader.*/#libvirt.loader = /' Vagrantfile |
| 79 | + fi |
| 80 | + - name: Generate SSH keys |
| 81 | + run: | |
| 82 | + ssh-keygen -t rsa -q -N "" -f ./ci/terraform/tmp-ssh-key |
| 83 | + - name: Set SSH key in ipxe-examples settings |
| 84 | + run: | |
| 85 | + export PUB_KEY=$(cat ./ci/terraform/tmp-ssh-key.pub) |
| 86 | + yq e -i ".harvester_config.ssh_authorized_keys += [ strenv(PUB_KEY) ]" ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml |
| 87 | + - name: Set artifacts in ipxe-examples settings |
| 88 | + run: | |
| 89 | + yq e -i ".harvester_iso_url = \"file://${{ github.workspace }}/harvester-${{ github.event.inputs.baseHarvesterVersion }}-amd64.iso\"" ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml |
| 90 | + yq e -i ".harvester_kernel_url = \"file://${{ github.workspace }}/harvester-${{ github.event.inputs.baseHarvesterVersion }}-vmlinuz-amd64\"" ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml |
| 91 | + yq e -i ".harvester_ramdisk_url = \"file://${{ github.workspace }}/harvester-${{ github.event.inputs.baseHarvesterVersion }}-initrd-amd64\"" ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml |
| 92 | + yq e -i ".harvester_rootfs_url = \"file://${{ github.workspace }}/harvester-${{ github.event.inputs.baseHarvesterVersion }}-rootfs-amd64.squashfs\"" ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml |
| 93 | + - name: Setup cluster |
| 94 | + working-directory: ${{ steps.ipxe.outputs.VAGRANT_HOME }} |
| 95 | + run: | |
| 96 | + ./setup_harvester.sh |
| 97 | + - name: Enable soft emulation |
| 98 | + working-directory: ./ci/terraform |
| 99 | + run: | |
| 100 | + ./enable_soft_emulation.sh ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml |
| 101 | + - name: Clean the previous temp files |
| 102 | + working-directory: ./ci/terraform |
| 103 | + run: | |
| 104 | + ./cleanup_test_files.sh |
| 105 | + - name: Testing existing files |
| 106 | + working-directory: ./ci/terraform |
| 107 | + run: | |
| 108 | + ./check_files.sh ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml |
| 109 | + - name: Testing services status |
| 110 | + working-directory: ./ci/terraform |
| 111 | + run: | |
| 112 | + ./check_services_status.sh ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml |
| 113 | +
|
| 114 | + - name: Create new-version.yaml |
| 115 | + run: | |
| 116 | + echo "apiVersion: harvesterhci.io/v1beta1" > new-version.yaml |
| 117 | + echo "kind: Version" >> new-version.yaml |
| 118 | + echo "metadata:" >> new-version.yaml |
| 119 | + echo " name: master-head" >> new-version.yaml |
| 120 | + echo " namespace: harvester-system" >> new-version.yaml |
| 121 | + echo "spec:" >> new-version.yaml |
| 122 | + echo " isoURL: http://localhost:8000/dist/artifacts/harvester-master-amd64.iso" >> new-version.yaml |
| 123 | + echo " minUpgradableVersion: v1.3.1" >> new-version.yaml |
| 124 | + echo " releaseDate: \"202401231\"" >> new-version.yaml |
| 125 | + echo " tags:" >> new-version.yaml |
| 126 | + echo " - dev" >> new-version.yaml |
| 127 | + echo " - test" >> new-version.yaml |
| 128 | +
|
| 129 | + - name: Create new-upgrade.yaml |
| 130 | + run: | |
| 131 | + echo "apiVersion: harvesterhci.io/v1beta1" > new-version.yaml |
| 132 | + echo "kind: Upgrade" >> new-version.yaml |
| 133 | + echo "metadata:" >> new-version.yaml |
| 134 | + echo " name: master-head" >> new-version.yaml |
| 135 | + echo " namespace: harvester-system" >> new-version.yaml |
| 136 | + echo "spec:" >> new-version.yaml |
| 137 | + echo " logEnabled: true" >> new-version.yaml |
| 138 | + echo " version: master-head" >> new-version.yaml |
| 139 | +
|
| 140 | + - name: Apply new-version.yaml |
| 141 | + run: | |
| 142 | + kubectl apply -f new-version.yaml |
| 143 | +
|
| 144 | + - name: Start file server |
| 145 | + run: | |
| 146 | + python3 -m http.server 8000 --bind 0.0.0.0 & |
| 147 | +
|
| 148 | + - name: Apply new-upgrade.yaml |
| 149 | + run: | |
| 150 | + kubectl apply -f new-upgrade.yaml |
| 151 | +
|
| 152 | + - name: Wait for upgrade to complete |
| 153 | + run: | |
| 154 | + kubectl wait --for=condition=Completed -n harvester-system upgrade/master-head --timeout=60m |
| 155 | +
|
| 156 | + - name: Collect logs |
| 157 | + if: failure() |
| 158 | + working-directory: ./ci/terraform |
| 159 | + run: | |
| 160 | + for i in 0 1 2; do |
| 161 | + node_ip=$(yq e ".harvester_network_config.cluster[$i].ip" ${{ steps.ipxe.outputs.VAGRANT_HOME }}/settings.yml) |
| 162 | + if ping -c 1 $node_ip &> /dev/null; then |
| 163 | + node_name="node$i" # Dynamically set node name (e.g., node0, node1, node2) |
| 164 | + mkdir -p logs/$node_name |
| 165 | + ssh -o "StrictHostKeyChecking no" -i tmp-ssh-key rancher@$node_ip "journalctl -u rancherd.service" > logs/$node_name/rancherd.log || true |
| 166 | + ssh -o "StrictHostKeyChecking no" -i tmp-ssh-key rancher@$node_ip "journalctl -u rancher-system-agent.service" > logs/$node_name/rancher-system-agent.log || true |
| 167 | + ssh -o "StrictHostKeyChecking no" -i tmp-ssh-key rancher@$node_ip "journalctl -u rke2-server.service" > logs/$node_name/rke2-server.log || true |
| 168 | + else |
| 169 | + echo "Failed to ping $node_ip" |
| 170 | + fi |
| 171 | + done |
| 172 | +
|
| 173 | + - uses: actions/upload-artifact@v4 |
| 174 | + name: Upload logs |
| 175 | + if: failure() |
| 176 | + with: |
| 177 | + name: node-logs |
| 178 | + path: | |
| 179 | + ./ci/terraform/logs |
| 180 | +
|
| 181 | + - name: Clean up vagrant cluster |
| 182 | + working-directory: ${{ steps.ipxe.outputs.VAGRANT_HOME }} |
| 183 | + run: | |
| 184 | + vagrant destroy -f |
0 commit comments