You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For new APIs, developers should use declarative validation for all validation rules that declarative validation supports.
651
-
See the [declarative validation tag catalog](https://kubernetes.io/docs/reference/using-api/declarative-validation/) for the list of supported validation rules.
652
-
This allows you to define validation rules directly on the API types using special Go comment tags.
650
+
For new APIs, developers should use declarative validation for all validation rules that declarative validation supports.
651
+
See the [declarative validation tag catalog](https://kubernetes.io/docs/reference/using-api/declarative-validation/) for the list of supported validation rules.
652
+
This allows you to define validation rules directly on the API types using special Go comment tags.
653
653
These validation rules are easier to write, review, and maintain as they live alongside the type and field definitions.
654
654
655
655
A new code generator, `validation-gen`, processes these tags to produce the validation logic automatically, reducing the need to write manual validation code in `validation.go`.
656
656
657
657
658
-
Setting up validation code generation involves the following steps.
658
+
Setting up validation code generation involves the following steps.
659
659
For APIs already using declarative validation, the first 2 plumbing steps can be skipped:
660
660
- Register the desired API group with validation-gen, similar to other code generators([Example PR doc.go change](https://github.com/kubernetes/kubernetes/pull/130724))
661
661
- Wire up the `strategy.go` for the desired API group to use declarative validation ([Example PR strategy.go change](https://github.com/kubernetes/kubernetes/pull/130724))
@@ -695,16 +695,16 @@ type ReplicationControllerSpec struct {
695
695
696
696
In this example, the `+k8s:optional` and `+k8s:minimum=0` tags specify that the `Replicas` and `MinReadySeconds` fields are optional and must have a value of at least 0 if present.
697
697
698
-
After adding these tags to your types, you will need to run the code generator to create or update the validation functions.
699
-
This is typically done by running `make update` or `hack/update-codegen.sh`.
700
-
To only run the declarative validation code generator, use `hack/update-codegen.sh validation`.
701
-
Running the validation-gen code generator will create a `zz_generated.validations.go` file for the declarative validations of the associated tagged API types and fields.
698
+
After adding these tags to your types, you will need to run the code generator to create or update the validation functions.
699
+
This is typically done by running `make update` or `hack/update-codegen.sh`.
700
+
To only run the declarative validation code generator, use `hack/update-codegen.sh validation`.
701
+
Running the validation-gen code generator will create a `zz_generated.validations.go` file for the declarative validations of the associated tagged API types and fields.
702
702
The generated validation methods in this file are then called via the modified `strategy.go` file in the above steps.
703
703
704
-
Testing the validation logic for the behaviour of a type is identical to the testing that would be done for hand-written validation code.
704
+
Testing the validation logic for the behaviour of a type is identical to the testing that would be done for hand-written validation code.
705
705
Users will need to write go unit tests similar to what is done for hand-written validation logic that verify specific cases are allowed, disallowed, etc and the validation behaviour is as expected.
706
706
707
-
While the goal is to express as much validation declaratively as possible, some complex or validation rules might still require manual implementation in `validation.go`.
707
+
While the goal is to express as much validation declaratively as possible, some complex or validation rules might still require manual implementation in `validation.go`.
708
708
709
709
## Edit version conversions
710
710
@@ -775,7 +775,7 @@ The generators that create go code have a `--go-header-file` flag
775
775
which should be a file that contains the header that should be
776
776
included. This header is the copyright that should be present at the
777
777
top of the generated file and should be checked with the
0 commit comments