Skip to content

Commit 11c9872

Browse files
committed
make pni immutable
1 parent faa9c44 commit 11c9872

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

crd/multitenancy/api/v1alpha1/podnetworkinstance.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ import (
1717
// +kubebuilder:metadata:labels=managed=
1818
// +kubebuilder:metadata:labels=owner=
1919
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status`
20+
//
21+
// Enforce immutability of .spec once reconcile is complete (status becomes Ready).
22+
// Rule semantics:
23+
// - Allow CREATE.
24+
// - Do not allow UPDATE require self.spec == oldSelf.spec (no spec changes).
25+
//
26+
// This compiles to a CRD-level x-kubernetes-validations transition rule using oldSelf.
27+
// Requires Kubernetes versions that support CEL transition rules.
28+
// +kubebuilder:validation:XValidation:rule="self.spec == oldSelf.spec",message="Spec is immutable."
2029
type PodNetworkInstance struct {
2130
metav1.TypeMeta `json:",inline"`
2231
metav1.ObjectMeta `json:"metadata,omitempty"`

crd/multitenancy/manifests/multitenancy.acn.azure.com_podnetworkinstances.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ spec:
2626
name: v1alpha1
2727
schema:
2828
openAPIV3Schema:
29-
description: PodNetworkInstance is the Schema for the PodNetworkInstances
30-
API
29+
description: |-
30+
PodNetworkInstance is the Schema for the PodNetworkInstances API
31+
32+
Enforce immutability of .spec once reconcile is complete (status becomes Ready).
33+
Rule semantics:
34+
- Allow CREATE.
35+
- Do not allow UPDATE require self.spec == oldSelf.spec (no spec changes).
36+
37+
This compiles to a CRD-level x-kubernetes-validations transition rule using oldSelf.
38+
Requires Kubernetes versions that support CEL transition rules.
3139
properties:
3240
apiVersion:
3341
description: |-
@@ -109,6 +117,9 @@ spec:
109117
type: string
110118
type: object
111119
type: object
120+
x-kubernetes-validations:
121+
- message: Spec is immutable.
122+
rule: self.spec == oldSelf.spec
112123
served: true
113124
storage: true
114125
subresources:

0 commit comments

Comments
 (0)