Skip to content

Commit a467cc0

Browse files
committed
test: kubectl-validate manifests in presubmit
Signed-off-by: Ernest Wong <chwong719@gmail.com>
1 parent 4021279 commit a467cc0

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ verify: vet fmt-verify manifests generate ci-lint verify-all
158158

159159
# Run static analysis.
160160
.PHONY: verify-all
161-
verify-all:
161+
verify-all: kubectl-validate
162162
hack/verify-all.sh -v
163163

164164
##@ Build
@@ -347,13 +347,15 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
347347
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
348348
HELM = $(PROJECT_DIR)/bin/helm
349349
YQ = $(PROJECT_DIR)/bin/yq
350+
KUBECTL_VALIDATE = $(PROJECT_DIR)/bin/kubectl-validate
350351

351352
## Tool Versions
352353
KUSTOMIZE_VERSION ?= v5.4.3
353354
CONTROLLER_TOOLS_VERSION ?= v0.16.1
354355
ENVTEST_VERSION ?= release-0.19
355356
GOLANGCI_LINT_VERSION ?= v1.62.2
356357
HELM_VERSION ?= v3.17.1
358+
KUBECTL_VALIDATE_VERSION ?= v0.0.4
357359

358360
.PHONY: kustomize
359361
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -383,6 +385,11 @@ yq: ## Download yq locally if necessary.
383385
helm: ## Download helm locally if necessary.
384386
GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on go install helm.sh/helm/v3/cmd/helm@$(HELM_VERSION)
385387

388+
.PHONY: kubectl-validate
389+
kubectl-validate: $(KUBECTL_VALIDATE) ## Download kubectl-validate locally if necessary.
390+
$(KUBECTL_VALIDATE): $(LOCALBIN)
391+
$(call go-install-tool,$(KUBECTL_VALIDATE),sigs.k8s.io/kubectl-validate,$(KUBECTL_VALIDATE_VERSION))
392+
386393
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
387394
# $1 - target path with name of binary
388395
# $2 - package url which can be installed

hack/verify-manifests.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
23+
TEMP_DIR=$(mktemp -d)
24+
trap "rm -rf ${TEMP_DIR}" EXIT
25+
26+
cp ${SCRIPT_ROOT}/config/crd/bases/* "${TEMP_DIR}/"
27+
28+
# Download external CRDs for validation
29+
curl -sL https://raw.githubusercontent.com/GoogleCloudPlatform/gke-gateway-api/refs/tags/v1.4.0/config/crd/networking.gke.io_gcpbackendpolicies.yaml -o "${TEMP_DIR}/networking.gke.io_gcpbackendpolicies.yaml"
30+
curl -sL https://raw.githubusercontent.com/GoogleCloudPlatform/gke-gateway-api/refs/tags/v1.4.0/config/crd/networking.gke.io_healthcheckpolicies.yaml -o "${TEMP_DIR}/networking.gke.io_healthcheckpolicies.yaml"
31+
curl -sL https://raw.githubusercontent.com/istio/istio/refs/tags/1.26.2/manifests/charts/base/files/crd-all.gen.yaml -o "${TEMP_DIR}/istio_crds.yaml"
32+
33+
${SCRIPT_ROOT}/bin/kubectl-validate "${TEMP_DIR}"
34+
${SCRIPT_ROOT}/bin/kubectl-validate ${SCRIPT_ROOT}/config/manifests --local-crds "${TEMP_DIR}"

0 commit comments

Comments
 (0)