Skip to content

Conversation

@chris-kaiser-7
Copy link

What type of PR is this?

/kind feature

What this PR does / why we need it:
This is required for the release changes https://docs.google.com/document/d/1iG6RKVJFZUxG1mZ4NbUL5Tm09n_zDck-LukYmUXoQ7c/edit?tab=t.0

Which issue(s) this PR fixes:

Fixes #
VAP for Upgrades #4162

Does this PR introduce a user-facing change?:

Adds a VAP that prohibits the following:
- Installation of experimental CRDs on top of standard channel CRDs (within the same API group)
- Installation of monthly releases
- Installation of older releases

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 12, 2025
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 12, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @chris-kaiser-7. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@chris-kaiser-7 chris-kaiser-7 changed the title [WIP] Vap for updates 4162 [WIP] Vap for updates Oct 12, 2025
Copy link
Contributor

@kflynn kflynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of very minor nits -- thanks very much for digging into this!

api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/3328
gateway.networking.k8s.io/bundle-version: v1.4.0
gateway.networking.k8s.io/channel: standard
name: "gateway-api-safe-upgrades.gateway.networking.k8s.io"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Should we drop the domain here?

Copy link
Author

@chris-kaiser-7 chris-kaiser-7 Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think it should be named "safe-upgrades.gateway.networking.k8s.io"? Yea it is a little redundant to have gateway api twice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think it should be named "safe-upgrades.gateway.networking.k8s.io"? Yea it is a little redundant to have gateway api twice.

Yep, I think that would be a nice simplification here

@kflynn
Copy link
Contributor

kflynn commented Oct 16, 2025

/approve

Looks good to me with a couple of minor comments, leaving the final LGTM for someone else -- thanks, @chris-kaiser-7! 🙂

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: chris-kaiser-7, kflynn
Once this PR has been reviewed and has the lgtm label, please assign aojea for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kflynn
Copy link
Contributor

kflynn commented Oct 16, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 16, 2025
operations: ["CREATE", "UPDATE"]
resources: ["*"]
validations:
- expression: "object.spec.group != 'gateway.networking.k8s.io' ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't block XListenerSet, XMesh, etc. Is that intended?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No its not. I'll fix that.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 16, 2025
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 16, 2025
Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chris-kaiser-7, this is a really great change! Any chance that you could include some basic tests for this VAP?

I'm thinking that we'd want them to validate the following behavior when the VAP is installed:

  1. Experimental CRDs that are part of x-k8s.io can be installed
  2. Experimental CRDs that are part of k8s.io can NOT be installed
  3. Standard CRDs with an old version can NOT be installed
  4. Standard CRDs with the current version can be installed

It might actually be possible in https://github.com/kubernetes-sigs/gateway-api/blob/150554d3a55b731d3261525cf265bc930d2d5d85/pkg/test/crd/crd_test.go, but I'll defer to @rikatz on the best home for this.

