Skip to content

Prepare types for CRD generation#11622

Closed
radixo wants to merge 4 commits into
projectcalico:masterfrom
radixo:fix-for-unpatched-controller-gen
Closed

Prepare types for CRD generation#11622
radixo wants to merge 4 commits into
projectcalico:masterfrom
radixo:fix-for-unpatched-controller-gen

Conversation

@radixo

@radixo radixo commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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=`^.*`

Copilot AI Jan 6, 2026

Copy link

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=`^.*`

Copilot AI Jan 6, 2026

Copy link

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=`^.*`

Copilot AI Jan 6, 2026

Copy link

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

hjiawei commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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?

@radixo radixo Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

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
@@ -429,6 +426,7 @@ spec:
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
Copy Markdown
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
Copy Markdown
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
@github-actions

github-actions Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 60 days with no activity.

@github-actions github-actions Bot added the stale Issues without recent activity label Mar 8, 2026
@danudey danudey modified the milestones: Calico v3.32.0, Calico v3.32.1 May 1, 2026
@github-actions github-actions Bot removed the stale Issues without recent activity label May 1, 2026
@radixo radixo added docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact and removed release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels May 1, 2026
@radixo radixo closed this May 1, 2026
@marvin-tigera marvin-tigera removed docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact labels May 1, 2026
@radixo

radixo commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Doing an alternative solution.

@radixo radixo deleted the fix-for-unpatched-controller-gen branch May 14, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants