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

bgpv1: Consolidate CRD API to follow K8s API Conventions #26040

Merged
merged 4 commits into from Jun 15, 2023

Conversation

rastislavs
Copy link
Contributor

@rastislavs rastislavs commented Jun 8, 2023

This PR aims to consolidate the BGP control plane k8s API to follow the K8s API Conventions.

Although it modifies some filed names, it does it only for fields that have been added recently (not yet released in any Cilium version) as part of:

Already released API fields are modified only in a backward compatible way (e.g. changed internal type to a pointer, but no type change in the generated CustomResourceDefinition). The only changes of already released API in the generated ciliumbgppeeringpolicies.yaml are:

  • exportPodCIDR: added default value (false, so not changing the default behaviour)
  • localASN + peerASN: added format annotation, but without the change of the underlying type

The changes are described in more detail in individual commits.

Although the diff looks pretty big, most of the changes are in the unit / component tests, where the API is actually used.

Fixes #25871

@rastislavs rastislavs added the wip label Jun 8, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Jun 8, 2023
@rastislavs rastislavs added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label Jun 8, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jun 8, 2023
@rastislavs
Copy link
Contributor Author

cc @danehans

pkg/bgpv1/agent/controller_test.go Outdated Show resolved Hide resolved
pkg/bgpv1/agent/controller.go Outdated Show resolved Hide resolved
pkg/bgpv1/agent/controller.go Outdated Show resolved Hide resolved
pkg/bgpv1/gobgp/server.go Outdated Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go Outdated Show resolved Hide resolved
pkg/bgpv1/manager/reconcile.go Outdated Show resolved Hide resolved
Copy link
Member

@YutaroHayakawa YutaroHayakawa left a comment

Choose a reason for hiding this comment

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

Thank you very much for woking on this! Now our API design looks very consistent. I left some nit picking comments.

pkg/bgpv1/agent/controller.go Outdated Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go Show resolved Hide resolved
pkg/bgpv1/manager/reconcile.go Outdated Show resolved Hide resolved
@rastislavs rastislavs force-pushed the bgp-api-refactor branch 2 times, most recently from 4a064eb to aa3458d Compare June 9, 2023 12:54
@rastislavs rastislavs force-pushed the bgp-api-refactor branch 2 times, most recently from e7faf37 to 3fa6902 Compare June 12, 2023 13:36
@rastislavs
Copy link
Contributor Author

Thanks for all the comments so far @YutaroHayakawa & @harsimran-pabla! As I addressed them, I squashed relevant commits and moved this PR out of draft - ready for the final review!

@rastislavs rastislavs marked this pull request as ready for review June 12, 2023 13:44
@rastislavs rastislavs requested review from a team as code owners June 12, 2023 13:44
@rastislavs rastislavs removed the wip label Jun 12, 2023
pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go Outdated Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go Outdated Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go Show resolved Hide resolved
pkg/bgpv1/agent/annotations.go Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go Outdated Show resolved Hide resolved
pkg/bgpv1/agent/controller_test.go Outdated Show resolved Hide resolved
pkg/bgpv1/gobgp/server.go Outdated Show resolved Hide resolved
pkg/bgpv1/manager/workdiff.go Show resolved Hide resolved
@rastislavs rastislavs force-pushed the bgp-api-refactor branch 2 times, most recently from 72f1cdd to bc81751 Compare June 13, 2023 09:11
@rastislavs
Copy link
Contributor Author

rastislavs commented Jun 14, 2023

/test

(rebased to fetch latest CI changes/fixes)

@YutaroHayakawa YutaroHayakawa added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 14, 2023
@YutaroHayakawa
Copy link
Member

API change is a bit of description changes. I think it's ready to merge.

