-
Notifications
You must be signed in to change notification settings - Fork 49
Add kustomize validation check #433
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
Open
sebrandon1
wants to merge
1
commit into
openshift-kni:main
Choose a base branch
from
sebrandon1:add_kustomization_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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,47 @@ | ||
| 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 | ||
|
|
||
| - name: Install Kustomize | ||
| run: | | ||
| # Download with retries to prevent flaky CI failures | ||
| MAX_ATTEMPTS=3 | ||
| ATTEMPT=1 | ||
| while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do | ||
| echo "Attempt $ATTEMPT of $MAX_ATTEMPTS: Downloading kustomize install script..." | ||
| if curl -fsSL --retry 3 --retry-delay 2 "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash; then | ||
| echo "Successfully downloaded and installed kustomize" | ||
| break | ||
| else | ||
| echo "Failed to install kustomize" | ||
| if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then | ||
| echo "All attempts failed" | ||
| exit 1 | ||
| fi | ||
| echo "Waiting 5 seconds before retry..." | ||
| sleep 5 | ||
| ATTEMPT=$((ATTEMPT + 1)) | ||
| fi | ||
| done | ||
| sudo mv kustomize /usr/local/bin/ | ||
| kustomize version | ||
| - 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,112 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| BLUE='\033[0;34m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| # Directories that require OpenShift ZTP external kustomize plugins | ||
| # These plugins (PolicyGenerator, ClusterInstance, SiteConfig, PolicyGenTemplate) are distributed | ||
| # via Red Hat container images and are designed to run in OpenShift ArgoCD with ACM/MCE installed. | ||
| # | ||
| # These plugins come from: | ||
| # - registry.redhat.io/openshift4/ztp-site-generate-rhel8 (ClusterInstance, SiteConfig) | ||
| # - registry.redhat.io/rhacm2/multicluster-operators-subscription-rhel9 (PolicyGenerator) | ||
| # | ||
| # They require: | ||
| # - KUSTOMIZE_PLUGIN_HOME environment variable | ||
| # - kustomize --enable-alpha-plugins flag | ||
| # - The plugin binaries extracted from the container images | ||
| # | ||
| # These can only be validated in an OpenShift cluster environment with ZTP tooling installed. | ||
| # Standard kustomize cannot process them without these prerequisites. | ||
| EXCLUDED_DIRS=( | ||
| "./telco-core/configuration" | ||
| "./telco-ran/configuration/argocd/example/acmpolicygenerator" | ||
| "./telco-ran/configuration/argocd/example/clusterinstance" | ||
| "./telco-ran/configuration/argocd/example/image-based-upgrades" | ||
| "./telco-ran/configuration/argocd/example/policygentemplates" | ||
| "./telco-ran/configuration/argocd/example/siteconfig" | ||
| ) | ||
|
|
||
| # Check if kustomize is installed | ||
| if ! command -v kustomize &> /dev/null; then | ||
| echo -e "${RED}ERROR: kustomize is not installed${NC}" | ||
| echo "" | ||
| echo "Please install kustomize to run this check:" | ||
| echo " - macOS: brew install kustomize" | ||
| echo " - Linux: curl -s \"https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh\" | bash" | ||
| echo " - Manual: https://kubectl.docs.kubernetes.io/installation/kustomize/" | ||
| echo "" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Checking all kustomization.yaml files can build successfully..." | ||
| echo "" | ||
|
|
||
| ERRORS=0 | ||
| CHECKED=0 | ||
| SKIPPED=0 | ||
|
|
||
| # Helper function to check if directory should be excluded | ||
| is_excluded() { | ||
| local dir="$1" | ||
| for excluded in "${EXCLUDED_DIRS[@]}"; do | ||
| if [ "$dir" = "$excluded" ]; then | ||
| return 0 | ||
| fi | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| # Find all kustomization.yaml files | ||
| kustomize_files=() | ||
| while IFS= read -r file; do | ||
| kustomize_files+=("$file") | ||
| done < <(find . -name 'kustomization.yaml' -not -path '*/venv/*' -not -path '*/.git/*' | 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: " | ||
|
|
||
| # Check if this directory requires external plugins | ||
| if is_excluded "$dir"; then | ||
| echo -e "${BLUE}SKIPPED${NC} (requires external plugins)" | ||
| SKIPPED=$((SKIPPED + 1)) | ||
| continue | ||
| fi | ||
|
|
||
| # Try to build the kustomization | ||
| if kustomize build "$dir" > /dev/null 2>&1; then | ||
| echo -e "${GREEN}OK${NC}" | ||
| CHECKED=$((CHECKED + 1)) | ||
| else | ||
| echo -e "${RED}FAILED${NC}" | ||
| echo -e "${YELLOW} Error details:${NC}" | ||
| kustomize build "$dir" 2>&1 | sed 's/^/ /' | ||
| echo "" | ||
| ERRORS=$((ERRORS + 1)) | ||
| CHECKED=$((CHECKED + 1)) | ||
| fi | ||
| done | ||
|
|
||
| echo "" | ||
| echo "Summary: Checked $CHECKED kustomization.yaml files, skipped $SKIPPED (require external plugins)" | ||
|
|
||
| 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.