Skip to content
Snippets Groups Projects
Select Git revision
  • 285c977cf7dbb14729163d25c0ee26c94a11ddfc
  • main default protected
  • renovate/main-zod-3.x
  • renovate/main-ghcr.io-renovatebot-base-image-10.x
  • renovate/main-ghcr.io-containerbase-devcontainer-13.x
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • 41.28.2
  • 41.28.1
  • 41.28.0
  • 41.27.1
  • 41.27.0
  • 41.26.2
  • 41.26.1
  • 41.26.0
  • 41.25.1
  • 41.25.0
  • 41.24.0
  • 41.23.5
  • 41.23.4
  • 41.23.3
  • 41.23.2
  • 41.23.1
  • 41.23.0
  • 41.22.0
  • 41.21.4
  • 41.21.3
41 results

index.js

Blame
  • validate.sh 2.64 KiB
    #!/usr/bin/env bash
    
    # This script downloads the Flux OpenAPI schemas, then it validates the
    # Flux custom resources and the kustomize overlays using kubeval.
    # 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 2020 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.
    
    # This script is meant to be run locally and in CI to validate the Kubernetes
    # manifests (including Flux custom resources) before changes are merged into
    # the branch synced by Flux in-cluster.
    
    # Prerequisites
    # - yq v4.6
    # - kustomize v4.1
    # - kubeval v0.15
    
    set -o errexit
    
    KUBERNETES_VERSION=1.22.12
    
    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' ! -path "./charts/*" -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' ! -path "./charts/*" -print0 | while IFS= read -r -d $'\0' file;
      do
        kubeval ${file} --strict --ignore-missing-schemas --kubernetes-version ${KUBERNETES_VERSION} --additional-schema-locations=file:///tmp/flux-crd-schemas
        if [[ ${PIPESTATUS[0]} != 0 ]]; then
          exit 1
        fi
    done
    
    # mirror kustomize-controller build options
    kustomize_flags="--load-restrictor=LoadRestrictionsNone --reorder=legacy"
    kustomize_config="kustomization.yaml"
    
    echo "INFO - Validating kustomize overlays"
    find . -type f -name $kustomize_config ! -path "./charts/*" -print0  | while IFS= read -r -d $'\0' file;
      do
        echo "INFO - Validating kustomization ${file/%$kustomize_config}"
        kustomize build "${file/%$kustomize_config}" $kustomize_flags | \
          kubeval --ignore-missing-schemas --strict --kubernetes-version ${KUBERNETES_VERSION} --additional-schema-locations=file:///tmp/flux-crd-schemas
        if [[ ${PIPESTATUS[0]} != 0 ]]; then
          exit 1
        fi
    done
    echo "INFO - Validation complete"