Commit graph

231 commits

Author SHA1 Message Date
Lalit Chauhan
0c84f84ec8 Fix wrong marking of errors 2026-06-03 19:33:53 +00:00
Lalit Chauhan
89fb0b9b3e Generate validation code 2026-05-02 00:09:53 +00:00
Tim Hockin
6d20d043cc
Add whitespace in DV func calls 2026-04-28 12:29:16 -07:00
Tim Hockin
685199b229
Add whitespace in DV ratcheting 2026-04-28 12:08:35 -07:00
Tim Hockin
a557aa7e80
Add whitespace in DV func bodies 2026-04-28 09:19:24 -07:00
Tim Hockin
edf080f056
Add whitespace in DV func signatures 2026-04-28 09:12:24 -07:00
Tim Hockin
8950aac006
Add whitespace in DV register func 2026-04-28 09:12:19 -07:00
Weixie Cui
de652a3b00 networking: fix invalid value in NetworkPolicyPort endPort range error
When endPort is less than port, field.Invalid should report the endPort
value as the bad value, not port.Port.IntVal. This aligns with the
endPort field path and other endPort validations.
2026-03-22 21:08:15 +08:00
Your Name
701db6b6a6 validation-gen: Fix all stable api violations by prefixing +k8s:alpha(since:"1.36") and exclude output_tests from linting 2026-02-25 00:50:31 +00:00
Your Name
7d08854616 Fix lint errors 2026-02-25 00:06:19 +00:00
Abhishek Srivastava
ed083ab6b7 add declarative validation tests for ipaddress 2026-02-22 06:53:56 -08:00
Abhishek Srivastava
864c54f658 add validation fields and generated code for v1 and v1beta1 2026-02-18 21:41:09 -08:00
Kubernetes Prow Robot
f067ad1e8f
Merge pull request #135715 from darshansreenivas/dtumkur-pr-network-tag-cidr
networkpolicy: migrate ipBlock.cidr validation to DV
2026-02-16 07:01:58 +05:30
darshansreenivas
bc17031d19 network: migrate CIDR validation to DV
Co-authored-by: Abhishek Srivastava <abhishek@asrivas.me>
2026-02-15 16:00:41 -08:00
Heba Elayoty
36f5750042
Move path-segment validation to pkg content
This is where all the scrubbed validation helpers are going.

Note: This does NOT check for  or too-long inputs, and changing it now
would be a breaking change.

