Skip to content

Commit

Permalink
fix a bug in Tortoise validation webhook (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho authored Oct 4, 2023
1 parent 92523fd commit dbab1db
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions api/v1beta1/tortoise_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"context"
"errors"
"fmt"
"reflect"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -206,16 +207,21 @@ func (r *Tortoise) ValidateUpdate(old runtime.Object) (admission.Warnings, error
}
if r.Spec.TargetRefs.HorizontalPodAutoscalerName != nil {
if oldTortoise.Spec.TargetRefs.HorizontalPodAutoscalerName == nil || *oldTortoise.Spec.TargetRefs.HorizontalPodAutoscalerName != *r.Spec.TargetRefs.HorizontalPodAutoscalerName {
// removed or updated.
// newly specified or updated.
return nil, fmt.Errorf("%s: immutable field get changed", fieldPath.Child("targetRefs", "horizontalPodAutoscalerName"))
}
} else {
if oldTortoise.Spec.TargetRefs.HorizontalPodAutoscalerName != nil {
// newly specified.
// Old has HorizontalPodAutoscalerName, but the new one doesn't.
// removed.
return nil, fmt.Errorf("%s: immutable field get changed", fieldPath.Child("targetRefs", "horizontalPodAutoscalerName"))
}
}

if reflect.DeepEqual(oldTortoise.Spec.ResourcePolicy, r.Spec.ResourcePolicy) {
return nil, fmt.Errorf("%s: immutable field get changed", fieldPath.Child("resourcePolicy"))
}

return nil, nil
}

Expand Down

0 comments on commit dbab1db

Please sign in to comment.