Skip to content

Commit

Permalink
Merge pull request #248 from abays/fix_8705
Browse files Browse the repository at this point in the history
[OSPRH-8705] Fix SwiftStorage replicas update nil pointer
  • Loading branch information
openshift-merge-bot[bot] authored Jul 17, 2024
2 parents d0117f2 + c2d9aac commit d6192b1
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions api/v1beta1/swift_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,22 @@ func (r *Swift) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *SwiftSpec) ValidateUpdate(old SwiftSpec, basePath *field.Path) field.ErrorList {
var allErrs field.ErrorList

if *r.SwiftStorage.Replicas < *old.SwiftStorage.Replicas {
zeroVal := int32(0)
oldReplicas := old.SwiftStorage.Replicas
newReplicas := r.SwiftStorage.Replicas

if oldReplicas == nil {
oldReplicas = &zeroVal
}

if newReplicas == nil {
newReplicas = &zeroVal
}

if *newReplicas < *oldReplicas {
allErrs = append(allErrs, field.Invalid(
basePath.Child("swiftStorage").Child("replicas"),
*r.SwiftStorage.Replicas,
*newReplicas,
"SwiftStorage does not support scale-in"))
}

Expand All @@ -202,10 +214,22 @@ func (r *SwiftSpec) ValidateUpdate(old SwiftSpec, basePath *field.Path) field.Er
func (r *SwiftSpecCore) ValidateUpdate(old SwiftSpecCore, basePath *field.Path) field.ErrorList {
var allErrs field.ErrorList

if *r.SwiftStorage.Replicas < *old.SwiftStorage.Replicas {
zeroVal := int32(0)
oldReplicas := old.SwiftStorage.Replicas
newReplicas := r.SwiftStorage.Replicas

if oldReplicas == nil {
oldReplicas = &zeroVal
}

if newReplicas == nil {
newReplicas = &zeroVal
}

if *newReplicas < *oldReplicas {
allErrs = append(allErrs, field.Invalid(
basePath.Child("swiftStorage").Child("replicas"),
*r.SwiftStorage.Replicas,
*newReplicas,
"SwiftStorage does not support scale-in"))
}

Expand Down

0 comments on commit d6192b1

Please sign in to comment.