Co-authored-by: Tim Hockin <thockin@google.com>
Signed-off-by: Heba Elayoty <heelayot@microsoft.com>
2026-01-13 13:27:41 -08:00
Darshan Murthy
1c24a05ce1
wire network group for declarative validation and +k8s:required to IngressClassParametersReference.Name and IngressClassParametersReference.Kind (#134909) 2026-01-09 03:11:43 +05:30
Kubernetes Prow Robot
cc4bccf6a1
Merge pull request #134422 from jaehanbyun/ingressclass-default-marker
ingressclass: show (default) marker for default IngressClass
2025-12-17 16:26:11 -08:00
kita456
950dfd612b test: add test for Ingress Update 2025-11-26 00:31:55 +09:00
kita456
ac90e6a809 Fix: Check defaultBackend in allowRelaxedServiceNameValidation
The allowRelaxedServiceNameValidation() function currently only checks
service names in spec.rules, but it should also check the service name
in spec.defaultBackend.

When an Ingress has a defaultBackend with a service name that is valid
per RFC 1123 but invalid per RFC 1035 (e.g., starting with a digit like
"1-default-service"), the function incorrectly returns false. This
prevents users from updating such Ingresses even though they were
validly created in the past.

This commit adds validation for spec.defaultBackend.service.name to
maintain backward compatibility for existing Ingresses.
2025-11-24 21:23:41 +09:00
jaehanbyun
336ec22700 ingressclass: show (default) marker for default IngressClass
Signed-off-by: jaehanbyun <awbrg789@naver.com>
2025-10-26 20:53:56 +09:00
Adrian Moisey
0fa441f962
Promote KEP-5311 (Relaxed validation for Services names) to beta 2025-10-09 08:29:01 +02:00
Kubernetes Prow Robot
9fbd2dae14
Merge pull request #132339 from adrianmoisey/relaxed-validation-for-services-names
KEP-5311 Relaxed validation for Services names
2025-07-08 09:03:26 -07:00
PatrickLaabs
f966647b4d chore: depr. pointer pkg replacement for pkg/apis 2025-07-07 12:54:05 +02:00
Adrian Moisey
19e7e38af2
Add unit test for Ingress service ref relaxed validation
Test the behaviour of feature gate RelaxedServiceNameValidation.
2025-07-02 12:57:32 +02:00
Adrian Moisey
b430159c86
Allow Ingress service refs to be validated with apimachineryvalidation.NameIsDNSLabel
Only validate when feature gate RelaxedServiceNameValidation is enabled
or when the Ingess resource contains a service ref that already
validates with apimachineryvalidation.NameIsDNSLabel
2025-07-02 12:57:28 +02:00
xiaoweim
8632257c93 Cleanup: Remove redundant detail messages in field.Required 2025-06-26 21:24:43 +00:00
Kubernetes Prow Robot
354520cd9b
Merge pull request #131354 from tomoish/fix-netpol-podselector-doc
Fix: Clarify optional podSelector in NetworkPolicy docs and schema
2025-06-16 10:12:59 -07:00
tomoish
7a95f3e478 Fix NetworkPolicy podSelector comments
Clarify that podSelector is optional and defaults to an empty selector,
matching all pods.
Replace “ingress rules” with “rules” to reflect both directions.

Update podSelector descriptions in NetworkPolicy documentation for clarity
2025-06-16 00:11:48 +09:00
Antonio Ojea
15ab88f88b remove networking v1alpha1 and make update 2025-05-06 13:29:54 +00:00
jayson wang
49f765e2b3 Remove redundant Required validation for IngressRules 2025-05-02 20:56:29 +08:00
Antonio Ojea
0266d3bcb3 Allow single-to-dual-stack reconfiguration for ServiceCIDR
This change modifies the validation logic for ServiceCIDR updates
(`ValidateServiceCIDRUpdate`) to specifically permit upgrading a
single-stack ServiceCIDR (either IPv4 or IPv6) to a dual-stack
configuration.

This reconfiguration path is considered safe because it only involves adding
a new CIDR range without altering the existing primary CIDR. This
ensures that existing Service IP allocations are not disrupted.

Other modifications, such as:
- Downgrading from dual-stack to single-stack
- Reordering CIDRs in a dual-stack configuration
- Changing the primary CIDR during a single-to-dual-stack
  reconfiguration

remain disallowed by the validation. These operations carry a higher
risk of breaking existing Services or cluster networking
configurations. Preventing these updates automatically encourages
administrators to perform such changes manually after carefully
assessing the potential impact on their specific cluster environment.
The validation errors and controller logs provide guidance when such
disallowed changes are attempted.

Change-Id: I41dc09dfddb05f277925da2262f8114d6accbd1d
2025-04-14 17:05:44 +00:00
Dan Winship
ad22c0d495 Fix IP/CIDR validation to allow updates to existing invalid objects
Ignore pre-existing bad IP/CIDR values in:
  - pod.spec.podIP(s)
  - pod.spec.hostIP(s)
  - service.spec.externalIPs
  - service.spec.clusterIP(s)
  - service.spec.loadBalancerSourceRanges (and corresponding annotation)
  - service.status.loadBalancer.ingress[].ip
  - endpoints.subsets
  - endpointslice.endpoints
  - networkpolicy.spec.{ingress[].from[],egress[].to[]}.ipBlock
  - ingress.status.loadBalancer.ingress[].ip

In the Endpoints and EndpointSlice case, if *any* endpoint IP is
changed, then the entire object must be valid; invalid IPs are only
allowed to remain in place for updates that don't change any IPs.
(e.g., changing the labels or annotations).

In most of the other cases, when the invalid IP is part of an array,
it can be moved around within the array without triggering
revalidation.
2025-03-12 12:41:32 -04:00
Dan Winship
692785d25b Add legacy versions of IsValidIP/IsValidCIDR
Add validation.IsValidIPForLegacyField and
validation.IsValidCIDRForLegacyField, which validate "legacy" IP/CIDR
fields correctly. Use them for all such fields (indirectly, via a
wrapper in pkg/apis/core/validation that handles the
StrictIPCIDRValidation feature gate correctly).

Change IsValidIP and IsValidCIDR to require strict parsing and
canonical form, and update the IPAddr, ServiceCIDR, and
NetworkDeviceData validation to make use of them.
2025-03-12 09:58:04 -04:00
Dan Winship
f79bccf4d9 validation unit test cleanups
Fix some incorrect test case names.

Use t.Run() in a few more places (to facilitate using
SetFeatureGateDuringTest later).

Clarify TestPodIPsValidation/TestHostIPsValidation (and fix
weird indentation).
2025-03-12 09:37:39 -04:00
Kubernetes Prow Robot
3782b558a2
Merge pull request #128786 from danwinship/bad-ip-warnings
warn on bad IPs in objects
2025-03-11 00:11:47 -07:00
Tim Hockin
e54719bb66
Use randfill, do API renames 2025-03-08 15:18:00 -08:00
Dan Winship
5e067b6781 Minor IP/CIDR validation cleanups/fixups
Remove unnecessary duplicate checks for pod.spec.podIPs /
pod.spec.hostIPs / node.spec.podCIDRs. (A list that is known to
contain exactly 2 values, where one is IPv4 and the other is IPv6,
cannot possibly contain duplicates.)

Fix a bad CIDR in the NetworkPolicy validation tests.

Fix some comment typos.
2025-03-07 10:44:19 -05:00
Antonio Ojea
3606d52cd6 make update 2025-01-20 13:01:54 +00:00
Patrick Ohly
8a908e0c0b remove import doc comments
The "// import <path>" comment has been superseded by Go modules.
We don't have to remove them, but doing so has some advantages:

- They are used inconsistently, which is confusing.
- We can then also remove the (currently broken) hack/update-vanity-imports.sh.
- Last but not least, it would be a first step towards avoiding the k8s.io domain.

This commit was generated with
   sed -i -e 's;^package \(.*\) // import.*;package \1;' $(git grep -l '^package.*// import' | grep -v 'vendor/')

Everything was included, except for
   package labels // import k8s.io/kubernetes/pkg/util/labels
because that package is marked as "read-only".
2024-12-02 16:59:34 +01:00
Tim Hockin
c8eeb486f4
Call-site comments: the "" arg to TooLong is unused 2024-11-05 15:10:24 -08:00
Tim Hockin
8a7af90300
Clarify that value arg to field.TooLong is unused 2024-11-05 15:10:23 -08:00
Joe Betz
2595aa1309 generate 2024-09-03 14:26:26 -04:00
Antonio Ojea
bc8bce2ef9 make update 2024-06-30 09:48:46 +00:00
Dan Winship
7a56b6e3f7 Add validation.IsValidCIDR
Move apivalidation.ValidateCIDR to apimachinery, and rename it and
change its return value to match the other functions.

Also, add unit tests.

(Also, while updating NetworkPolicy validation for the API change, fix
a variable name that implied that IPBlock.Except[] is IP-valued rather
than CIDR-valued.)
2024-02-07 09:48:01 -05:00
Kubernetes Prow Robot
052bce26f4
Merge pull request #122931 from danwinship/ip-validation-cleanup
consistently use IsValidIP for IP validation
2024-02-06 15:58:15 -08:00
liyuerich
e490439262 drop deprecated pointer package
Signed-off-by: liyuerich <yue.li@daocloud.io>
2024-01-24 19:44:07 +08:00
Dan Winship
1d59d6b6c6 Use validation.IsValidIP in a few more places
Rather than using netutils.ParseIPSloppy directly.

Also fix the field paths in the errors for pod.spec.hostAliases to
include the array index.
2024-01-23 09:10:35 -05:00
Antonio Ojea
fee07ad608 make update with the new API with arrays 2023-10-31 21:05:58 +00:00
Antonio Ojea
c3d9b77d94 update ServiceCIDR API: replace IPv4,IPv6 fields by an array of strings
https: //docs.google.com/document/d/1-CKDPRHsG6XfnGs-Bb7ptWgDtTq9-hj8aJQpGz1CSh8/edit

Change-Id: If7134a5553b4ecc12b1d58ffc52ebb9f8594778a
2023-10-31 21:05:06 +00:00
Antonio Ojea
8182c4d9ec make update
Change-Id: I4007d4f6dda24b5c74f602d35191556f315de222
2023-10-31 21:05:05 +00:00