Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump controller-runtime and k8s deps #6634

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tsaarni
Copy link
Member

@tsaarni tsaarni commented Aug 24, 2024

This pull request contains following changes:

Background:

sigs.k8s.io/controller-runtime v0.19.0 includes a breaking change that necessitates updating it alongside k8s.io/* v1.31.

sigs.k8s.io/controller-tools v0.16.x needs to be updated for k8s.io/* v1.31 compatibility, which also prompted the re-generation of CRDs.

@tsaarni tsaarni added the release-note/none-required Marks a PR as not requiring a release note. Should only be used for very small changes. label Aug 24, 2024
@tsaarni tsaarni requested a review from a team as a code owner August 24, 2024 05:48
@tsaarni tsaarni requested review from skriss and sunjayBhatia and removed request for a team August 24, 2024 05:48
@sunjayBhatia sunjayBhatia requested review from a team, rajatvig and davinci26 and removed request for a team August 24, 2024 05:49
Copy link

codecov bot commented Aug 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.01%. Comparing base (e5a25e2) to head (2c1946c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6634      +/-   ##
==========================================
- Coverage   81.76%   81.01%   -0.76%     
==========================================
  Files         133      133              
  Lines       15944    19996    +4052     
==========================================
+ Hits        13037    16200    +3163     
- Misses       2614     3503     +889     
  Partials      293      293              

see 127 files with indirect coverage changes

@tsaarni
Copy link
Member Author

tsaarni commented Aug 24, 2024

I believe the RBAC rules were changed by make generate because of deduplication done by controller-tools v0.16.0 kubernetes-sigs/controller-tools#937.

@tsaarni
Copy link
Member Author

tsaarni commented Aug 24, 2024

There is still an additional hurdle with the version bump. Following change in controller-tools v0.16.0

✨ add support for kubernetes +required annotations kubernetes-sigs/controller-tools#944

This change appropriately triggers the generation of new "required" entries in CRDs when +required is specified in the type definition.

In our API, we have a +required field in ExtensionServiceReference

// +required
// +kubebuilder:validation:MinLength=1
Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"`

ExtensionServiceReference is used in AuthorizationServer as an +optional field but it is embedded as a struct rather than a pointer

// +optional
ExtensionServiceRef ExtensionServiceReference `json:"extensionRef,omitempty"`

Now consider how AuthorizationServer is used in the Go code

Authorization: &contour_v1.AuthorizationServer{
AuthPolicy: &contour_v1.AuthorizationPolicy{
Disabled: true,
},
},

Even though the optional HTTPProxy.Spec.VirtualHost.Authorization.ExtensionServiceRef is never explicitly set, it gets included in the request since it's embedded in the AuthorizationServer struct. The omitempty tag does not prevent this since the field should have been a pointer for omitempty to work as intended. As a result, ExtensionServiceReference.Name is initialized with a nil value, and the newly introduced +required validation triggers, causing configuration to fail.

https://github.com/projectcontour/contour/actions/runs/10536218743/job/29196551673?pr=6634

  	Error:      	Received unexpected error:
  	            	HTTPProxy.projectcontour.io "external-auth" is invalid: [spec.virtualhost.authorization.extensionRef.name: Required value, <nil>: Invalid value: "null": some validation rules were not checked because the object was invalid; correct the existing errors to complete validation]
  	Test:       	HTTPProxy global external auth with namespace: httpproxy-global-ext-auth-non-tls-disabled with global external auth service global external auth can be disabled on a non TLS HTTPProxy

@tsaarni
Copy link
Member Author

tsaarni commented Aug 24, 2024

There are several other types that also use +required, but only ExtensionServiceReference.Name is causing the test suite to fail.

I believe backwards compatible fix would be to remove the +required from ExtensionServiceReference.Name. Although it seems illogical to reference to a non-existing resource, this approach shouldn't be any worse than previous state, since +required has never actually been enforced by the CRD.

Another option would be to change HTTPProxy.Spec.VirtualHost.Authorization.ExtensionServiceRef to a pointer, but that could potentially break external Go code relying on the API.

Any thoughts?

@sunjayBhatia
Copy link
Member

There are several other types that also use +required, but only ExtensionServiceReference.Name is causing the test suite to fail.

I believe backwards compatible fix would be to remove the +required from ExtensionServiceReference.Name. Although it seems illogical to reference to a non-existing resource, this approach shouldn't be any worse than previous state, since +required has never actually been enforced by the CRD.

Another option would be to change HTTPProxy.Spec.VirtualHost.Authorization.ExtensionServiceRef to a pointer, but that could potentially break external Go code relying on the API.

Any thoughts?

Looks like we missed out making the change to a pointer in #4994

Since it is a v1 type seems like we should go the conservative approach here and do the former

@tsaarni
Copy link
Member Author

tsaarni commented Sep 11, 2024

Since it is a v1 type seems like we should go the conservative approach here and do the former

I agree. I've removed the +required annotation from ExtensionServiceReference.Name so that it will be treated as optional again, like it was before controller-tools v0.16.0.

Starting with version v0.16.0 of controller-tool, the +required tag began being processed, leading to the inclusion of new "required" entries in CRDs.

The ExtensionServiceReference is used in the AuthorizationServer as an optional field, but it is embedded as a struct rather than a pointer.
This causes it to be included in requests even when not explicitly set.

This resulted in the following error:

HTTPProxy.projectcontour.io "external-auth" is invalid:
[spec.virtualhost.authorization.extensionRef.name: Required value, <nil>:
Invalid value: "null": some validation rules were not checked because the
object was invalid; correct the existing errors to complete validation]

Ideally, HTTPProxy.Spec.VirtualHost.Authorization.ExtensionServiceRef should have been a pointer to make it truly optional.
However, changing it to a pointer now would break backward compatibility.
An alternative solution is to make ExtensionServiceReference.Name optional, which should be acceptable since the +required tag was never enforced by the CRD in the first place.

Signed-off-by: Tero Saarni <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/none-required Marks a PR as not requiring a release note. Should only be used for very small changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants