Skip to content

Commit 6fccab4

Browse files
committed
address feedback
1 parent d3d6f5a commit 6fccab4

File tree

1 file changed

+68
-0
lines changed
  • keps/sig-api-machinery/5073-declarative-validation-with-validation-gen

1 file changed

+68
-0
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
- [Common Patterns Reference Enabled By Existing + New Tags: Non-Lists/Maps](#common-patterns-reference-enabled-by-existing--new-tags-non-listsmaps)
9595
- [Common Patterns Reference Enabled By Existing + New Tags: Lists/Maps](#common-patterns-reference-enabled-by-existing--new-tags-listsmaps)
9696
- [Common Patterns Reference Enabled By Existing + New Tags: List Items](#common-patterns-reference-enabled-by-existing--new-tags-list-items)
97+
- [Immutability Patterns and Tags Demonstrated](#immutability-patterns-and-tags-demonstrated)
9798
- [Cross-Field Validation](#cross-field-validation)
9899
- [Handling Ratcheting In Cross-Field Validation Tags](#handling-ratcheting-in-cross-field-validation-tags)
99100
- [Referencing Fields in Validation-Gen For Cross-Field Validation Rules](#referencing-fields-in-validation-gen-for-cross-field-validation-rules)
@@ -1241,6 +1242,73 @@ csr.Conditions = [{Type: "InProgress", Status: "True"}]
12411242

12421243
² = Must remain at zero value (`+k8s:forbidden` validation logic)
12431244

1245+
##### Immutability Patterns and Tags Demonstrated
1246+
1247+
```go
1248+
type DeploymentSpec struct {
1249+
// Pattern: Required
1250+
// +k8s:required
1251+
// Operation:
1252+
Replicas *int32
1253+
1254+
// ✅ CREATE: replicas = 3
1255+
// ✅ UPDATE(modify): replicas = 5
1256+
// ❌ UPDATE(clear): replicas = nil
1257+
}
1258+
1259+
type PersistentVolumeStatus struct {
1260+
// Pattern: RequiredOnceSet (Optional, but cannot be cleared once set)
1261+
// +k8s:optional
1262+
// +k8s:update=NoClear
1263+
Phase *PersistentVolumePhase
1264+
1265+
// Operation:
1266+
// ✅ CREATE: phase = nil (volume created)
1267+
// ✅ UPDATE(set): phase = "Available" (set once)
1268+
// ✅ UPDATE(modify): phase = "Bound" (modify allowed)
1269+
// ❌ UPDATE(clear): phase = nil (cannot clear due to NoClear)
1270+
}
1271+
1272+
type PersistentVolumeClaimSpec struct {
1273+
// Pattern: Set Once (Optional, can be set at create or update, then immutable)
1274+
// +k8s:optional
1275+
// +k8s:update=NoModify
1276+
// +k8s:update=NoClear
1277+
VolumeName string
1278+
1279+
// Operation:
1280+
// ✅ CREATE: volumeName = ""
1281+
// ✅ UPDATE(set): volumeName = "pv-123" (set once by PV controller)
1282+
// ❌ UPDATE(modify): volumeName = "pv-456" (cannot change binding)
1283+
// ❌ UPDATE(clear): volumeName = "" (cannot unbind)
1284+
}
1285+
1286+
type PersistentVolumeSpec struct {
1287+
// Pattern: Required at creation, then immutable
1288+
// +k8s:required
1289+
// +k8s:immutable
1290+
Capacity ResourceList
1291+
1292+
// Operation:
1293+
// ✅ CREATE: capacity = {"storage": "10Gi"}
1294+
// ❌ UPDATE(modify): capacity = {"storage": "20Gi"}
1295+
}
1296+
1297+
type PodSpec struct {
1298+
// Pattern: Immutable (State decided at creation, cannot transition set/unset or modify)
1299+
// +k8s:optional
1300+
// +k8s:immutable // functionally equivalent to NoSet,NoModify,NoClear
1301+
HostNetwork bool
1302+
1303+
// Operation scenario 1:
1304+
// ✅ CREATE: hostNetwork = true
1305+
// ❌ UPDATE(modify): hostNetwork = false
1306+
// Operation scenario 2:
1307+
// ✅ CREATE: hostNetwork = false (or unset)
1308+
// ❌ UPDATE(set/modify): hostNetwork = true
1309+
}
1310+
```
1311+
12441312

12451313
### Cross-Field Validation
12461314

0 commit comments

Comments
 (0)