Skip to content

Conversation

@radixo
Copy link
Contributor

@radixo radixo commented Jan 6, 2026

Description

It will be built a new calico/go-build image with a controller-gen without patches for numorstring types, those changes prepares calico repository to be built with this changes.

Related issues/PRs

Todos

  • Tests
  • Documentation
  • Release note

Release Note

Prepare types for CRD generation

Reminder for the reviewer

Make sure that this PR has the correct labels and milestone set.

Every PR needs one docs-* label.

  • docs-pr-required: This change requires a change to the documentation that has not been completed yet.
  • docs-completed: This change has all necessary documentation completed.
  • docs-not-required: This change has no user-facing impact and requires no docs.

Every PR needs one release-note-* label.

  • release-note-required: This PR has user-facing changes. Most PRs should have this label.
  • release-note-not-required: This PR has no user-facing changes.

Other optional labels:

  • cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.
  • needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.

Copilot AI review requested due to automatic review settings January 6, 2026 01:12
@radixo radixo requested a review from a team as a code owner January 6, 2026 01:12
@marvin-tigera marvin-tigera added this to the Calico v3.32.0 milestone Jan 6, 2026
@marvin-tigera marvin-tigera added release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels Jan 6, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prepares Calico's custom types for CRD generation with a new version of controller-gen that doesn't have patches for numorstring types. The changes add kubebuilder validation markers to numorstring types and update the CRD generation paths to be more specific.

Key Changes:

  • Added kubebuilder validation markers (Type=integer, XIntOrString, Pattern) to Uint8OrString, Protocol, and Port types to enable proper CRD schema generation
  • Updated Makefile CRD generation paths from ./lib/apis/... to ./lib/apis/crd.projectcalico.org/... to limit scope

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
libcalico-go/Makefile Narrowed CRD generation paths to specifically target crd.projectcalico.org APIs
api/pkg/lib/numorstring/uint8orstring.go Added kubebuilder validation markers for CRD schema generation
api/pkg/lib/numorstring/protocol.go Added kubebuilder validation markers for CRD schema generation
api/pkg/lib/numorstring/port.go Added kubebuilder validation markers for CRD schema generation

Comment on lines +27 to +29
// +kubebuilder:validation:Type=integer
// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern=`^.*`
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The kubebuilder markers seem contradictory. Type=integer suggests only integer values are valid, but Pattern=^.*$ allows any string. Additionally, XIntOrString is typically used for Kubernetes IntOrString types. Please clarify the intended validation behavior and ensure the markers accurately reflect whether this type accepts integers only, strings only, or both.

Suggested change
// +kubebuilder:validation:Type=integer
// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern=`^.*`
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:XIntOrString

Copilot uses AI. Check for mistakes.

// +kubebuilder:validation:Type=integer
// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern=`^.*`
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The same marker inconsistency exists here as in Uint8OrString. The combination of Type=integer with Pattern=^.*$ (which matches any string) creates ambiguous validation semantics. Verify these markers correctly represent the type's dual integer/string nature.

Suggested change
// +kubebuilder:validation:Pattern=`^.*`
// +kubebuilder:validation:Pattern=`^(UDP|TCP|ICMP|ICMPv6|SCTP|UDPLite|[0-9]+)$`

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +34
// +kubebuilder:validation:Type=integer
// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern=`^.*`
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The kubebuilder markers appear inconsistent. Type=integer conflicts with Pattern=^.*$ which accepts any string. For a Port type that can represent port ranges or named ports, clarify whether these markers should validate the struct fields (MinPort, MaxPort, PortName) or if different markers are needed.

Suggested change
// +kubebuilder:validation:Type=integer
// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern=`^.*`

Copilot uses AI. Check for mistakes.
@hjiawei hjiawei self-assigned this Jan 6, 2026
@hjiawei
Copy link
Contributor

hjiawei commented Jan 6, 2026

Related toolchain changes in projectcalico/toolchain#754.

@hjiawei hjiawei marked this pull request as draft January 6, 2026 18:25
// PortName to "".
// - For a single port, set MinPort = MaxPort and PortName = "".
//
// +kubebuilder:validation:Type=integer
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change force the type to be an integer only?

Copy link
Contributor Author

@radixo radixo Jan 6, 2026

Choose a reason for hiding this comment

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

No, just set type to Integer, and the XIntOrString relax it to accept string as well. I'm using the same for DSCP

Comment on lines 421 to 429
anyOf:
- type: integer
- type: string
description: |-
BPFPSNATPorts sets the range from which we randomly pick a port if there is a source port
collision. This should be within the ephemeral range as defined by RFC 6056 (1024–65535) and
preferably outside the ephemeral ranges used by common operating systems. Linux uses
32768–60999, while others mostly use the IANA defined range 49152–65535. It is not necessarily
a problem if this range overlaps with the operating systems. Both ends of the range are
inclusive. [Default: 20000:29999]
pattern: ^.*
type: integer
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these breaking changes @radixo ? Same question for other places.

"ParsedDefaultJSON": "0",
"ParsedType": "numorstring.Port",
"YAMLType": "integer or string",
"YAMLType": "integer",
Copy link
Contributor

Choose a reason for hiding this comment

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

The felix doc for YAMLType is affected by the +kubebuilder:validation:Type=integer marker.

@hjiawei hjiawei force-pushed the fix-for-unpatched-controller-gen branch from df2093b to 4efbb3d Compare January 6, 2026 19:55
radixo and others added 3 commits January 6, 2026 14:32
This update builds a new calico/go-build container image that includes
the controller-gen tool and removes patches for numorstring types. The
changes prepare the Calico repository for the updated toolchain.
@hjiawei hjiawei force-pushed the fix-for-unpatched-controller-gen branch from 4efbb3d to 8c47499 Compare January 6, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-pr-required Change is not yet documented release-note-required Change has user-facing impact (no matter how small)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants