Commit graph

133 commits

Author SHA1 Message Date
Kubernetes Prow Robot
7b9694ee77
Merge pull request #139005 from yongruilin/dv-fg-scale-fix
Consolidate Scale declarative validation tests into test/declarative_validation/
2026-05-20 23:54:45 +05:30
Joe Betz
10685fb246
Migrate all storage tests to use request info 2026-05-19 16:37:03 -04:00
Yongrui Lin
9b2fb3f2d0 pkg/{apis,registry}: drop Scale tests superseded by new tree
The autoscaling validation test only ran cross-version DV without the
gate matrix. The replicationcontroller storage test toggled the
deprecated DeclarativeValidationTakeover gate and only covered RC.
Both are subsumed by test/declarative_validation/{autoscaling,apps}/scale/.
2026-05-13 20:35:04 +00:00
Yongrui Lin
c4ad092890 pkg/registry: route Scale subresource validation through ValidateScaleUpdate
Replace inline ValidateScale + dv.ValidateDeclaratively composition in
each ScaleREST.UpdatedObject with a call to ValidateScaleUpdate.
Replicationcontroller already invoked declarative validation inline;
deployment, replicaset, and statefulset now do so too, so HV/DV mismatch
metrics fire on apps /scale traffic in addition to RC.
2026-05-13 20:07:35 +00:00
Yongrui Lin
a791288d81 test/declarative_validation: migrate DV equivalence tests to new tree
Move the existing declarative_validation_test.go files out of
pkg/registry/ into a top-level tree at
test/declarative_validation/<group>/<kind>/. The new location pairs
each hand-written test with the per-Kind TestMain and version-init
files emitted by validation-gen, so the coverage gate runs alongside
the equivalence checks and apiVersions no longer needs to be
hand-maintained.
2026-05-09 19:11:01 +00:00
Patrick Ohly
163211ee45 apiserver: pass context with ReqInfo to AllowUnconditionalUpdate and AllowCreateOnUpdate
This enables implementing different behavior for AllowUnconditionalUpdate and
AllowCreateOnUpdate depending on the API version, which can be found in
ReqInfo.APIVersion. The specific need for this is to switch from
AllowUnconditionalUpdate=true (not recommended!) to false in v1 of
resource.k8s.io DeviceTaintRule.

This is done by adding the missing context parameter to the existing methods
instead of adding a new optional interface because a) the resulting
implementation is simpler and gets checked by the compiler and b) the Go API
guarantees of k8s.io/apiserver are more relaxed than in other modules because
it's less used downstream.

Example implementation:

    func (*deviceTaintRuleStrategy) AllowUnconditionalUpdate(ctx context.Context) bool {
           reqInfo, _ := request.RequestInfoFrom(ctx)
           if reqInfo != nil && reqInfo.APIVersion == "v1" {
                   // Should have done that already earlier. Better late than never...
                   return false
           }
           // Historic behavior for v1beta2 and older, cannot change that anymore.
           return true
    }
2026-05-05 12:48:19 +02:00
Joe Betz
a0095b5379
Migrate all strategies to DV 2026-04-24 12:01:39 -04: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
3b5298f0a4 Fix resource claim DV 2026-02-24 18:36:47 +00:00
Aaron Prindle
0cab277183 Graduate DeclarativeValidation feature gate to GA
This change graduates the 'DeclarativeValidation' feature gate to GA in v1.36.
The feature gate is now locked to 'true' by default.

Changes:
- Updated 'DeclarativeValidation' feature gate to GA in 'pkg/features/kube_features.go' and 'staging/src/k8s.io/apiserver/pkg/features/kube_features.go'.
- Updated feature gate documentation and versioned lists via 'hack/update-featuregates.sh'.
- Added feature gate emulation versioning to tests that explicitly disable 'DeclarativeValidation' to prevent panics now that the gate is locked to default.
2026-01-29 05:38:20 +00:00
Aaron Prindle
9d83f71cde fix validation_test.go to use path normalization 2025-10-16 17:40:19 +00:00
Kubernetes Prow Robot
db63a581ca
Merge pull request #134366 from tallclair/feature-gates-test
Set multiple feature gates simultaneously in test
2025-10-13 13:11:33 -07:00
Tim Allclair
4986abe0b8 Automated refactoring to use SetFeatureGatesDuringTest 2025-10-01 21:10:53 -07:00
Tim Hockin
229c6b13ca Validate ReplicationController.metadata.name
This relies on `+k8s:subfield` and validation cohorts.  The
`k8s:optional` ensures that we don't run the name validation if name is
empty, because core apimachinery will already flag it as Required().

