Skip to content

Commit 70241e2

Browse files
committed
Tidied up redundant code.
Signed-off-by: Aryan <gorwadearyan@gmail.com>
1 parent 43df585 commit 70241e2

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

internal/webhook/apps/v1alpha1/nimcache_webhook.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ func (v *NIMCacheCustomValidator) ValidateCreate(_ context.Context, obj runtime.
8282
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type NIMCache.
8383
// Check immutable fields haven't changed, validate transitions between states, ensure updates don't break existing functionality.
8484
func (v *NIMCacheCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
85-
nimcache, ok := newObj.(*appsv1alpha1.NIMCache)
86-
if !ok {
87-
return nil, fmt.Errorf("expected a NIMCache object for the newObj but got %T", newObj)
88-
}
89-
nimcachelog.V(4).Info("Validation for NIMCache upon update", "name", nimcache.GetName())
90-
91-
fldPath := field.NewPath("nimcache").Child("spec")
92-
93-
// Begin by validating the new spec structurally.
94-
errList := validateNIMCacheSpec(&nimcache.Spec, fldPath)
95-
9685
oldNIMCache, ok := oldObj.(*appsv1alpha1.NIMCache)
9786
if !ok {
9887
return nil, fmt.Errorf("expected a NIMCache object for oldObj but got %T", oldObj)
@@ -101,6 +90,12 @@ func (v *NIMCacheCustomValidator) ValidateUpdate(_ context.Context, oldObj, newO
10190
if !ok {
10291
return nil, fmt.Errorf("expected a NIMCache object for newObj but got %T", newObj)
10392
}
93+
nimcachelog.V(4).Info("Validation for NIMCache upon update", "name", newNIMCache.GetName())
94+
95+
fldPath := field.NewPath("nimcache").Child("spec")
96+
97+
// Begin by validating the new spec structurally.
98+
errList := validateNIMCacheSpec(&newNIMCache.Spec, fldPath)
10499

105100
// Append immutability errors after structural checks.
106101
errList = append(errList, validateImmutableNIMCacheSpec(oldNIMCache, newNIMCache, field.NewPath("nimcache"))...)

internal/webhook/apps/v1alpha1/nimservice_webhook.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,6 @@ func (v *NIMServiceCustomValidator) ValidateCreate(_ context.Context, obj runtim
106106

107107
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type NIMService.
108108
func (v *NIMServiceCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
109-
nimservice, ok := newObj.(*appsv1alpha1.NIMService)
110-
if !ok {
111-
return nil, fmt.Errorf("expected a NIMService object for the newObj but got %T", newObj)
112-
}
113-
nimservicelog.V(4).Info("Validation for NIMService upon update", "name", nimservice.GetName())
114-
115-
fldPath := field.NewPath("nimservice").Child("spec")
116-
// Start with structural validation to ensure the updated object is well formed.
117-
errList := validateNIMServiceSpec(&nimservice.Spec, fldPath, v.k8sVersion)
118-
119-
// All fields of NIMService.Spec are mutable, except for:
120-
// - Spec.MultiNode
121-
// - If PVC has been created with PVC.Create = true, reject any updates to any fields of PVC object
122109
oldNIMService, ok := oldObj.(*appsv1alpha1.NIMService)
123110
if !ok {
124111
return nil, fmt.Errorf("expected a NIMService object for oldObj but got %T", oldObj)
@@ -127,7 +114,15 @@ func (v *NIMServiceCustomValidator) ValidateUpdate(_ context.Context, oldObj, ne
127114
if !ok {
128115
return nil, fmt.Errorf("expected a NIMService object for newObj but got %T", newObj)
129116
}
117+
nimservicelog.V(4).Info("Validation for NIMService upon update", "name", newNIMService.GetName())
118+
119+
fldPath := field.NewPath("nimservice").Child("spec")
120+
// Start with structural validation to ensure the updated object is well formed.
121+
errList := validateNIMServiceSpec(&newNIMService.Spec, fldPath, v.k8sVersion)
130122

123+
// All fields of NIMService.Spec are mutable, except for:
124+
// - Spec.MultiNode
125+
// - If PVC has been created with PVC.Create = true, reject any updates to any fields of PVC object
131126
errList = append(errList, validateMultiNodeImmutability(oldNIMService, newNIMService, field.NewPath("spec").Child("multiNode"))...)
132127
errList = append(errList, validatePVCImmutability(oldNIMService, newNIMService, field.NewPath("spec").Child("storage").Child("pvc"))...)
133128
errList = append(errList, validateDRAResourceImmutability(oldNIMService, newNIMService, field.NewPath("spec").Child("draResources"))...)

0 commit comments

Comments
 (0)