Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mloskot/0a3c3ca457083ea33745b8040acaaaf1 to your computer and use it in GitHub Desktop.
Save mloskot/0a3c3ca457083ea33745b8040acaaaf1 to your computer and use it in GitHub Desktop.
---
name: 'upgrade-cluster-flux'
on:
schedule:
# Every Monday at 3 AM UTC
- cron: "0 3 * * 1"
workflow_dispatch:
inputs:
environment:
description: 'Environment to run tests against'
required: true
type: choice
options:
- dev
- prod
default: 'dev'
open-pull-request:
description: 'Open pull request? Otherwise, perform dry-run showing current/new manifests difference.'
required: true
type: boolean
default: true
force-upgrade:
description: 'Perform upgrade even if there is no newer Flux available.'
required: true
type: boolean
default: false
run-name: 'Upgrade Flux (open-pull-request=${{ inputs.open-pull-request }}) by @${{ github.actor }}'
jobs:
upgrade-flux:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.MY_GITHUB_BOT_PAT }}
- name: Setup Flux CLI
uses: fluxcd/flux2/action@main
with:
token: ${{ secrets.MY_GITHUB_BOT_PAT }}
- name: Check current Flux version
id: check_current
run: |
VERSION=$(head -n 15 ./cluster/${{ inputs.environment }}/flux-system/gotk-components.yaml | grep "app.kubernetes.io/version:" | tr -s "[:blank:]" | cut -d ":" -f 2 | cut -d "v" -f 2)
echo "flux_version=$VERSION" >> $GITHUB_OUTPUT
echo $VERSION
- name: Check upcoming Flux version
id: check_upcoming
run: |
flux -v
VERSION="$(flux -v | cut -d ' ' -f 3)"
echo "flux_version=$VERSION" >> $GITHUB_OUTPUT
if [[ "${{ steps.check_current.outputs.flux_version }}" == "$VERSION" ]]; then
echo "::notice ::Upcoming Flux $VERSION is not newer than Flux ${{ steps.check_current.outputs.flux_version }} used to generate current manifests"
fi
- name: Update Flux manifests
id: upgrade
run: |
FORCE_FLUX_UPGRADE="${{ inputs.force-upgrade }}"
if [[ "${FORCE_FLUX_UPGRADE}" == "true" ]] || [[ "${{ steps.check_current.outputs.flux_version }}" != "${{ steps.check_upcoming.outputs.flux_version }}" ]]; then
flux install \
--components-extra=image-reflector-controller,image-automation-controller \
--export > ./cluster/${{ inputs.environment }}/flux-system/gotk-components.yaml
fi
VERSION="$(flux -v | cut -d ' ' -f 3)"
echo "flux_version=$VERSION" >> $GITHUB_OUTPUT
- if: ${{ ! inputs.open-pull-request }}
name: Dump Flux manifests diff
id: diff
run: |
git diff --unified=1 --no-color | head -n 500
- if: ${{ inputs.open-pull-request }}
name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.MY_GITHUB_BOT_PAT }}
branch: update-flux
delete-branch: true
commit-message: 'Upgrade Flux ${{ steps.upgrade.outputs.flux_version }} in ${{ inputs.environment }} environment cluster'
title: '[upgrade] Flux ${{ steps.upgrade.outputs.flux_version }} in ${{ inputs.environment }} environment cluster'
body: |
Upgrading to [Flux v${{ steps.upgrade.outputs.flux_version }}](https://github.com/fluxcd/flux2/releases/tag/v${{ steps.upgrade.outputs.flux_version }}) on the **${{ inputs.environment }}** environment of the hosting Kubernetes cluster with automated update of the components manifest.
## Tasklist
1. Upgrade your local installation of Flux to ${{ steps.upgrade.outputs.flux_version }}
```
choco install flux --version=${{ steps.upgrade.outputs.flux_version }}
```
2. Review
3. Make the pull request "Ready for review" and check the changes are recorded as expected.
4. Merge the pull request to deploy the upgrade.
5. Run `flux check` to verify that the controllers have been upgraded on the cluster.
labels: |
component/flux
environment/${{ inputs.environment }}
assignees: mloskot
draft: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment