Skip to content

Commit

Permalink
Unable to update spec.version when Operand has been removed. Resolves #…
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson committed Jun 13, 2024
1 parent ce7957a commit 9cc5470
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions api/v1/infinispan_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1

import (
"context"
"errors"
"fmt"
"strconv"

Expand Down Expand Up @@ -185,26 +186,30 @@ func (i *Infinispan) ValidateUpdate(oldRuntimeObj runtime.Object) error {
if old.Spec.Version != "" {
// We know the versions must be valid as they have already been validated, so the error will always be nil
operand, _ := versionManager.WithRef(i.Spec.Version)
oldOperand, _ := versionManager.WithRef(old.Spec.Version)

if i.GracefulShutdownUpgrades() {
// Version downgrades are not supported with Graceful Shutdown
if operand.LT(oldOperand) {
detail := fmt.Sprintf("Version downgrading not supported. Existing='%s', Requested='%s'.", oldOperand.Ref(), operand.Ref())
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("version"), detail))
}
} else if operand.LT(oldOperand) {
if old.Status.HotRodRollingUpgradeStatus == nil {
detail := fmt.Sprintf("Version rollback only supported when a Hot Rolling Upgrade is in progress. Existing='%s', Requested='%s'.", oldOperand.Ref(), operand.Ref())
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("version"), detail))
} else {
// Only allow upgrades to be rolled back to the original source version
validRollbackOperand, _ := versionManager.WithRef(i.Status.HotRodRollingUpgradeStatus.SourceVersion)
if !validRollbackOperand.EQ(operand) {
detail := fmt.Sprintf("Hot Rod Rolling Upgrades can only be rolled back to the original source version. Existing='%s', Source='%s', Requested='%s'.",
oldOperand.Ref(), validRollbackOperand.Ref(), operand.Ref())
oldOperand, err := versionManager.WithRef(old.Spec.Version)

var unknown *version.UnknownError
// If the oldOperand has been removed, then no validation required as we must upgrade to a newer version
if !errors.As(err, &unknown) {
if i.GracefulShutdownUpgrades() {
// Version downgrades are not supported with Graceful Shutdown
if operand.LT(oldOperand) {
detail := fmt.Sprintf("Version downgrading not supported. Existing='%s', Requested='%s'.", oldOperand.Ref(), operand.Ref())
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("version"), detail))
}
} else if operand.LT(oldOperand) {
if old.Status.HotRodRollingUpgradeStatus == nil {
detail := fmt.Sprintf("Version rollback only supported when a Hot Rolling Upgrade is in progress. Existing='%s', Requested='%s'.", oldOperand.Ref(), operand.Ref())
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("version"), detail))
} else {
// Only allow upgrades to be rolled back to the original source version
validRollbackOperand, _ := versionManager.WithRef(i.Status.HotRodRollingUpgradeStatus.SourceVersion)
if !validRollbackOperand.EQ(operand) {
detail := fmt.Sprintf("Hot Rod Rolling Upgrades can only be rolled back to the original source version. Existing='%s', Source='%s', Requested='%s'.",
oldOperand.Ref(), validRollbackOperand.Ref(), operand.Ref())
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("version"), detail))
}
}
}
}
}
Expand Down

0 comments on commit 9cc5470

Please sign in to comment.