Skip to content

Commit

Permalink
Add e2e tests with Kubernetes Kind
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
  • Loading branch information
stefanprodan committed Aug 18, 2023
1 parent 5dffefe commit 2913380
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: e2e

on:
workflow_dispatch:
push:
branches: [ '*' ]
tags-ignore: [ '*' ]

jobs:
kubernetes:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Flux
uses: fluxcd/flux2/action@main
- name: Setup Kubernetes
uses: helm/kind-action@v1.8.0
with:
cluster_name: flux
version: v0.20.0
# The versions below should target the newest Kubernetes version
# Keep this up-to-date with https://endoflife.date/kubernetes
node_image: kindest/node:v1.28.0@sha256:9f3ff58f19dcf1a0611d11e8ac989fdb30a28f40f236f59f0bea31fb956ccf5c
kubectl_version: v1.28.0
- name: Install Flux in Kubernetes Kind
run: flux install
- name: Setup cluster reconciliation
run: |
flux create source git flux-system \
--url=${{ github.event.repository.html_url }} \
--branch=${GITHUB_REF#refs/heads/} \
--ignore-paths="clusters/**/flux-system/"
flux create kustomization flux-system \
--source=flux-system \
--path=./clusters/test
- name: Verify cluster reconciliation
run: |
kubectl -n flux-system wait kustomization/monitoring-controllers --for=condition=ready --timeout=10m
kubectl -n flux-system wait kustomization/monitoring-configs --for=condition=ready --timeout=1m
- name: Debug failure
if: failure()
run: |
kubectl -n flux-system logs deploy/source-controller
kubectl -n flux-system logs deploy/kustomize-controller
kubectl -n flux-system logs deploy/helm-controller
flux get all --all-namespaces
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: test

on:
workflow_dispatch:
pull_request:
push:
branches: [ '*' ]
tags-ignore: [ '*' ]

jobs:
manifests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup yq
uses: fluxcd/pkg/actions/yq@main
- name: Setup kubeconform
uses: fluxcd/pkg/actions/kubeconform@main
- name: Setup kustomize
uses: fluxcd/pkg/actions/kustomize@main
- name: Validate manifests
run: ./scripts/validate.sh
66 changes: 66 additions & 0 deletions scripts/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

# This script downloads the Flux OpenAPI schemas, then it validates the
# Flux custom resources and the kustomize overlays using kubeconform.
# This script is meant to be run locally and in CI before the changes
# are merged on the main branch that's synced by Flux.

# Copyright 2023 The Flux authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Prerequisites
# - yq v4.34
# - kustomize v5.0
# - kubeconform v0.6

set -o errexit
set -o pipefail

# mirror kustomize-controller build options
kustomize_flags=("--load-restrictor=LoadRestrictionsNone")
kustomize_config="kustomization.yaml"

# skip Kubernetes Secrets due to SOPS fields failing validation
kubeconform_flags=("-skip=Secret")
kubeconform_config=("-strict" "-ignore-missing-schemas" "-schema-location" "default" "-schema-location" "/tmp/flux-crd-schemas" "-verbose")

echo "INFO - Downloading Flux OpenAPI schemas"
mkdir -p /tmp/flux-crd-schemas/master-standalone-strict
curl -sL https://github.com/fluxcd/flux2/releases/latest/download/crd-schemas.tar.gz | tar zxf - -C /tmp/flux-crd-schemas/master-standalone-strict

find . -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file;
do
echo "INFO - Validating $file"
yq e 'true' "$file" > /dev/null
done

echo "INFO - Validating clusters"
find ./clusters -maxdepth 2 -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file;
do
kubeconform "${kubeconform_flags[@]}" "${kubeconform_config[@]}" "${file}"
if [[ ${PIPESTATUS[0]} != 0 ]]; then
exit 1
fi
done

echo "INFO - Validating kustomize overlays"
find . -type f -name $kustomize_config -print0 | while IFS= read -r -d $'\0' file;
do
echo "INFO - Validating kustomization ${file/%$kustomize_config}"
kustomize build "${file/%$kustomize_config}" "${kustomize_flags[@]}" | \
kubeconform "${kubeconform_flags[@]}" "${kubeconform_config[@]}"
if [[ ${PIPESTATUS[0]} != 0 ]]; then
exit 1
fi
done

0 comments on commit 2913380

Please sign in to comment.