Commit Graph

17 Commits

Author SHA1 Message Date
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
ba189de78f Slightly improve EndpointSlice address validation
Because it used both IsValidIPv4Address and ValidateEndpointIP,
EndpointSlice validation produced duplicate error messages when given
an invalid IP. Fix this by calling IsValidIP first, and only doing the
other checks if that one fails.

Also, since no one else was using the IsValidIPv4Address and
IsValidIPv6Address methods anyway, just inline them into the
EndpointSlice validation, so we don't have to worry about "should they
do legacy or strict validation" later.
2025-03-12 09:37:39 -04:00
Stephen Kitt
ff3e9ea79f pkg/api(s): drop pointer wrapper functions
The new k8s.io/utils/ptr package provides generic wrapper functions,
which can be used instead of type-specific pointer wrapper functions.
This replaces the latter with the former, and migrates other uses of
the deprecated pointer package to ptr in affacted files.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
2024-09-23 23:00:34 +02:00
TommyStarK
f166a52573 pkg/apis: Replace deprecated pointer function
Signed-off-by: TommyStarK <thomasmilox@gmail.com>
2023-01-05 11:48:05 +01:00
Rob Scott
764b501ac4 Updating EndpointSlice validation to match Endpoints validation 2021-04-13 15:26:19 -07:00
Rob Scott
11f0944dbc Adding Hints to EndpointSlice API 2021-03-08 15:37:34 -08:00
Swetha Repakula
a9891b4b9b Graduate EndpointSlice API to GA
* Removes discovery v1alpha1 API
  * Replaces per Endpoint Topology with a read only DeprecatedTopology
  in GA API
  * Adds per Endpoint Zone field in GA API
2021-03-05 12:02:41 -08:00
he.qingguo
fe499b5960 Fix typo of invalide in claims.go]
Signed-off-by: he.qingguo <he.qingguo@zte.com.cn>
2021-01-09 16:41:45 +08:00
Rob Scott
84e4b30a3e Updates related to PR feedback
- Remove feature gate consideration from EndpointSlice validation
- Deprecate topology field, note that it will be removed in future
release
- Update kube-proxy to check for NodeName if feature gate is enabled
- Add comments indicating the feature gates that can be used to enable
alpha API fields
- Add comments explaining use of deprecated address type in tests
2020-11-12 12:30:50 -08:00
Rob Scott
ff46573692 Cleaning up EndpointSlice update validation tests 2020-11-11 16:50:50 -08:00
Rob Scott
9613f79add Adding NodeName to EndpointSlice API, deprecation updates
In addition to adding NodeName, this notes that the topology field will
be deprecated soon. It also removes the IP address type that was
deprecated in Kubernetes 1.17 and intended to be removed in 1.20.
2020-11-11 16:50:23 -08:00
Rob Scott
0fa9981e01 Splitting IP address type into IPv4 and IPv6 for EndpointSlices 2019-11-12 09:03:53 -08:00
John Howard
d00794ca60 Add appProtocol to EndpointSlice.Port 2019-11-08 09:22:50 -08:00
Rob Scott
fe54e1f386 Fixing EndpointSlice port validation
This updates EndpointSlice port validation to mirror the validation
already in use for Service and Endpoint ports. This is required to
ensure all valid Service ports can be mapped directly to EndpointSlice
ports.
2019-10-30 12:32:23 -07:00
Rob Scott
d410bd28c3 Adding FQDN address type for EndpointSlice 2019-10-24 13:56:04 -07:00
Rob Scott
f80cee9280 Adding discovery/v1alpha1 API for EndpointSlices 2019-08-26 14:50:00 -07:00