message: "Installing experimental CRDs on top of standard channel CRDs is prohibited by default. Uninstall ValidatingAdmissionPolicy gateway-api-safe-upgrades.gateway.networking.k8s.io to install experimental CRDs on top of standard channel CRDs."
reason: Invalid
- expression: "(object.spec.group != 'gateway.networking.k8s.io' && object.spec.group != 'gateway.networking.x-k8s.io') ||
(!matches(object.metadata.annotations['gateway.networking.k8s.io/bundle-version'], 'v1.[0-3].\\\\d+') &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding a note to RELEASE.md to include a step to update this value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea good idea. The logic is a bit weird because CEL doesn't allow match groups in regex as far as I can tell so the regex gets a bit long.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note in RELEASE.md. I was thinking I could add a script in hack to update this regex based on the bundle version. That would make the process easier.

annotations:
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/3328
gateway.networking.k8s.io/bundle-version: v1.4.0
gateway.networking.k8s.io/channel: standard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure if this should be part of a release channel or not. Fine for now, but may want to adjust if we make a VAP that is meant to be included with both release channels.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about this too.

annotations:
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/3328
gateway.networking.k8s.io/bundle-version: v1.4.0
gateway.networking.k8s.io/channel: standard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above - unsure if this is necessary

@rikatz
Copy link
Member

rikatz commented Oct 16, 2025

/cc
/assign

@chris-kaiser-7
Copy link
Author

Thanks @chris-kaiser-7, this is a really great change! Any chance that you could include some basic tests for this VAP?

I'm thinking that we'd want them to validate the following behavior when the VAP is installed:

  1. Experimental CRDs that are part of x-k8s.io can be installed
  2. Experimental CRDs that are part of k8s.io can NOT be installed
  3. Standard CRDs with an old version can NOT be installed
  4. Standard CRDs with the current version can be installed

It might actually be possible in https://github.com/kubernetes-sigs/gateway-api/blob/150554d3a55b731d3261525cf265bc930d2d5d85/pkg/test/crd/crd_test.go, but I'll defer to @rikatz on the best home for this.

Thanks for the review. I just started working on the tests.

matchResources:
objectSelector: {}

# !has(object.metadata.annotations['gateway.networking.k8s.io/channel']) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this something required or something that was on file and was left behind?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I didn't notice that. I cleaned it up.

policyName: gateway-api-safe-upgrades.gateway.networking.k8s.io
validationActions: [Deny]
matchResources:
objectSelector: {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add the object selector of CRDs here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say something like:

spec.matchResources.resourceRules.apiGroups = apiextensions.k8s.io
spec.matchResources...apiVersions=v1
spec.matchResources...resources=customresourcedefinitions

Not sure this would properly work, but if so the idea is at least to filter out this binding and not send every resource validation to our VAP

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did look into this but had issues selecting crds with this. I'll look into again tho.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK never mind it seems to be working as you said. I must have done something wrong before when testing resourcerRules in binding.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 23, 2025
@chris-kaiser-7
Copy link
Author

Thanks @chris-kaiser-7, this is a really great change! Any chance that you could include some basic tests for this VAP?

I'm thinking that we'd want them to validate the following behavior when the VAP is installed:

  1. Experimental CRDs that are part of x-k8s.io can be installed
  2. Experimental CRDs that are part of k8s.io can NOT be installed
  3. Standard CRDs with an old version can NOT be installed
  4. Standard CRDs with the current version can be installed

It might actually be possible in https://github.com/kubernetes-sigs/gateway-api/blob/150554d3a55b731d3261525cf265bc930d2d5d85/pkg/test/crd/crd_test.go, but I'll defer to @rikatz on the best home for this.

I pushed some tests in CRD_test. I can move them to a separate test file if that is better. I also made a few changes to that. I pulled some of the init tests up a level so you can run isolated tests like. "make test.crds-validation GO_TEST_FLAGS="-run TestCRDValidation/safeupgrades_VAP_should_validate_correctly"".

@chris-kaiser-7
Copy link
Author

I noticed a race condition and spent a while trying to fix it without time.sleep. I'm going to look at this some more but figured I should push what I got.

@chris-kaiser-7 chris-kaiser-7 changed the title [WIP] Vap for updates Vap for updates Nov 3, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 3, 2025
@chris-kaiser-7
Copy link
Author

@rikatz @robscott See anything else that needs fixing?

Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chris-kaiser-7!

@@ -0,0 +1,10611 @@
# Copyright 2025 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of including the entire release manifest from previous releases, let's just add some very lightweight manifests with a variety of annotations (different release channels, versions, etc).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1! Or pick some existing manifest from https://github.com/kubernetes-sigs/gateway-api/tree/main/config/crd and mutate it accordingly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call! I work on this.

Comment on lines -97 to -99
t.Run("should be able to set kubectl and kubeconfig and connect to the cluster", func(t *testing.T) {
kubectlLocation = testEnv.ControlPlane.KubectlPath
require.NotEmpty(t, kubectlLocation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for removing this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this logic in the parent test so that you could run targeted tests without issue. for example "make test.crds-validation GO_TEST_FLAGS="-run TestCRDValidation/safeupgrades_VAP_should_validate_correctly"". would not work as well as a few other tests because it depended on logic in this test.

(has(object.metadata.annotations) && object.metadata.annotations.exists(k, k == 'gateway.networking.k8s.io/bundle-version') &&
!matches(object.metadata.annotations['gateway.networking.k8s.io/bundle-version'], 'v1.[0-3].\\\\d+') &&
!matches(object.metadata.annotations['gateway.networking.k8s.io/bundle-version'], 'v0'))"
message: "Installing CRDs with version before v1.4.0 is prohibited by default. Uninstall ValidatingAdmissionPolicy gateway-api-safe-upgrades.gateway.networking.k8s.io to install older versions."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the goal here is to block the installation of older CRDs (avoid downgrade), right?

Can we add a note/comment that on Kubernetes 1.37 we should migrate this to something like https://kubernetes.io/docs/reference/using-api/cel/#kubernetes-semver-library instead?

This way, instead of having this bump as part of the release process, we can probably extract the version directly and check if it is older than the current existing.

Copy link
Author

@chris-kaiser-7 chris-kaiser-7 Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this is good. I didn't know this was in CEL for Kubernetes. I was just working off the base CEL documentation and that was kind of frustrating to say the least. I'll update it to this for 1.37. There is a lot of other good stuff in that doc too I didn't know about.

kind: ValidatingAdmissionPolicyBinding
metadata:
annotations:
gateway.networking.k8s.io/bundle-version: v1.4.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this will be released with main, should we make this v1.5.0?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that makes sense. I'll fix that.

@rikatz
Copy link
Member

rikatz commented Nov 4, 2025

overall lgtm, thanks.

I just want to be sure that:

  • We have a comment and an action item to use the semver library on vap once we can safely rely on it (eg.: Kubernetes 1.34 added it, once 1.37 is released we could rely on it as we would drop support for 1.33).
  • The CRD generation can be much much smaller as Rob pointed out. or even use the existing one, but do some "inplace replacement" just of the annotation (like some strings.Replace)

@chris-kaiser-7
Copy link
Author

overall lgtm, thanks.

I just want to be sure that:

  • We have a comment and an action item to use the semver library on vap once we can safely rely on it (eg.: Kubernetes 1.34 added it, once 1.37 is released we could rely on it as we would drop support for 1.33).
  • The CRD generation can be much much smaller as Rob pointed out. or even use the existing one, but do some "inplace replacement" just of the annotation (like some strings.Replace)

@rikatz @robscott
Thanks for the feedback. I was considering using logic like strings.Replace but I was a bit worried about the integrity of the test if it has logical dependencies like that but that might be a little to nit. Though if you're both ok with that I can definitely do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants