Skip to content

Commit

Permalink
fix(workflows): yeet multicluster logic
Browse files Browse the repository at this point in the history
Signed-off-by: Devin Buhl <[email protected]>
  • Loading branch information
onedr0p committed Dec 28, 2024
1 parent 2272c4b commit 79df00e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
push:
branches: ["main"]
paths:
- .github/workflows/publish-docs.yaml
- .github/workflows/docs.yaml
- docs/**
- README.md

Expand Down
44 changes: 5 additions & 39 deletions .github/workflows/flux-diff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,13 @@ concurrency:
cancel-in-progress: true

jobs:
changed-clusters:
name: Changed Clusters
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed-clusters.outputs.all_changed_and_modified_files }}
steps:
- name: Generate Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: "${{ secrets.BOT_APP_ID }}"
private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}"

- name: Checkout Default Branch
uses: actions/checkout@v4
with:
token: "${{ steps.app-token.outputs.token }}"
fetch-depth: 0

- name: Get Changed Clusters
id: changed-clusters
uses: tj-actions/changed-files@v45
with:
files: kubernetes/**
files_ignore: kubernetes/shared/**
dir_names: true
dir_names_max_depth: 2
matrix: true

- name: List All Changed Clusters
run: echo "${{ steps.changed-clusters.outputs.all_changed_and_modified_files }}"

flux-diff:
name: Flux Diff
runs-on: ubuntu-latest
needs: ["changed-clusters"]
permissions:
pull-requests: write
strategy:
matrix:
paths: ${{ fromJSON(needs.changed-clusters.outputs.matrix) }}
resources: ["helmrelease", "kustomization"]
max-parallel: 4
fail-fast: false
Expand All @@ -64,7 +30,7 @@ jobs:
app-id: "${{ secrets.BOT_APP_ID }}"
private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}"

- name: Checkout
- name: Checkout Pull Request Branch
uses: actions/checkout@v4
with:
token: "${{ steps.app-token.outputs.token }}"
Expand All @@ -83,8 +49,8 @@ jobs:
args: >-
diff ${{ matrix.resources }}
--unified 6
--path /github/workspace/pull/${{ matrix.paths }}/flux
--path-orig /github/workspace/default/${{ matrix.paths }}/flux
--path /github/workspace/pull/kubernetes/main/flux
--path-orig /github/workspace/default/kubernetes/main/flux
--strip-attrs "helm.sh/chart,checksum/config,app.kubernetes.io/version,chart"
--limit-bytes 10000
--all-namespaces
Expand All @@ -108,11 +74,11 @@ jobs:
} >> "$GITHUB_STEP_SUMMARY"
- if: ${{ steps.diff.outputs.diff != '' }}
name: Add comment
name: Add Comment
uses: mshick/add-pr-comment@v2
with:
repo-token: "${{ steps.app-token.outputs.token }}"
message-id: "${{ github.event.pull_request.number }}/${{ matrix.paths }}/${{ matrix.resources }}"
message-id: "${{ github.event.pull_request.number }}/kubernetes/main/${{ matrix.resources }}"
message-failure: Diff was not successful
message: |
```diff
Expand Down
29 changes: 9 additions & 20 deletions .github/workflows/helm-repository-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ name: "Helm Repository Sync"
on:
workflow_dispatch:
inputs:
clusterName:
description: Cluster Name
default: main
required: true
helmRepoNamespace:
description: Helm Repository Namespace
default: flux-system
Expand Down Expand Up @@ -46,41 +42,34 @@ jobs:
"aqua:fluxcd/flux2" = "latest"
"aqua:mikefarah/yq" = "latest"
- if: ${{ github.event.inputs.clusterName == '' && github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }}
- if: ${{ github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }}
name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: kubernetes/**/helmrelease.yaml
safe_output: false

- if: ${{ github.event.inputs.clusterName == '' && github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }}
name: List All Changed Files
run: echo "${{ steps.changed-files.outputs.all_changed_and_modified_files }}"

