Skip to content

Commit

Permalink
Merge pull request #2754 from LiorLieberman/add-check-for-kubebuilder…
Browse files Browse the repository at this point in the history
…-validation

add github workflow to check supportedFeatures freshness
  • Loading branch information
k8s-ci-robot authored Feb 6, 2024
2 parents 69831b5 + ba96bfe commit 38f6299
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/workflows/supported_features.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 'kubebuilder-supported-features-freshness'
on:
pull_request:
branches:
- main
paths:
- 'conformance/utils/suite/**'
jobs:
checker:
runs-on: ubuntu-latest
steps:
- name: 'checkout'
uses: actions/checkout@v4
- name: 'check_diff'
run: |
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='‘\033[1;33m'
NC='\033[0m'
current_features=$(grep -B 1 'type SupportedFeature string' apis/v1/gatewayclass_types.go | grep -oP '// \+kubebuilder:validation:Enum=\K.*')
expected_features=$(go run hack/supportedfeatures/main.go)
if [[ "$current_features" != "$expected_features" ]]; then
echo "found diff between the current and the expected supportedFeatures"
echo -e "expected: ${GREEN}${expected_features}${NC}"
echo -e "current: ${RED}${current_features}${NC}"
echo -e "${YELLOW}Please run \`hack/supportedfeatures/update_supported_features.sh\` to update kubebuilder:validation:Enum list${NC}"
exit 1
fi
4 changes: 3 additions & 1 deletion apis/v1/gatewayclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,7 @@ type GatewayClassList struct {

// SupportedFeature is used to describe distinct features that are covered by
// conformance tests.
// +kubebuilder:validation:Enum=Gateway;GatewayPort8080;GatewayStaticAddresses;HTTPRoute;HTTPRouteDestinationPortMatching;HTTPRouteHostRewrite;HTTPRouteMethodMatching;HTTPRoutePathRedirect;HTTPRoutePathRewrite;HTTPRoutePortRedirect;HTTPRouteQueryParamMatching;HTTPRouteRequestMirror;HTTPRouteRequestMultipleMirrors;HTTPRouteResponseHeaderModification;HTTPRouteSchemeRedirect;Mesh;ReferenceGrant;TLSRoute
// +NOTE kububuilder enum validation below has a freshness check configured.
// +Please refrain from adding a line between the line below and `type SupportedFeature string`.
// +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
type SupportedFeature string

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions hack/supportedfeatures/update_supported_features.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Copyright 2024 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

expected_features=$(go run hack/supportedfeatures/main.go)
sed -i -E "/^\/\/\s\+kubebuilder:validation:Enum=/ {N; s|(\/\/\s\+kubebuilder:validation:Enum=)(.*)(\ntype\sSupportedFeature\sstring)|\1$expected_features\3|}"

0 comments on commit 38f6299

Please sign in to comment.