Skip to content

Commit 15b4356

Browse files
embikkcp-ci-bot
authored andcommitted
Add hack/verify-apiresourceschemas.sh to ensure immutability
On-behalf-of: SAP <marvin.beckers@sap.com> Signed-off-by: Marvin Beckers <marvin@kubermatic.com>
1 parent 1ed1a49 commit 15b4356

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ verify-codegen: ## Verify codegen
224224
exit 1; \
225225
fi
226226

227+
./hack/verify-apiresourceschemas.sh
228+
227229
.PHONY: imports
228230
imports: WHAT ?=
229231
imports: $(GOLANGCI_LINT) verify-go-versions

hack/verify-apiresourceschemas.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The KCP 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+
# This script ensures that the generated client code checked into git is up-to-date
18+
# with the generator. If it is not, re-generate the configuration to update it.
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
TARGET_REF=${PULL_BASE_REF:-main}
25+
26+
find config/root-phase0 -name 'apiresourceschema-*.yaml' | while read schema
27+
do
28+
if ! git diff --exit-code ${TARGET_REF} -- ${schema} 2>&1 >/dev/null; then
29+
current_name=$(yq '.metadata.name' ${schema})
30+
previous_name=$(git show ${TARGET_REF}:${schema} | yq '.metadata.name')
31+
32+
if [ "${current_name}" == "${previous_name}" ]; then
33+
echo "${schema} has changed in comparison to '${TARGET_REF}', but object name is the same (${current_name} == ${previous_name})."
34+
echo "This is not valid as APIResourceSchemas are immutable."
35+
echo "Please run \`make crds\` without modifying APIResourceSchema files manually."
36+
exit 1
37+
fi
38+
fi
39+
done

0 commit comments

Comments
 (0)