Skip to content

Replace forked net parsers with regexp hacks#330

Closed
danwinship wants to merge 1 commit intokubernetes:masterfrom
danwinship:sporkednet
Closed

Replace forked net parsers with regexp hacks#330
danwinship wants to merge 1 commit intokubernetes:masterfrom
danwinship:sporkednet

Conversation

@danwinship
Copy link
Contributor

Proof-of-concept, since I keep mentioning we could do this if we wanted. I'm not sure we do want to, but...

Note that we only use the regexps if the initial attempt at parsing fails, so we only take the regexp hit on invalid or legacy inputs.

/kind cleanup
/cc @aojea @thockin

@k8s-ci-robot k8s-ci-robot requested review from aojea and thockin August 20, 2025 23:58
@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 20, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danwinship

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

The pull request process is described here

Details 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 20, 2025
@danwinship
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 20, 2025
"regexp"
)

var matchZeros = regexp.MustCompile(`(^|:)0*(0|[1-9][0-9]*)\.0*(0|[1-9][0-9]*)\.0*(0|[1-9][0-9]*)\.0*(0|[1-9][0-9]*)((/)0*(0|[1-9][0-9]*))?$`)
Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of being able to not just tolerate an IP using old style parsing, but actually transform it into the acceptable version, so that we could conceivably scrub existing data and stop accepting leading 0s via the API at some point in the future.

as nits, if we were going to do this for real, I'd want to split the IP and CIDR cases so we match exactly what we intend to for each scenario, and probably try to factor out the matcher for the leading-zero number to make the overall structure easier to see:

var (
  num = `0*(0|[1-9][0-9]*)`
  dot = `\.`
  
  leadingZeroIP = regexp.MustCompile(`(^|:)` + num + dot + num + dot + num + dot + num + `$`)
  leadingZeroIPReplace = `$1$2.$3.$4.$5`

  leadingZeroCIDR = regexp.MustCompile(`(^|:)` + num + dot + num + dot + num + dot + num + `/` + num + `$`)
  leadingZeroCIDRReplace = `$1$2.$3.$4.$5/$6`
)

I'd also consider whether we wanted to use these cleaners externally to detect a field was relying on this (so we could warn) or to do the transform (so we could normalize or clean up existing or incoming data)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to detect a field was relying on this (so we could warn)

KEP-4858 already took care of all of this (for non-CRD types). kubernetes/kubernetes#122550 split IP/CIDR validation into IsValid{IP,CIDR} for new fields vs IsValid{IP,CIDR}ForLegacyField, for older fields, and kubernetes/kubernetes#128786 added warnings when you're using a value with 0s in a legacy field.

As for transform/clean-up, that's been an ongoing discussion, most recently in #328 (comment) (which is the proximate cause of me filing this PR).

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 2, 2025
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 2, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 31, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 30, 2026
@danwinship
Copy link
Contributor Author

/close

I did this because I thought Antonio wanted to get rid of the forked parsers, but he says he'd rather have those than regexp hacks.

@k8s-ci-robot
Copy link
Contributor

@danwinship: Closed this PR.

Details

In response to this:

/close

I did this because I thought Antonio wanted to get rid of the forked parsers, but he says he'd rather have those than regexp hacks.

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.

@aojea
Copy link
Member

aojea commented Feb 2, 2026

mandatory xkcd XD

image

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants