Skip to content

Commit 38f6299

Browse files
authored
Merge pull request #2754 from LiorLieberman/add-check-for-kubebuilder-validation
add github workflow to check supportedFeatures freshness
2 parents 69831b5 + ba96bfe commit 38f6299

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 'kubebuilder-supported-features-freshness'
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
paths:
7+
- 'conformance/utils/suite/**'
8+
jobs:
9+
checker:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: 'checkout'
13+
uses: actions/checkout@v4
14+
- name: 'check_diff'
15+
run: |
16+
RED='\033[0;31m'
17+
GREEN='\033[0;32m'
18+
YELLOW='‘\033[1;33m'
19+
NC='\033[0m'
20+
current_features=$(grep -B 1 'type SupportedFeature string' apis/v1/gatewayclass_types.go | grep -oP '// \+kubebuilder:validation:Enum=\K.*')
21+
expected_features=$(go run hack/supportedfeatures/main.go)
22+
if [[ "$current_features" != "$expected_features" ]]; then
23+
echo "found diff between the current and the expected supportedFeatures"
24+
echo -e "expected: ${GREEN}${expected_features}${NC}"
25+
echo -e "current: ${RED}${current_features}${NC}"
26+
echo -e "${YELLOW}Please run \`hack/supportedfeatures/update_supported_features.sh\` to update kubebuilder:validation:Enum list${NC}"
27+
exit 1
28+
fi

apis/v1/gatewayclass_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,7 @@ type GatewayClassList struct {
266266

267267
// SupportedFeature is used to describe distinct features that are covered by
268268
// conformance tests.
269-
// +kubebuilder:validation:Enum=Gateway;GatewayPort8080;GatewayStaticAddresses;HTTPRoute;HTTPRouteDestinationPortMatching;HTTPRouteHostRewrite;HTTPRouteMethodMatching;HTTPRoutePathRedirect;HTTPRoutePathRewrite;HTTPRoutePortRedirect;HTTPRouteQueryParamMatching;HTTPRouteRequestMirror;HTTPRouteRequestMultipleMirrors;HTTPRouteResponseHeaderModification;HTTPRouteSchemeRedirect;Mesh;ReferenceGrant;TLSRoute
269+
// +NOTE kububuilder enum validation below has a freshness check configured.
270+
// +Please refrain from adding a line between the line below and `type SupportedFeature string`.
271+
// +kubebuilder:validation:Enum=Gateway;GatewayPort8080;GatewayStaticAddresses;HTTPRoute;HTTPRouteBackendProtocolH2C;HTTPRouteBackendProtocolWebSocket;HTTPRouteBackendTimeout;HTTPRouteDestinationPortMatching;HTTPRouteHostRewrite;HTTPRouteMethodMatching;HTTPRouteParentRefPort;HTTPRoutePathRedirect;HTTPRoutePathRewrite;HTTPRoutePortRedirect;HTTPRouteQueryParamMatching;HTTPRouteRequestMirror;HTTPRouteRequestMultipleMirrors;HTTPRouteRequestTimeout;HTTPRouteResponseHeaderModification;HTTPRouteSchemeRedirect;Mesh;ReferenceGrant;TLSRoute
270272
type SupportedFeature string

config/crd/experimental/gateway.networking.k8s.io_gatewayclasses.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Copyright 2024 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+
expected_features=$(go run hack/supportedfeatures/main.go)
18+
sed -i -E "/^\/\/\s\+kubebuilder:validation:Enum=/ {N; s|(\/\/\s\+kubebuilder:validation:Enum=)(.*)(\ntype\sSupportedFeature\sstring)|\1$expected_features\3|}"

0 commit comments

Comments
 (0)