This demonstrates some of the DV value - docs and clients are now (in
theory) able to see what RC's name format is.

Co-Authored-by: Yongrui Lin <yongrlin@outlook.com>
2025-10-01 19:45:37 +00:00
Tim Hockin
7b93851395 Fix ReplicationControl double validation 2025-10-01 18:37:13 +00:00
yongruilin
96349a4608 chore: Move declarative validation featuregates to staging apiserver 2025-09-26 22:30:16 +00:00
yongruilin
2d7dd9164f Refactor: Centralize declarative validation and migration logic
The boilerplate for running declarative validation was duplicated across multiple resource strategies. This included feature gate checks, metric identifier generation, error comparison, and conditional merging logic, which made the code verbose and difficult to maintain.

This commit introduces a new helper function, `rest.ValidateDeclarativelyWithMigrationChecks`, to encapsulate this common logic. All relevant strategies have been refactored to use this new function, resulting in cleaner and more concise code.
2025-09-26 17:22:46 +00:00
Lalit Chauhan
92dcd02459 Add helpers for declarative validation tests
Introduces new testing helpers to simplify testing of declarative validation rules. The new `VerifyValidationEquivalence` and `VerifyUpdateValidationEquivalence` functions reduce boilerplate by encapsulating the logic for:

- Toggling the `DeclarativeValidation` and `DeclarativeValidationTakeover` feature gates.
- Comparing the validation output from the imperative and declarative paths.

The declarative validation tests for CertificateSigningRequest and ReplicationController are updated to use these new, simpler helpers.
2025-09-16 16:57:21 +00:00
Lalit Chauhan
1a5e77135b Add fine grained metrics to narrow down DV mismatches and panics 2025-09-16 00:36:14 +00:00
Davanum Srinivas
ebc1ccc491
Bump k8s.io/kube-openapi to latest SHA (f3f2b991d03b)
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2025-07-14 07:24:48 -04:00
Joe Betz
7dc8660d03 Update testing to fully track subresources 2025-05-23 21:47:08 -04:00
Joe Betz
105391403f Enable scale subresource in generated validations 2025-05-23 21:47:08 -04:00
Joe Betz
a3eddf7d85 Add declarative validation testing for replicationcontroller/scale 2025-05-23 21:47:07 -04:00
Joe Betz
356f395f0d Enable declarative validation for replicationcontroller/scale 2025-05-23 21:47:07 -04:00
Joe Betz
48e1079cf0 Add subresource mapping support to ValidateDeclaratively and introduce configs
# Conflicts:
#	staging/src/k8s.io/apiserver/pkg/registry/rest/validate_test.go
2025-05-23 21:47:07 -04:00
Joe Betz
5a98d4dbb4 Limit declarative validation to spec until subresource support is added 2025-03-14 11:58:19 -04:00
Joe Betz
f7296b31f0 Add declarative test cases for RC.Spec.MinReadySeconds 2025-03-13 21:26:17 -04:00
Joe Betz
20b69a54bf Add declarative test cases for RC.Spec.Replicas 2025-03-13 21:24:50 -04:00
Tim Hockin
7315d0a687
Change internal-version RC.Spec.Replicas to a ptr
This is needed to make declaratve validation clean.  Past me thought
this was clever (pointer versioned, non-pointer internal) but it is just
confusing.
2025-03-13 08:47:19 -07:00
Joe Betz
b5bc283808 ReplicationController: Add declarative validation test suite
Introduce a test suite that ensures declarative test cases
are fully tested and that validation errors are compared
with handwritten validation to ensure consistency.

Co-authored-by: Tim Hockin <thockin@google.com>
Co-authored-by: Aaron Prindle <aprindle@google.com>
Co-authored-by: Yongrui Lin <yongrlin@google.com>
2025-03-12 19:53:44 -04:00
Joe Betz
5a5ed81e1f ReplicationController: Enable declarative validation
After declarative validation is enabled in the ReplicationController
strategy in this way, the generated declarative validation code
in pkg/apis/core/v1/zz.generated.validations.go will be run
when the strategy validates ReplicationController.

