Skip to content

Commit c597cc1

Browse files
committed
Allow OpenAPI verification to pass both with and without strict alpha
handling
1 parent 2b025e6 commit c597cc1

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

hack/update-openapi-spec.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ fi
7272
# Start kube-apiserver
7373
# omit enums from static openapi snapshots used to generate clients until #109177 is resolved
7474
kube::log::status "Starting kube-apiserver"
75-
kube-apiserver \
75+
# KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA ensures that the OpenAPI is updated with all APIs
76+
# that are intended to be removed at a particular release during alpha.
77+
# If a new version tag was just created and you are seeing an unrelated diff when adding
78+
# a new API, run `KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA=false ./hack/update-openapi-spec.sh`.
79+
KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA=${KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA:-true} kube-apiserver \
7680
--bind-address="${API_HOST}" \
7781
--secure-port="${API_PORT}" \
7882
--etcd-servers="http://${ETCD_HOST}:${ETCD_PORT}" \

hack/verify-openapi-spec.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
# limitations under the License.
1616

1717
# This script checks whether updating of OpenAPI specification is needed or not.
18+
# It verifies that the OpenAPI specification is up to date in strict mode, and
19+
# will fallback to check in non-strict mode if that fails. Strict mode removes
20+
# all APIs marked # as removed in a particular version, while non-strict mode
21+
# allows them to persist until the release cutoff. We allow non-strict to
22+
# prevent CI failures when we bump the version number in the git tag.
1823
# We should run `hack/update-openapi-spec.sh` if OpenAPI specification is out of
1924
# date.
2025
# Usage: `hack/verify-openapi-spec.sh`.
@@ -26,5 +31,7 @@ set -o pipefail
2631
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2732

2833
source "${KUBE_ROOT}/hack/lib/verify-generated.sh"
29-
30-
kube::verify::generated "Generated files need to be updated" "Please run 'hack/update-openapi-spec.sh'" hack/update-openapi-spec.sh "$@"
34+
(
35+
kube::verify::generated "Generated files failed strict alpha check and MAY need be updated" "Running verification again without strict alpha check" hack/update-openapi-spec.sh "$@"
36+
) || \
37+
KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA=false kube::verify::generated "Generated files need to be updated" "Please run 'hack/update-openapi-spec.sh'" hack/update-openapi-spec.sh "$@"

staging/src/k8s.io/apiserver/pkg/server/deleted_kinds.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ import (
3535
type resourceExpirationEvaluator struct {
3636
currentVersion *apimachineryversion.Version
3737
isAlpha bool
38+
// Special flag checking for the existence of alpha.0
39+
// alpha.0 is a special case where everything merged to master is auto propagated to the release-1.n branch
40+
isAlphaZero bool
3841
// This is usually set for testing for which tests need to be removed. This prevent insta-failing CI.
3942
// Set KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA to see what will be removed when we tag beta
43+
// This flag only takes effect during alpha but not alphaZero.
4044
strictRemovedHandlingInAlpha bool
4145
// This is usually set by a cluster-admin looking for a short-term escape hatch after something bad happened.
4246
// This should be made a flag before merge
@@ -64,6 +68,7 @@ func NewResourceExpirationEvaluator(currentVersion *apimachineryversion.Version)
6468
// Only keeps the major and minor versions from input version.
6569
ret.currentVersion = apimachineryversion.MajorMinor(currentVersion.Major(), currentVersion.Minor())
6670
ret.isAlpha = strings.Contains(currentVersion.PreRelease(), "alpha")
71+
ret.isAlphaZero = strings.Contains(currentVersion.PreRelease(), "alpha.0")
6772

6873
if envString, ok := os.LookupEnv("KUBE_APISERVER_STRICT_REMOVED_API_HANDLING_IN_ALPHA"); !ok {
6974
// do nothing
@@ -127,7 +132,7 @@ func (e *resourceExpirationEvaluator) ShouldServeForVersion(majorRemoved, minorR
127132
// at this point major and minor are equal, so this API should be removed when the current release GAs.
128133
// If this is an alpha tag, don't remove by default, but allow the option.
129134
// If the cluster-admin has requested serving one more release, allow it.
130-
if e.isAlpha && e.strictRemovedHandlingInAlpha { // don't serve in alpha if we want strict handling
135+
if e.isAlpha && !e.isAlphaZero && e.strictRemovedHandlingInAlpha { // don't serve in alpha.1+ if we want strict handling
131136
return false
132137
}
133138
if e.isAlpha { // alphas are allowed to continue serving expired betas while we clean up the test

staging/src/k8s.io/apiserver/pkg/server/deleted_kinds_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ func Test_newResourceExpirationEvaluator(t *testing.T) {
4242
expected: resourceExpirationEvaluator{currentVersion: apimachineryversion.MajorMinor(1, 20)},
4343
},
4444
{
45-
name: "alpha",
45+
name: "alpha .0",
4646
currentVersion: "v1.20.0-alpha.0.62+a5d22854a2ac21",
47-
expected: resourceExpirationEvaluator{currentVersion: apimachineryversion.MajorMinor(1, 20), isAlpha: true},
47+
expected: resourceExpirationEvaluator{currentVersion: apimachineryversion.MajorMinor(1, 20), isAlpha: true, isAlphaZero: true},
4848
},
49+
{
50+
name: "alpha not .0",
51+
currentVersion: "v1.20.0-alpha.1.62+a5d22854a2ac21",
52+
expected: resourceExpirationEvaluator{currentVersion: apimachineryversion.MajorMinor(1, 20), isAlpha: true, isAlphaZero: false},
53+
},
54+
4955
{
5056
name: "maintenance",
5157
currentVersion: "v1.20.1",
@@ -196,6 +202,17 @@ func Test_resourceExpirationEvaluator_shouldServe(t *testing.T) {
196202
restStorage: storageRemovedIn(1, 20),
197203
expected: false,
198204
},
205+
{
206+
name: "removed-in-curr-but-alpha-but-strict-and-alpha-zero",
207+
resourceExpirationEvaluator: resourceExpirationEvaluator{
208+
currentVersion: apimachineryversion.MajorMinor(1, 20),
209+
isAlpha: true,
210+
isAlphaZero: true,
211+
strictRemovedHandlingInAlpha: true,
212+
},
213+
restStorage: storageRemovedIn(1, 20),
214+
expected: true,
215+
},
199216
{
200217
name: "removed-in-prev-deferral-does-not-help",
201218
resourceExpirationEvaluator: resourceExpirationEvaluator{

0 commit comments

Comments
 (0)