From 916d8c4ec292b59d7aee66d57990a283d89603c9 Mon Sep 17 00:00:00 2001 From: Lior Lieberman Date: Mon, 5 Feb 2024 17:46:53 +0000 Subject: [PATCH 1/4] add github workflow to check supportedFeatures freshness --- .github/workflows/supported_features.yml | 27 ++++++++++++++++++++++++ conformance/utils/suite/features.go | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/supported_features.yml diff --git a/.github/workflows/supported_features.yml b/.github/workflows/supported_features.yml new file mode 100644 index 0000000000..6e48b81a4f --- /dev/null +++ b/.github/workflows/supported_features.yml @@ -0,0 +1,27 @@ +name: 'kubebuilder-supported-features-freshness' +on: + pull_request: + branches: + - main + - master + 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' + 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}" + exit 1 + fi diff --git a/conformance/utils/suite/features.go b/conformance/utils/suite/features.go index f3c4689a8b..2726542625 100644 --- a/conformance/utils/suite/features.go +++ b/conformance/utils/suite/features.go @@ -217,7 +217,7 @@ var MeshCoreFeatures = sets.New( // AllFeatures contains all the supported features and can be used to run all // conformance tests with `all-features` flag. -// +// asd // NOTE: as new feature sets are added they should be inserted into this set. var AllFeatures = sets.New[SupportedFeature](). Insert(GatewayExtendedFeatures.UnsortedList()...). From b40893e6636068ffcd0b4f37cb774ef7ff99cc6b Mon Sep 17 00:00:00 2001 From: Lior Lieberman Date: Mon, 5 Feb 2024 18:06:37 +0000 Subject: [PATCH 2/4] adding missing supportedFeatures to kubebuilder validation --- .github/workflows/supported_features.yml | 1 - apis/v1/gatewayclass_types.go | 2 +- conformance/utils/suite/features.go | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/supported_features.yml b/.github/workflows/supported_features.yml index 6e48b81a4f..29186e4ce4 100644 --- a/.github/workflows/supported_features.yml +++ b/.github/workflows/supported_features.yml @@ -3,7 +3,6 @@ on: pull_request: branches: - main - - master paths: - 'conformance/utils/suite/**' jobs: diff --git a/apis/v1/gatewayclass_types.go b/apis/v1/gatewayclass_types.go index becbc14b23..b4f2104d28 100644 --- a/apis/v1/gatewayclass_types.go +++ b/apis/v1/gatewayclass_types.go @@ -266,5 +266,5 @@ 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 +// +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 diff --git a/conformance/utils/suite/features.go b/conformance/utils/suite/features.go index 2726542625..f3c4689a8b 100644 --- a/conformance/utils/suite/features.go +++ b/conformance/utils/suite/features.go @@ -217,7 +217,7 @@ var MeshCoreFeatures = sets.New( // AllFeatures contains all the supported features and can be used to run all // conformance tests with `all-features` flag. -// asd +// // NOTE: as new feature sets are added they should be inserted into this set. var AllFeatures = sets.New[SupportedFeature](). Insert(GatewayExtendedFeatures.UnsortedList()...). From 54fd807d1dec9754723a9e4936b01667457a4845 Mon Sep 17 00:00:00 2001 From: Lior Lieberman Date: Mon, 5 Feb 2024 21:17:03 +0000 Subject: [PATCH 3/4] add action item if kubebuilder freshness check fails --- .github/workflows/supported_features.yml | 2 ++ .../gateway.networking.k8s.io_gatewayclasses.yaml | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/supported_features.yml b/.github/workflows/supported_features.yml index 29186e4ce4..5765bb699c 100644 --- a/.github/workflows/supported_features.yml +++ b/.github/workflows/supported_features.yml @@ -15,6 +15,7 @@ jobs: 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) @@ -22,5 +23,6 @@ jobs: 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 \`go run hack/supportedfeatures/main.go\` and update +kubebuilder:validation:Enum in gatewayclass_types.go${NC}" exit 1 fi diff --git a/config/crd/experimental/gateway.networking.k8s.io_gatewayclasses.yaml b/config/crd/experimental/gateway.networking.k8s.io_gatewayclasses.yaml index 3aa0cc0bbe..4e77fb0ed1 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_gatewayclasses.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_gatewayclasses.yaml @@ -268,15 +268,20 @@ spec: - GatewayPort8080 - GatewayStaticAddresses - HTTPRoute + - HTTPRouteBackendProtocolH2C + - HTTPRouteBackendProtocolWebSocket + - HTTPRouteBackendTimeout - HTTPRouteDestinationPortMatching - HTTPRouteHostRewrite - HTTPRouteMethodMatching + - HTTPRouteParentRefPort - HTTPRoutePathRedirect - HTTPRoutePathRewrite - HTTPRoutePortRedirect - HTTPRouteQueryParamMatching - HTTPRouteRequestMirror - HTTPRouteRequestMultipleMirrors + - HTTPRouteRequestTimeout - HTTPRouteResponseHeaderModification - HTTPRouteSchemeRedirect - Mesh @@ -542,15 +547,20 @@ spec: - GatewayPort8080 - GatewayStaticAddresses - HTTPRoute + - HTTPRouteBackendProtocolH2C + - HTTPRouteBackendProtocolWebSocket + - HTTPRouteBackendTimeout - HTTPRouteDestinationPortMatching - HTTPRouteHostRewrite - HTTPRouteMethodMatching + - HTTPRouteParentRefPort - HTTPRoutePathRedirect - HTTPRoutePathRewrite - HTTPRoutePortRedirect - HTTPRouteQueryParamMatching - HTTPRouteRequestMirror - HTTPRouteRequestMultipleMirrors + - HTTPRouteRequestTimeout - HTTPRouteResponseHeaderModification - HTTPRouteSchemeRedirect - Mesh From ba96bfef000952b3cf50cd8e6f6afd4a3e3194cd Mon Sep 17 00:00:00 2001 From: Lior Lieberman Date: Tue, 6 Feb 2024 17:09:04 +0000 Subject: [PATCH 4/4] add update_supported_features.sh --- .github/workflows/supported_features.yml | 2 +- apis/v1/gatewayclass_types.go | 2 ++ .../update_supported_features.sh | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 hack/supportedfeatures/update_supported_features.sh diff --git a/.github/workflows/supported_features.yml b/.github/workflows/supported_features.yml index 5765bb699c..1c7dd9f285 100644 --- a/.github/workflows/supported_features.yml +++ b/.github/workflows/supported_features.yml @@ -23,6 +23,6 @@ jobs: 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 \`go run hack/supportedfeatures/main.go\` and update +kubebuilder:validation:Enum in gatewayclass_types.go${NC}" + echo -e "${YELLOW}Please run \`hack/supportedfeatures/update_supported_features.sh\` to update kubebuilder:validation:Enum list${NC}" exit 1 fi diff --git a/apis/v1/gatewayclass_types.go b/apis/v1/gatewayclass_types.go index b4f2104d28..72725a6ac2 100644 --- a/apis/v1/gatewayclass_types.go +++ b/apis/v1/gatewayclass_types.go @@ -266,5 +266,7 @@ type GatewayClassList struct { // SupportedFeature is used to describe distinct features that are covered by // conformance tests. +// +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 diff --git a/hack/supportedfeatures/update_supported_features.sh b/hack/supportedfeatures/update_supported_features.sh new file mode 100755 index 0000000000..58d93dd337 --- /dev/null +++ b/hack/supportedfeatures/update_supported_features.sh @@ -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|}"