Skip to content

Commit

Permalink
Merge branch 'main' into renovate/sol-k3s-io-k3s-1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
coolguy1771 authored Dec 22, 2023
2 parents 1478444 + e90ab01 commit 230bec1
Show file tree
Hide file tree
Showing 85 changed files with 402 additions and 356 deletions.
1 change: 0 additions & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"extends": [
"config:recommended",
"docker:enableMajor",
"helpers:pinGitHubActionDigests",
"replacements:k8s-registry-move",
":automergeBranch",
":disableRateLimiting",
Expand Down
118 changes: 88 additions & 30 deletions .github/workflows/flux-diff.yaml
Original file line number Diff line number Diff line change
@@ -1,71 +1,129 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Flux Diff"

on:
pull_request:
branches: ["main"]
paths: ["kubernetes/**.yaml"]
paths: ["kubernetes/**"]

env:
DEBCONF_NONINTERACTIVE_SEEN: "true"
DEBIAN_FRONTEND: noninteractive
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE: DontWarn
NIX_FLAKE_PATH: ./.github/workflows/resources/nix
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true

jobs:
changed-files:
name: Get Changed Files
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed-files.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 files
id: changed-files
uses: tj-actions/changed-files@v40
with:
files: kubernetes/**
dir_names: true
dir_names_max_depth: 2
json: true
quotepath: false
escape_json: false

- name: List all changed files
run: echo "${{ steps.changed-files.outputs.all_changed_and_modified_files }}"

flux-diff:
name: Flux Diff
runs-on: ubuntu-latest
needs: ["changed-files"]
permissions:
pull-requests: write
strategy:
matrix:
path: ["kubernetes/kyak", "kubernetes/sol"]
resource: ["helmrelease", "kustomization"]
paths: ${{ fromJSON(needs.changed-files.outputs.matrix) }}
resources: ["helmrelease", "kustomization"]
max-parallel: 4
fail-fast: false
steps:
- name: Generate Token
uses: actions/create-github-app-token@2986852ad836768dfea7781f31828eb3e17990fa # v1.6.2
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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
token: "${{ steps.app-token.outputs.token }}"

- name: Install OS Deps
- name: Setup System Tools
shell: bash
run: sudo apt-get update && sudo apt-get install -y curl git xz-utils
run: sudo apt-get -qq update && sudo apt-get -qq install --no-install-recommends -y curl git

- name: Install Nix
uses: cachix/install-nix-action@7ac1ec25491415c381d9b62f0657c7a028df52a7 # v24
- name: Checkout Live Branch
uses: actions/checkout@v4
with:
github_access_token: "${{ steps.app-token.outputs.token }}"
token: "${{ steps.app-token.outputs.token }}"
ref: main
path: default

- name: Switch to Nix devShell
uses: nicknovitski/nix-develop@a2060d116a50b36dfab02280af558e73ab52427d # v1.1.0
- name: Checkout PR branch
uses: actions/checkout@v4
with:
arguments: "${{ env.NIX_FLAKE_PATH }}"
token: "${{ steps.app-token.outputs.token }}"
path: pull

- name: Diff Resources
# uses: allenporter/flux-local/action/diff@19bfc6920e8964a479363bc230e6c329120ead02 # 3.2.0
uses: allenporter/flux-local/action/diff@flux-build
id: diff
uses: docker://ghcr.io/allenporter/flux-local:v4.2.0
with:
sources: home-kubernetes
path: "${{ matrix.path }}"
resource: "${{ matrix.resource }}"
args: >-
--log-level DEBUG
diff ${{ matrix.resources }}
--unified 6
--path-orig /github/workspace/default/${{ matrix.paths }}
--path /github/workspace/pull/${{ matrix.paths }}
--strip-attrs "helm.sh/chart,checksum/config,app.kubernetes.io/version,chart"
--limit-bytes 10000
--all-namespaces
--sources "home-kubernetes"
--output-file diff.patch
- name: Generate Diff
id: diff
run: |
cat diff.patch
echo "diff<<EOF" >> $GITHUB_OUTPUT
cat diff.patch >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- if: ${{ steps.diff.outputs.diff != '' }}
name: Add comment
uses: mshick/add-pr-comment@7c0890544fb33b0bdd2e59467fbacb62e028a096 # v2.8.1
uses: mshick/add-pr-comment@v2.8.1
with:
repo-token: "${{ steps.app-token.outputs.token }}"
message-id: "${{ github.event.pull_request.number }}/${{ matrix.path }}/${{ matrix.resource }}"
message-id: "${{ github.event.pull_request.number }}/${{ matrix.paths }}/${{ matrix.resources }}"
message-failure: Diff was not successful
message: |
```diff
${{ steps.diff.outputs.diff }}
```
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
flux-diff-success:
if: ${{ always() }}
needs: ["flux-diff"]
name: Flux diff successful
runs-on: ubuntu-latest
steps:
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
name: Check matrix status
run: exit 1
119 changes: 119 additions & 0 deletions .github/workflows/flux-hr-image-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Flux Helm Release Image Test"

on:
pull_request:
branches: ["main"]
paths: ["kubernetes/**/helmrelease.yaml"]

env:
WORKFLOW_KUBERNETES_DIR: ./kubernetes

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true

jobs:
changed-files:
name: Get Changed Files
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed-files.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 files
id: changed-files
uses: tj-actions/changed-files@v40
with:
files: kubernetes/**/helmrelease.yaml
json: true
quotepath: false
escape_json: false

- name: List all changed files
run: echo "${{ steps.changed-files.outputs.all_changed_and_modified_files }}"

extract-images:
if: ${{ needs.changed-files.outputs.matrix != '[]' }}
name: Extract images from Helm Release
runs-on: ubuntu-latest
needs: ["changed-files"]
strategy:
matrix:
files: ${{ fromJSON(needs.changed-files.outputs.matrix) }}
max-parallel: 4
fail-fast: false
outputs:
matrix: ${{ steps.extract-images.outputs.images }}
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: Setup System Tools
shell: bash
run: sudo apt-get -qq update && sudo apt-get -qq install --no-install-recommends -y curl git

- name: Setup Workflow Tools
uses: jdx/rtx-action@v1
with:
install: true
cache: true
rtx_toml: |
[tools]
helm = "latest"
kustomize = "latest"
- name: Extract Images from Helm Release
id: extract-images
run: |
images=$(npx zx ./.github/scripts/extract-images.mjs --kubernetes-dir "${{ env.WORKFLOW_KUBERNETES_DIR }}" --helmrelease "${{ matrix.files }}")
echo "images=${images}" >> $GITHUB_OUTPUT
echo "${images}"
test-images:
if: ${{ needs.extract-images.outputs.matrix != '[]' }}
name: Test images from Helm Release
runs-on: ubuntu-latest
needs: ["extract-images"]
strategy:
matrix:
images: ${{ fromJSON(needs.extract-images.outputs.matrix) }}
max-parallel: 4
fail-fast: false
steps:
- name: Test Images from Helm Release
run: docker pull ${{ matrix.images }}

# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
test-images-success:
if: ${{ always() }}
needs: ["test-images"]
name: Test images from Helm Release successful
runs-on: ubuntu-latest
steps:
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
name: Check matrix status
run: exit 1
41 changes: 18 additions & 23 deletions .github/workflows/flux-hr-sync.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Flux Helm Repository Sync"

on:
workflow_dispatch:
inputs:
clusterName:
description: Cluster Name
default: kyak
default: main
required: true
helmRepoNamespace:
description: Helm Repository Namespace
Expand All @@ -19,55 +20,49 @@ on:
branches: ["main"]
paths: ["kubernetes/**/helmrelease.yaml"]

env:
DEBCONF_NONINTERACTIVE_SEEN: "true"
DEBIAN_FRONTEND: noninteractive
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE: DontWarn
NIX_FLAKE_PATH: ./.github/workflows/resources/nix

jobs:
sync:
name: Flux Helm Repository Sync
runs-on: ["arc-runner-set-home-ops"]
steps:
- name: Generate Token
uses: actions/create-github-app-token@2986852ad836768dfea7781f31828eb3e17990fa # v1.6.2
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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@v4
with:
token: "${{ steps.app-token.outputs.token }}"
fetch-depth: 0

- name: Install OS Deps
- name: Setup System Tools
shell: bash
run: sudo apt-get update && sudo apt-get install -y curl git xz-utils

- name: Install Nix
uses: cachix/install-nix-action@7ac1ec25491415c381d9b62f0657c7a028df52a7 # v24
with:
github_access_token: "${{ steps.app-token.outputs.token }}"
run: sudo apt-get -qq update && sudo apt-get -qq install --no-install-recommends -y curl git

- name: Switch to Nix devShell
uses: nicknovitski/nix-develop@a2060d116a50b36dfab02280af558e73ab52427d # v1.1.0
- name: Setup Workflow Tools
uses: jdx/rtx-action@v1
with:
arguments: "${{ env.NIX_FLAKE_PATH }}"
install: true
cache: true
rtx_toml: |
[tools]
flux2 = "latest"
yq = "latest"
- name: Write kubeconfig
id: kubeconfig
uses: timheuer/base64-to-file@784a1a4a994315802b7d8e2084e116e783d157be # v1.2.4
uses: timheuer/base64-to-file@v1
with:
encodedString: "${{ secrets.KUBECONFIG }}"
fileName: kubeconfig

- if: ${{ github.event.inputs.clusterName == '' && github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }}
name: Get changed files
id: changed-files
uses: tj-actions/changed-files@56284d80811fb5963a972b438f2870f175e5b7c8 # v40.2.3
uses: tj-actions/changed-files@v40
with:
files: kubernetes/**/helmrelease.yaml

Expand All @@ -80,8 +75,8 @@ jobs:
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 '.spec.chart.spec.sourceRef.namespace' "${f}")"
repo_name="$(yq '.spec.chart.spec.sourceRef.name' "${f}")"
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}")
done
mapfile -t repos < <(printf "%s\n" "${repos[@]}" | sort -u)
Expand Down
Loading

0 comments on commit 230bec1

Please sign in to comment.