Skip to content

Commit 52f6c94

Browse files
committed
test: kubectl-validate manifests in presubmit
Signed-off-by: Ernest Wong <[email protected]>
1 parent 5c58ef2 commit 52f6c94

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,15 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
354354
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
355355
HELM = $(PROJECT_DIR)/bin/helm
356356
YQ = $(PROJECT_DIR)/bin/yq
357+
KUBECTL_VALIDATE = $(PROJECT_DIR)/bin/kubectl-validate
357358

358359
## Tool Versions
359360
KUSTOMIZE_VERSION ?= v5.4.3
360361
CONTROLLER_TOOLS_VERSION ?= v0.16.1
361362
ENVTEST_VERSION ?= release-0.19
362363
GOLANGCI_LINT_VERSION ?= v1.62.2
363364
HELM_VERSION ?= v3.17.1
365+
KUBECTL_VALIDATE_VERSION ?= v0.0.4
364366

365367
.PHONY: kustomize
366368
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -390,6 +392,11 @@ yq: ## Download yq locally if necessary.
390392
helm: ## Download helm locally if necessary.
391393
GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on go install helm.sh/helm/v3/cmd/helm@$(HELM_VERSION)
392394

395+
.PHONY: kubectl-validate
396+
kubectl-validate: $(KUBECTL_VALIDATE) ## Download kubectl-validate locally if necessary.
397+
$(KUBECTL_VALIDATE): $(LOCALBIN)
398+
$(call go-install-tool,$(KUBECTL_VALIDATE),sigs.k8s.io/kubectl-validate,$(KUBECTL_VALIDATE_VERSION))
399+
393400
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
394401
# $1 - target path with name of binary
395402
# $2 - package url which can be installed

hack/verify-manifests.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/..
22+
GATEWAY_API_VERSION="${GATEWAY_API_VERSION:-v1.3.0}"
23+
GKE_GATEWAY_API_VERSION="${GKE_GATEWAY_API_VERSION:-v1.4.0}"
24+
ISTIO_VERSION="${ISTIO_VERSION:-1.26.2}"
25+
TEMP_DIR=$(mktemp -d)
26+
27+
cleanup() {
28+
rm -rf "${TEMP_DIR}" || true
29+
}
30+
trap cleanup EXIT
31+
32+
fetch_crds() {
33+
local url="$1"
34+
curl -sL "${url}" -o "${TEMP_DIR}/$(basename "${url}")"
35+
}
36+
37+
main() {
38+
cp ${SCRIPT_ROOT}/config/crd/bases/* "${TEMP_DIR}/"
39+
40+
# Download external CRDs for validation
41+
fetch_crds "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/refs/tags/${GATEWAY_API_VERSION}/config/crd/standard/gateway.networking.k8s.io_gateways.yaml"
42+
fetch_crds "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/refs/tags/${GATEWAY_API_VERSION}/config/crd/standard/gateway.networking.k8s.io_httproutes.yaml"
43+
fetch_crds "https://raw.githubusercontent.com/GoogleCloudPlatform/gke-gateway-api/refs/tags/${GKE_GATEWAY_API_VERSION}/config/crd/networking.gke.io_gcpbackendpolicies.yaml"
44+
fetch_crds "https://raw.githubusercontent.com/GoogleCloudPlatform/gke-gateway-api/refs/tags/${GKE_GATEWAY_API_VERSION}/config/crd/networking.gke.io_healthcheckpolicies.yaml"
45+
fetch_crds "https://raw.githubusercontent.com/istio/istio/refs/tags/${ISTIO_VERSION}/manifests/charts/base/files/crd-all.gen.yaml"
46+
47+
make kubectl-validate
48+
49+
${SCRIPT_ROOT}/bin/kubectl-validate "${TEMP_DIR}"
50+
${SCRIPT_ROOT}/bin/kubectl-validate "${SCRIPT_ROOT}/config/manifests" --local-crds "${TEMP_DIR}"
51+
}
52+
53+
main

0 commit comments

Comments
 (0)