Skip to content

Commit 68a452d

Browse files
committed
CNFCERT-1258: Add kustomize validation check
1 parent 12d971a commit 68a452d

5 files changed

Lines changed: 180 additions & 4 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Kustomize Validation
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
kustomize-validation:
13+
name: Validate Kustomization Files
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install Kustomize
20+
run: |
21+
# Download with retries to prevent flaky CI failures
22+
MAX_ATTEMPTS=3
23+
ATTEMPT=1
24+
25+
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
26+
echo "Attempt $ATTEMPT of $MAX_ATTEMPTS: Downloading kustomize install script..."
27+
if curl -fsSL --retry 3 --retry-delay 2 "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash; then
28+
echo "Successfully downloaded and installed kustomize"
29+
break
30+
else
31+
echo "Failed to install kustomize"
32+
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
33+
echo "All attempts failed"
34+
exit 1
35+
fi
36+
echo "Waiting 5 seconds before retry..."
37+
sleep 5
38+
ATTEMPT=$((ATTEMPT + 1))
39+
fi
40+
done
41+
42+
sudo mv kustomize /usr/local/bin/
43+
kustomize version
44+
45+
- name: Validate Kustomization Files
46+
run: make test-kustomize
47+

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,6 @@ linters-settings:
152152
- .WrapPrefixf(
153153
run:
154154
concurrency: 6
155-
timeout: 10m
155+
timeout: 5m
156156
skip-files:
157157
- ".*_test\\.go"

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ check-coverage: install-go-test-coverage
213213
${GOBIN}/go-test-coverage --config=./.testcoverage.yml
214214

215215
.PHONY: ci-job
216-
ci-job: common-deps-update generate fmt vet golangci-lint unittest shellcheck bashate yamllint bundle-check
216+
ci-job: common-deps-update generate fmt vet golangci-lint unittest shellcheck bashate yamllint test-kustomize bundle-check
217217

218218
# Download go tools
219219
.PHONY: controller-gen
@@ -347,11 +347,17 @@ GINKGO_FLAGS = -ginkgo.focus="$(FOCUS)" -ginkgo.v -ginkgo.skip="$(SKIP)"
347347
##@ Tools and Linting
348348

349349
.PHONY: lint
350-
lint: bashate golangci-lint shellcheck yamllint markdownlint
350+
lint: bashate golangci-lint shellcheck yamllint markdownlint test-kustomize
351351

352352
.PHONY: tools
353353
tools: opm operator-sdk yq
354354

355+
.PHONY: test-kustomize
356+
test-kustomize: kustomize ## Validate all kustomization.yaml files can build successfully
357+
@echo "Running kustomize validation on all kustomization.yaml files..."
358+
@$(PROJECT_DIR)/hack/test-kustomize.sh
359+
@echo "Kustomize validation completed successfully."
360+
355361
.PHONY: bashate-download
356362
bashate-download: sync-git-submodules $(LOCALBIN) ## Download bashate locally if necessary and run against bash files. If wrong version is installed, it will be removed before downloading.
357363
@echo "Downloading bashate..."

hack/test-kustomize.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
BLUE='\033[0;34m'
10+
NC='\033[0m' # No Color
11+
12+
# Temporary file tracking for cleanup
13+
TEMP_FILES=()
14+
15+
# Cleanup function (invoked via trap, not called directly)
16+
# shellcheck disable=SC2329
17+
cleanup() {
18+
if [ ${#TEMP_FILES[@]} -gt 0 ]; then
19+
echo ""
20+
echo "Cleaning up temporary files..."
21+
for temp_file in "${TEMP_FILES[@]}"; do
22+
if [ -f "$temp_file" ]; then
23+
rm -f "$temp_file"
24+
echo " Removed: $temp_file"
25+
fi
26+
done
27+
fi
28+
}
29+
30+
# Set trap to ensure cleanup on exit
31+
trap cleanup EXIT
32+
33+
# Directories requiring external kustomize plugins (e.g., PolicyGenerator, ClusterInstance)
34+
EXCLUDED_DIRS=()
35+
36+
# Check if kustomize is installed
37+
if ! command -v kustomize &> /dev/null; then
38+
echo -e "${RED}ERROR: kustomize is not installed${NC}"
39+
echo ""
40+
echo "Please install kustomize to run this check:"
41+
echo " - macOS: brew install kustomize"
42+
echo " - Linux: curl -s \"https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh\" | bash"
43+
echo " - Manual: https://kubectl.docs.kubernetes.io/installation/kustomize/"
44+
echo ""
45+
exit 1
46+
fi
47+
48+
# Generate temporary patch files that are normally created during build
49+
# config/manager/related-images/patch.yaml is generated from in.yaml with envsubst
50+
PATCH_FILE="./config/manager/related-images/patch.yaml"
51+
if [ ! -f "$PATCH_FILE" ] && [ -f "./config/manager/related-images/in.yaml" ]; then
52+
echo "Generating temporary patch file for validation: $PATCH_FILE"
53+
# Use a placeholder value for PRECACHE_WORKLOAD_IMG
54+
PRECACHE_WORKLOAD_IMG="quay.io/openshift-kni/lifecycle-agent-operator:latest" envsubst < "./config/manager/related-images/in.yaml" > "$PATCH_FILE"
55+
TEMP_FILES+=("$PATCH_FILE")
56+
echo ""
57+
fi
58+
59+
echo "Checking all kustomization.yaml files can build successfully..."
60+
echo ""
61+
62+
ERRORS=0
63+
CHECKED=0
64+
SKIPPED=0
65+
66+
# Helper function to check if directory should be excluded
67+
is_excluded() {
68+
local dir="$1"
69+
for excluded in "${EXCLUDED_DIRS[@]}"; do
70+
if [ "$dir" = "$excluded" ]; then
71+
return 0
72+
fi
73+
done
74+
return 1
75+
}
76+
77+
# Find all kustomization.yaml files
78+
kustomize_files=()
79+
while IFS= read -r file; do
80+
kustomize_files+=("$file")
81+
done < <(find . -name 'kustomization.yaml' -not -path '*/vendor/*' -not -path '*/.git/*' -not -path '*/bin/*' -not -path '*/telco5g-konflux/*' | sort)
82+
83+
if [ ${#kustomize_files[@]} -eq 0 ]; then
84+
echo -e "${YELLOW}WARNING: No kustomization.yaml files found${NC}"
85+
exit 0
86+
fi
87+
88+
for kustomize_file in "${kustomize_files[@]}"; do
89+
dir=$(dirname "$kustomize_file")
90+
echo -n " $dir: "
91+
92+
# Check if this directory requires external plugins
93+
if is_excluded "$dir"; then
94+
echo -e "${BLUE}SKIPPED${NC} (requires external plugins)"
95+
SKIPPED=$((SKIPPED + 1))
96+
continue
97+
fi
98+
99+
BUILD_OUTPUT=$(kustomize build "$dir" 2>&1)
100+
if [ $? -eq 0 ]; then
101+
echo -e "${GREEN}OK${NC}"
102+
else
103+
echo -e "${RED}FAILED${NC}"
104+
echo -e "${YELLOW} Error details:${NC}"
105+
echo " ${BUILD_OUTPUT//$'\n'/$'\n' }"
106+
echo ""
107+
ERRORS=$((ERRORS + 1))
108+
fi
109+
CHECKED=$((CHECKED + 1))
110+
done
111+
112+
echo ""
113+
echo "Summary: Checked $CHECKED kustomization.yaml files, skipped $SKIPPED (require external plugins)"
114+
115+
if [[ $ERRORS -eq 0 ]]; then
116+
echo -e "${GREEN}All kustomization files validated successfully!${NC}"
117+
exit 0
118+
else
119+
echo -e "${RED}$ERRORS kustomization file(s) failed validation${NC}"
120+
exit 1
121+
fi
122+

internal/clusterconfig/lvmconfig.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ func (r *UpgradeClusterConfigGather) fetchLocalVolumes(ctx context.Context, mani
9898

9999
var scNameSet = make(map[string]bool)
100100
for _, lv := range lvsList.Items {
101-
CleanResource(&lv)
101+
lv.SetUID("")
102+
lv.SetResourceVersion("")
102103

103104
lvFileName := fmt.Sprintf("%s_%s_%s.json", lv.GetKind(), lv.GetName(), lv.GetNamespace())
104105
filePath := filepath.Join(manifestsDir, lvFileName)

0 commit comments

Comments
 (0)