- if: ${{ github.event.inputs.clusterName == '' && github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }}
- if: ${{ github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }}
name: Sync Helm Repository
shell: bash
run: |
declare -a repos=()
for f in ${{ steps.changed-files.outputs.all_changed_and_modified_files }}; do
cluster_name=$(echo "${f}" | awk -F'/' '{print $2}')
repo_namespace="$(yq -r '.spec.chart.spec.sourceRef.namespace' "${f}")"
repo_name="$(yq -r '.spec.chart.spec.sourceRef.name' "${f}")"
repos+=("${cluster_name}:${repo_namespace}:${repo_name}")
repos+=("${repo_namespace}:${repo_name}")
done
mapfile -t repos < <(printf "%s\n" "${repos[@]}" | sort -u)
for r in "${repos[@]}"; do
IFS=':' read -r cluster_name repo_namespace repo_name <<< "${r}"
flux \
--namespace ${repo_namespace} \
reconcile source helm ${repo_name} || true
IFS=':' read -r repo_namespace repo_name <<< "${r}"
flux --namespace ${repo_namespace} \
reconcile source helm ${repo_name}
done
- if: ${{ github.event.inputs.clusterName != '' && github.event.inputs.helmRepoNamespace != '' && github.event.inputs.helmRepoName != '' }}
- if: ${{ github.event.inputs.helmRepoNamespace != '' && github.event.inputs.helmRepoName != '' }}
name: Sync Helm Repository
shell: bash
run: |
flux \
--namespace ${{ github.event.inputs.helmRepoNamespace }} \
reconcile source helm ${{ github.event.inputs.helmRepoName }} || true
flux --namespace ${{ github.event.inputs.helmRepoNamespace }} \
reconcile source helm ${{ github.event.inputs.helmRepoName }}
42 changes: 2 additions & 40 deletions .github/workflows/pre-pull-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,11 @@ concurrency:
cancel-in-progress: true

jobs:
changed-clusters:
name: Changed Clusters
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed-clusters.outputs.all_changed_and_modified_files }}
steps:
- name: Generate Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: "${{ secrets.BOT_APP_ID }}"
private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}"

- name: Checkout
uses: actions/checkout@v4
with:
token: "${{ steps.app-token.outputs.token }}"
fetch-depth: 0

- name: Get Changed Clusters
id: changed-clusters
uses: tj-actions/changed-files@v45
with:
files: kubernetes/**
files_ignore: kubernetes/shared/**
dir_names: true
dir_names_max_depth: 2
matrix: true

- name: List All Changed Clusters
run: echo "${{ steps.changed-clusters.outputs.all_changed_and_modified_files }}"

extract-images:
name: Extract Images
runs-on: ubuntu-latest
needs: ["changed-clusters"]
permissions:
pull-requests: write
strategy:
matrix:
paths: ${{ fromJSON(needs.changed-clusters.outputs.matrix) }}
max-parallel: 4
fail-fast: false
outputs:
matrix: ${{ steps.extract-images.outputs.images }}
steps:
Expand Down Expand Up @@ -90,7 +52,7 @@ jobs:
with:
args: >-
get cluster
--path /github/workspace/default/${{ matrix.paths }}/flux
--path /github/workspace/default/kubernetes/main/flux
--enable-images
--output yaml
--output-file default.yaml
Expand All @@ -100,7 +62,7 @@ jobs:
with:
args: >-
get cluster
--path /github/workspace/pull/${{ matrix.paths }}/flux
--path /github/workspace/pull/kubernetes/main/flux
--enable-images
--output yaml
--output-file pull.yaml
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ jobs:
with:
token: "${{ steps.app-token.outputs.token }}"

- name: Setup mise
uses: jdx/mise-action@v2
with:
mise_toml: |
[tools]
"aqua:kubernetes/kubectl" = "latest"
# TODO: mise won't work due to subshell nonsense in crd-extractor.sh
- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Setup Workflow Tools
shell: bash
run: brew install kubectl

- name: Setup Python
uses: actions/setup-python@v5
Expand Down

0 comments on commit 79df00e

Please sign in to comment.