Skip to content

Commit 898da98

Browse files
committed
Replace ratcheting section with stub
1 parent 999448d commit 898da98

File tree

1 file changed

+3
-14
lines changed
  • keps/sig-api-machinery/5073-declarative-validation-with-validation-gen

1 file changed

+3
-14
lines changed

keps/sig-api-machinery/5073-declarative-validation-with-validation-gen/README.md

+3-14
Original file line numberDiff line numberDiff line change
@@ -1014,21 +1014,10 @@ Subresources such as `pods/exec`, `pods/attach`, and `pods/portforward` do not r
10141014

10151015
### Ratcheting
10161016

1017-
As `validation-gen`‘s go validation code has old object access we can write any transition rule we want for validation ratcheting. `validation-gen` has access to the old and new state of obj for any field. This gives us a building block to make any flavor of ratcheting we would need in theory. We can think the basic form of ratcheting as - “allow old value to be written in updates even if now not valid as long as it doesn’t change -> easy to test”. If old = new -> short circuit validation (don’t care if it failed). If certain ratcheting needs syntactic sugar, we can add that as well based ont the current `validation-gen` design. An example of what ratcheting validation logic might look like for `validation-gen` is below:
1017+
TODO: Document and explain how:
10181018

1019-
```go
1020-
// Tightened validation (also known as ratcheting validation) would be supported by
1021-
// defining a new validation function. For example:
1022-
//
1023-
        func TightenedMaxLength(opCtx operation.Context, fldPath *field.Path, value, oldValue *string) field.ErrorList {
1024-
          if oldValue != nil && len(MaxLength(opCtx, fldPath, oldValue, nil)) > 0 {
1025-
            // old value is not valid, so this value skips the tightened validation
1026-
            return nil
1027-
          }
1028-
          return MaxLength(opCtx, fldPath, value, nil)
1029-
        }
1030-
1031-
```
1019+
- Add general purpose ratcheting to automatically skip validation of unchanged fields
1020+
- Catalog and handle complex cases where strict equality checks are not sufficient (lots of non-trivial cases exist today)
10321021

10331022
### Test Plan
10341023

0 commit comments

Comments
 (0)