Commit Graph

544 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
76f1684117 Rename ValidateNonSpecialIP to ValidateEndpointIP
There is not a single definition of "non-special IP" that makes sense
in all contexts. Rename ValidateNonSpecialIP to ValidateEndpointIP and
clarify that it shouldn't be used for other validations.

Also add a few more unit tests.
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
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
Natasha Sarkar
eab9197d1a Add observedGeneration and validation to pod status and conditions 2025-03-06 20:08:06 +00:00
Kubernetes Prow Robot
cd451c6a36 Merge pull request #130282 from natasha41575/podresizevalidation
Clean up preparation for pod subresource updates
2025-03-05 14:41:45 -08:00
Natasha Sarkar
f91105a77e fix prep and validation for pod subresource updates 2025-02-28 16:51:10 +00:00
Tim Hockin
c8111709e5 Add an error matcher, convert 2 tests
I fixed up the TestValidateEndpointsCreate path to show the matcher
instead of manual origin checking.

I picked TestValidateTopologySpreadConstraints because it was the last
failing test on my screen when I changed on of the commonly hard-coded
error strings. I fixed exactly those validation errors that were needed
to make this test pass.  Some of the Origin values can be debated.

The `field/testing.Matcher` interface allows tests to configure the
criteria by which they want to match expected and actual errors.  The
hope is that everyone will use Origin for Invalid errors.

There's some collateral impact for tests which use exact-comparisons and
don't expect origins.  These are all candidates for using the matcher.
2025-02-28 08:36:26 -08:00
Tim Hockin
6b7e38f018 Fix nits from PR 130355 2025-02-28 00:06:11 -08:00
Kubernetes Prow Robot
803e9d6495 Merge pull request #130355 from yongruilin/validation_origin
validation: Add Origin field to field.Error for more precise error tracking
2025-02-28 00:04:23 -08:00
yongruilin
c7cf852086 test: Add Origin field support to ReplicationController spec.Replicas validation test 2025-02-28 06:56:02 +00:00
yongruilin
07477c656e test: convert ValidateEndpointsCreate to use error Origin field in test
Update ValidateEndpointsCreate validation tests to use the new Origin field for more precise error comparisons. It leverage the Origin field instead of detailed error messages, improving test robustness and readability.

Co-authored-by: Tim Hockin <thockin@google.com>
2025-02-28 06:55:58 +00:00
Kubernetes Prow Robot
b14fad5adc Merge pull request #130181 from natasha41575/apiserver-generation
start setting pod metadata.generation
2025-02-24 10:48:29 -08:00
Natasha Sarkar
d02401dea9 start setting pod metadata.generation 2025-02-24 16:22:14 +00:00
Tim Allclair
e52274a9e2 Don't allow resize policy mutation 2025-02-14 13:15:13 -08:00
Tim Allclair
a1595d9dca Don't allow memory limit decrease unless resize policy is RestartContainer 2025-02-14 12:38:52 -08:00
vivzbansal
cfa0349159 Update validation code 2025-01-28 00:55:55 +00:00
vivzbansal
c31b1b3332 Resolved some review comments 2025-01-27 19:46:55 +00:00
vivzbansal
5889da1bbc Resolved latest review comments 2025-01-27 19:46:54 +00:00
vivzbansal
8fa8277908 Added some unit tests 2025-01-27 19:46:54 +00:00
vivzbansal
1cf4587277 Fix build error 2025-01-27 19:42:14 +00:00
vivzbansal
a0d3cb0a2c Added proper validation msg when non-sidecar containers are resized 2025-01-27 19:42:13 +00:00
vivzbansal
591b0f547a Fix issue of pod spec mismatch if there is any non-restarble init container present 2025-01-27 19:42:13 +00:00
vivzbansal
3885d2f8ab Added sidecar support in ValidatePodResize and dropNonResizeUpdates 2025-01-27 19:42:13 +00:00
vivzbansal
cdddaed841 Added sidecar support in and 2025-01-27 19:42:13 +00:00
vivzbansal
d1fac494f4 resolve merge conflicts 2025-01-27 19:42:13 +00:00
Davanum Srinivas
4e05bc20db Linter to ensure go-cmp/cmp is used ONLY in tests
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2025-01-24 20:49:14 -05:00
Kubernetes Prow Robot
7a504aa97b Merge pull request #129174 from RyanAoh/fix-115896
Remove the limitation on exposing port 10250 externally
2024-12-13 01:48:32 +01:00
Aohan Yang
e8087b3f6a Remove the limitation on exposing port 10250 externally 2024-12-12 19:45:19 +08:00
AxeZhan
ae11c7deb1 DisallowInvalidLabelValueInNodeSelector 2024-12-12 15:06:14 +08:00
AxeZhan
3075a9ae96 DRA API: validate node selector labels
Previously, ValidateNodeSelector did not check that labels are valid. Now it
does for resource.k8s.io, regardless whether an object already was created with
invalid labels in an earlier Kubernetes release. Theoretically this is a
breaking change and could cause problems during an upgrade, but that is highly
unlikely in practice.

