Skip to content

Commit

Permalink
Fix SwiftStorage replicas update nil pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
abays authored and openshift-cherrypick-robot committed Sep 13, 2024
1 parent 22ce49c commit 428e320
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 428e320

Please sign in to comment.