Skip to content

Commit

Permalink
Merge pull request #269 from openshift-cherrypick-robot/cherry-pick-2…
Browse files Browse the repository at this point in the history
…48-to-18.0.0-proposed

[18.0.0-proposed] [OSPRH-8705] Fix SwiftStorage replicas update nil pointer
  • Loading branch information
openshift-merge-bot[bot] authored Sep 13, 2024
2 parents 22ce49c + 428e320 commit d6d328d
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 d6d328d

Please sign in to comment.