Co-authored-by: Tim Hockin <thockin@google.com>
Co-authored-by: Aaron Prindle <aprindle@google.com>
Co-authored-by: Yongrui Lin <yongrlin@google.com>
Co-authored-by: David Eads <deads@redhat.com>
2025-03-12 19:51:31 -04:00
Maciej Szulik
1fa995224a
Update scale sub-resource to return the same error everywhere
Signed-off-by: Maciej Szulik <soltysh@gmail.com>
2025-01-28 15:42:08 +01: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
Michael Fraenkel
cd949bafa4
use MakePodSpec consistently (#125805)
cleaning up some tests after MakePod/MakePodSpec were introduced
2024-06-30 10:28:36 -07:00
Michael Fraenkel
a7264f95ff
pod terminationGracePeriodSeconds is always valid (#124461)
* Pod terminationGracePeriodSeconds is always valid

Validation of a pod spec will always use the pod's
TerminationGracePeriodSeconds value.

A set of pod test-helpers have been created to help construct Pods.

* remove unused func

* reduction

* reduce 2

* simplify test

* report invalid grace period

* update SupplementalGroupPolicy tests
2024-06-29 18:09:29 -07:00
carlory
98353f1338 rc registry: add unit test for UpdateStatus 2024-04-16 14:57:01 +08:00
Michelle Au
c4aab1036f Add sig OWNERS to registry packages 2023-10-31 01:20:16 +00:00
Tim Hockin
29c0b73d64
Replace uses of diff.ObjectDiff with cmp.Diff
ObjectDiff is already a shim over cmp.Diff, so no actual output or
behavior changes
2023-04-12 08:46:12 -07:00
Antoine Pelisse
4f3859ce91 managedfields: Move most of fieldmanager package to managefields 2023-03-08 13:44:00 -08:00
Kubernetes Prow Robot
12c71fdf1c
Merge pull request #113542 from ardaguclu/fix-shortname-disperancy
Set singular names for core types to pass to discovery
2023-01-03 09:29:43 -08:00
Tim Hockin
e27cf75094
rc: API warn when name is not DNS label 2022-12-16 13:06:10 -08:00
Arda Güçlü
1abf94bec3 Remove GetSingularName for subresources 2022-11-18 12:21:19 +03:00
Arda Güçlü
672e0b1e01 Use correct singular name format for subresources 2022-11-18 12:21:19 +03:00
Arda Güçlü
578ddde80e Add singular name for the rest of types 2022-11-18 12:21:13 +03:00
Arda Güçlü
0990ba1cc9 Introduce singularNameProvider for core types
This introduces `singularNameProvider`. This provider will be used
by core types to have their singular names are defined in discovery
endpoint. Thanks to that, core resources singular name always have
higher precedence than CRDs shortcuts or singular names.
2022-11-18 12:21:07 +03:00
Wojciech Tyczyński
80060a502c Implement Destroy() method for all registries 2022-04-19 15:59:13 +02:00
Patrick Ohly
edffc700a4 enhance and fix log calls
Some of these changes are cosmetic (repeatedly calling klog.V instead of
reusing the result), others address real issues:

- Logging a message only above a certain verbosity threshold without
  recording that verbosity level (if klog.V().Enabled() { klog.Info... }):
  this matters when using a logging backend which records the verbosity
  level.

- Passing a format string with parameters to a logging function that
  doesn't do string formatting.

All of these locations where found by the enhanced logcheck tool from
https://github.com/kubernetes/klog/pull/297.

In some cases it reports false positives, but those can be suppressed with
source code comments.
2022-03-24 11:13:50 +01:00
Yuvaraj Kakaraparthi
801c39b478 kubectl: API changes to support --subresource in kubectl
Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
Co-authored-by: Nikhita Raghunath <nikitaraghunath@gmail.com>
Co-authored-by: Yuvaraj Kakaraparthi <kakaraparthy@vmware.com>
2022-03-23 11:19:58 +05:30
Jordan Liggitt
f669796dfd Send pod spec warnings when creating or changing workload objects 2021-05-18 10:42:36 -04:00
Jordan Liggitt
8c8a4cf3e4 Add WarningsOnCreate,WarningsOnUpdate 2021-05-18 10:42:36 -04:00