In contrast to node affinity, DRA does not ignore parse errors
(= uses NewNodeSelector, not NewLazyErrorNodeSelector), so invalid labels would
have been found instead of being silently ignored.

Even if some object has invalid labels, this only affects an alpha -> beta
upgrade which isn't guaranteed to work seamlessly.
2024-11-22 09:10:02 +01:00
vivzbansal
95591abd02 Add AllowSidecarResizePolicy to relax resize policy validation check of sidecar containers 2024-11-12 05:08:51 +00:00
Kubernetes Prow Robot
2691a29eac Merge pull request #128683 from AnishShah/validation
[FG:InPlacePodVerticalScaling] Disallow removing requests & limits for Burstable pods.
2024-11-08 09:08:43 +00:00
Kubernetes Prow Robot
c25f5eefe4 Merge pull request #128407 from ndixita/pod-level-resources
[PodLevelResources] Pod Level Resources Feature Alpha
2024-11-08 07:10:50 +00:00
Anish Shah
7680f0f293 api: reject removing requsets & limits for Burstable pods. 2024-11-07 21:06:54 -08:00
ndixita
8a8dc27b4e Adding the logic to validate pod-level resources as following:
1. The effective container requests cannot be greater than pod-level requests
2. Inidividual container limits cannot be greater than pod-level limits
3. Only CPU & Memory are supported at pod-level
4. Inplace container resources updates are not supported if pod-level resources are set
Note: effective container requests cannot be greater than pod-level limits is supported by transitivity. Effective container requests <= pod-level requests && pod-level requests <= pod-level limits; Therefore effective container requests <= pod-level limits

Signed-off-by: ndixita <ndixita@google.com>
2024-11-08 03:00:54 +00:00
Kubernetes Prow Robot
46b3d9b320 Merge pull request #128186 from sreeram-venkitesh/117767-in-place-pod-vertical-scaling-version-skew
Updated version skew strategy for InPlacePodVerticalScaling
2024-11-08 02:21:14 +00:00
Kubernetes Prow Robot
9660e5c4cd Merge pull request #127360 from knight42/feat/split-stdout-stderr-server-side
API: add a new `Stream` field to `PodLogOptions`
2024-11-07 19:44:45 +00:00
Sreeram Venkitesh
8f1e69bbb0 Fix verify-gofmt.sh 2024-11-07 13:28:40 +05:30
Lan Liang
6e5a3cde50 Remove PodHostIPs feature gates.
Signed-off-by: Lan Liang <gcslyp@gmail.com>
2024-11-06 23:10:36 -08:00
Sreeram Venkitesh
385d2b198c Fixes from review, updated tests cases 2024-11-07 11:34:58 +05:30
Sreeram Venkitesh
7d1d7182f3 Update function name and remove feature gate check 2024-11-07 11:29:11 +05:30
Sreeram Venkitesh
4dae42a796 Updated version skew strategy for InPlacePodVerticalScaling 2024-11-07 11:29:07 +05:30
Anish Shah
207842d3e0 drop InPlacePodVerticalScaling support in windows 2024-11-06 12:57:55 -08:00
Kubernetes Prow Robot
96250d4411 Merge pull request #124918 from SergeyKanzhelev/commentIgnoringBadStatuses
added a comment that statuses lists are not being validated
2024-11-06 20:09:29 +00:00
Jian Zeng
b9228836e1 feat: update validation helpers
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
2024-11-06 21:27:12 +08:00
Kubernetes Prow Robot
648717cc74 Merge pull request #128266 from AnishShah/resize-subresource
[FG:InPlacePodVerticalScaling] Introduce  /resize subresource to request pod resource resizing
2024-11-06 06:59:29 +00:00
Kubernetes Prow Robot
a50b4e52a9 Merge pull request #128553 from thockin/master
Validation: merge TooLong and TooLongMaxLen
2024-11-06 04:19:43 +00:00
Anish Shah
332d794559 remove redundant validation check for pod resize 2024-11-06 01:33:15 +00:00