-
Notifications
You must be signed in to change notification settings - Fork 53
CNFCERT-1258: Add kustomize validation check #3054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: Kustomize Validation | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| kustomize-validation: | ||
| name: Validate Kustomization Files | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Validate Kustomization Files | ||
| run: make test-kustomize | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| # Temporary file tracking for cleanup | ||
| TEMP_FILES=() | ||
|
|
||
| # Cleanup function (invoked via trap, not called directly) | ||
| # shellcheck disable=SC2329 | ||
| cleanup() { | ||
| for temp_file in "${TEMP_FILES[@]}"; do | ||
| if [ -f "$temp_file" ]; then | ||
| rm -f "$temp_file" | ||
| echo "Cleaned up: $temp_file" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| # Set trap to ensure cleanup on exit | ||
| trap cleanup EXIT | ||
|
|
||
| # Check if kustomize is installed | ||
| if ! command -v kustomize &> /dev/null; then | ||
| echo -e "${RED}ERROR: kustomize is not installed${NC}" | ||
| echo "Install via: make kustomize" | ||
| exit 1 | ||
| fi | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| # Generate temporary patch files that are normally created during build. | ||
| # config/manager/related-images/patch.yaml is generated from in.yaml with envsubst. | ||
| PATCH_FILE="./config/manager/related-images/patch.yaml" | ||
| if [ ! -f "$PATCH_FILE" ] && [ -f "./config/manager/related-images/in.yaml" ]; then | ||
| if ! command -v envsubst &> /dev/null; then | ||
| echo -e "${RED}ERROR: envsubst is not installed (provided by gettext)${NC}" | ||
| exit 1 | ||
| fi | ||
| echo "Generating temporary patch file for validation: $PATCH_FILE" | ||
| PRECACHE_WORKLOAD_IMG="quay.io/openshift-kni/lifecycle-agent-operator:latest" \ | ||
| envsubst < "./config/manager/related-images/in.yaml" > "$PATCH_FILE" | ||
| TEMP_FILES+=("$PATCH_FILE") | ||
| fi | ||
|
|
||
| echo "Checking all kustomization.yaml files can build successfully..." | ||
| echo "" | ||
|
|
||
| ERRORS=0 | ||
| CHECKED=0 | ||
|
|
||
| # Find all kustomization.yaml files | ||
| kustomize_files=() | ||
| while IFS= read -r file; do | ||
| kustomize_files+=("$file") | ||
| done < <(find . -name 'kustomization.yaml' -not -path '*/vendor/*' -not -path '*/.git/*' -not -path '*/bin/*' -not -path '*/telco5g-konflux/*' | sort) | ||
|
|
||
| if [ ${#kustomize_files[@]} -eq 0 ]; then | ||
| echo -e "${YELLOW}WARNING: No kustomization.yaml files found${NC}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| for kustomize_file in "${kustomize_files[@]}"; do | ||
| dir=$(dirname "$kustomize_file") | ||
| echo -n " $dir: " | ||
|
|
||
| if BUILD_OUTPUT=$(kustomize build "$dir" 2>&1); then | ||
| echo -e "${GREEN}OK${NC}" | ||
| else | ||
| echo -e "${RED}FAILED${NC}" | ||
| echo -e "${YELLOW} Error details:${NC}" | ||
| echo " ${BUILD_OUTPUT//$'\n'/$'\n' }" | ||
| echo "" | ||
| ERRORS=$((ERRORS + 1)) | ||
| fi | ||
| CHECKED=$((CHECKED + 1)) | ||
| done | ||
|
|
||
| echo "" | ||
| echo "Summary: Checked $CHECKED kustomization.yaml file(s)" | ||
|
|
||
| if [[ $ERRORS -eq 0 ]]; then | ||
| echo -e "${GREEN}All kustomization files validated successfully!${NC}" | ||
| exit 0 | ||
| else | ||
| echo -e "${RED}$ERRORS kustomization file(s) failed validation${NC}" | ||
| exit 1 | ||
| fi | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.