@@ -68,37 +68,42 @@ func (v *DynamoGraphDeploymentValidator) Validate() (admission.Warnings, error)
6868}
6969
7070// ValidateUpdate performs stateful validation comparing old and new DynamoGraphDeployment.
71+ // userInfo is used for identity-based validation (replica protection).
72+ // If userInfo is nil, replica changes for DGDSA-enabled services are rejected (fail closed).
7173// Returns warnings and error.
72- func (v * DynamoGraphDeploymentValidator ) ValidateUpdate (old * nvidiacomv1alpha1.DynamoGraphDeployment ) (admission.Warnings , error ) {
73- return v .ValidateUpdateWithUserInfo (old , nil )
74- }
74+ func (v * DynamoGraphDeploymentValidator ) ValidateUpdate (old * nvidiacomv1alpha1.DynamoGraphDeployment , userInfo * authenticationv1.UserInfo ) (admission.Warnings , error ) {
75+ var warnings admission.Warnings
7576
76- // ValidateUpdateWithUserInfo performs stateful validation with user identity checking.
77- // When userInfo is provided, it validates that only allowed controllers can modify
78- // replicas for services with scaling adapter enabled.
79- // Returns warnings and error.
80- func (v * DynamoGraphDeploymentValidator ) ValidateUpdateWithUserInfo (old * nvidiacomv1alpha1.DynamoGraphDeployment , userInfo * authenticationv1.UserInfo ) (admission.Warnings , error ) {
81- // Validate that BackendFramework is not changed (immutable)
82- if v .deployment .Spec .BackendFramework != old .Spec .BackendFramework {
83- warning := "Changing spec.backendFramework may cause unexpected behavior"
84- return admission.Warnings {warning }, fmt .Errorf ("spec.backendFramework is immutable and cannot be changed after creation" )
77+ // Validate immutable fields
78+ if err := v .validateImmutableFields (old , & warnings ); err != nil {
79+ return warnings , err
8580 }
8681
8782 // Validate replicas changes for services with scaling adapter enabled
88- if userInfo != nil {
89- if err := v .validateReplicasChanges (old , * userInfo ); err != nil {
90- return nil , err
91- }
83+ // Pass userInfo (may be nil - will fail closed for DGDSA-enabled services)
84+ if err := v .validateReplicasChanges (old , userInfo ); err != nil {
85+ return warnings , err
9286 }
9387
94- return nil , nil
88+ return warnings , nil
89+ }
90+
91+ // validateImmutableFields checks that immutable fields have not been changed.
92+ // Appends warnings to the provided slice.
93+ func (v * DynamoGraphDeploymentValidator ) validateImmutableFields (old * nvidiacomv1alpha1.DynamoGraphDeployment , warnings * admission.Warnings ) error {
94+ if v .deployment .Spec .BackendFramework != old .Spec .BackendFramework {
95+ * warnings = append (* warnings , "Changing spec.backendFramework may cause unexpected behavior" )
96+ return fmt .Errorf ("spec.backendFramework is immutable and cannot be changed after creation" )
97+ }
98+ return nil
9599}
96100
97101// validateReplicasChanges checks if replicas were changed for services with scaling adapter enabled.
98102// Only authorized service accounts (operator controller, planner) can modify these fields.
99- func (v * DynamoGraphDeploymentValidator ) validateReplicasChanges (old * nvidiacomv1alpha1.DynamoGraphDeployment , userInfo authenticationv1.UserInfo ) error {
103+ // If userInfo is nil, all replica changes for DGDSA-enabled services are rejected (fail closed).
104+ func (v * DynamoGraphDeploymentValidator ) validateReplicasChanges (old * nvidiacomv1alpha1.DynamoGraphDeployment , userInfo * authenticationv1.UserInfo ) error {
100105 // If the request comes from an authorized service account, allow the change
101- if internalwebhook .CanModifyDGDReplicas (userInfo ) {
106+ if userInfo != nil && internalwebhook .CanModifyDGDReplicas (* userInfo ) {
102107 return nil
103108 }
104109
0 commit comments