@rastislavs rastislavs added the kind/cleanup This includes no functional changes. label Jun 14, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 14, 2023
@rastislavs rastislavs added kind/enhancement This would improve or streamline existing functionality. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. and removed kind/cleanup This includes no functional changes. labels Jun 14, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 14, 2023
@rastislavs rastislavs added ready-to-merge This PR has passed all tests and received consensus from code owners to merge. and removed ready-to-merge This PR has passed all tests and received consensus from code owners to merge. labels Jun 15, 2023
Modifies the type of recently added CRD fields of type
`meta/v1.Duration` to integer type and their name to follow
the K8s API Conventions rule:

"Duration fields must be represented as integer fields with
units being part of the field name (e.g. leaseDurationSeconds).
We don't use Duration in the API since that would require clients
to implement go-compatible parsing."

Also enables defaulting for these fields on apiserver by using
the kubebuilder:default tags (for static defaults).

This includes the KeepaliveTimeSeconds field, which was defaulted
at runtime to 1/3 of HoldTimeSeconds. As per K8s API Conventions,
static defaults are preferred. It also makes the value more
transparent to the user.

Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
This allows the default value to be versioned with the API.
It also provides consistency with the kubebuilder tags that
define the default values - both are kept in the same source file.

Also moves timers validation logic to API package to co-locate
the validation logic for API constraints that cannot be
expressed with kubebuilder markers with the API itself.

Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
Modifies the types of CRD fileds to follow  the K8s API
Conventions rules:
- "Use pointer types for all optional fields that do not have
built-in nil value"
- "Do not use unsigned integers, due to inconsistent support
across languages and libraries"
- "All public integer fields MUST use the Go (u)int32 or Go
 (u)int64 types, not (u)int"

Also changes the types of the existing ASN CRD fileds to int64
to satisfy the above rules.

Defaults ExportPodCIDR field of CiliumBGPVirtualRouter to false
explicitly for consistency with other optional fields.
As the default behavior remains the same, this is
a backward-compatible change.

Pointer types can be directly dereferenced in the reconcilers code.
To allow that we provide defaulting methods for our API types,
that can be used from the controllers / unit tests.

Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
Add unit tests to newly added SetDefaults() and Validate()
methods of the BGP CRD types. Do not perform detailed
defaulting / validation checks in unit tests of other packages,
to have that testing logic co-located within a single package.

Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
@rastislavs
Copy link
Contributor Author

/test

@rastislavs
Copy link
Contributor Author

API change is a bit of description changes. I think it's ready to merge.

Rebased due to a conflicting change in the main branch. All green after the rebase - marking as ready to merge again.

@rastislavs rastislavs added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 15, 2023
Copy link
Member

@aanm aanm left a comment

Choose a reason for hiding this comment

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

I did an overall review on the PR. It looks that pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go got a lot of modifications, did we consider on using v2alpha2 with a new CRD? If not, is there any upgrade path from users using v2alpha1 bgp?

@maintainer-s-little-helper maintainer-s-little-helper bot removed the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 15, 2023
@rastislavs
Copy link
Contributor Author

rastislavs commented Jun 15, 2023

@aanm

pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go got a lot of modifications, did we consider on using v2alpha2 with a new CRD? If not, is there any upgrade path from users using v2alpha1 bgp?

I believe this PR does not introduce any breaking change to the types that were already released in Cilium 1.13. Most of the changes in this PR are on the fields that were added as recent "to be released" features in the past weeks (listed in the PR description). There are only 3 backward compatible changes on the previously released CRD fields - copying from this PR's description:

Already released API fields are modified only in a backward compatible way (e.g. changed internal type to a pointer, but no type change in the generated CustomResourceDefinition). The changes of already released API in the generated ciliumbgppeeringpolicies.yaml are:

  • exportPodCIDR: added default value (false, so not changing the default behaviour)
  • localASN + peerASN: added format annotation, but without the change of the underlying type

EDIT: so there is no need for any upgrade path, this change is transparent for existing users.

Copy link
Member

@aanm aanm left a comment

Choose a reason for hiding this comment

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

Thanks for the clarification

@aanm aanm merged commit 97704da into cilium:main Jun 15, 2023
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bgp kind/enhancement This would improve or streamline existing functionality. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BGP CP: Move Default API Values to Type Definitions
6 participants