mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-11-13 09:00:38 -05:00
cli: upgrade errors for microservice (#1259)
Handle invalid upgrade errors similarly as for images and k8s.
This commit is contained in:
parent
6b9065b444
commit
984f0589d2
6 changed files with 72 additions and 134 deletions
|
|
@ -37,23 +37,6 @@ import (
|
|||
// ErrInProgress signals that an upgrade is in progress inside the cluster.
|
||||
var ErrInProgress = errors.New("upgrade in progress")
|
||||
|
||||
// InvalidUpgradeError present an invalid upgrade. It wraps the source and destination version for improved debuggability.
|
||||
type InvalidUpgradeError struct {
|
||||
from string
|
||||
to string
|
||||
innerErr error
|
||||
}
|
||||
|
||||
// Unwrap returns the inner error, which is nil in this case.
|
||||
func (e *InvalidUpgradeError) Unwrap() error {
|
||||
return e.innerErr
|
||||
}
|
||||
|
||||
// Error returns the String representation of this error.
|
||||
func (e *InvalidUpgradeError) Error() string {
|
||||
return fmt.Sprintf("upgrading from %s to %s is not a valid upgrade: %s", e.from, e.to, e.innerErr)
|
||||
}
|
||||
|
||||
// Upgrader handles upgrading the cluster's components using the CLI.
|
||||
type Upgrader struct {
|
||||
stableInterface stableInterface
|
||||
|
|
@ -105,7 +88,7 @@ func (u *Upgrader) UpgradeImage(ctx context.Context, newImageReference, newImage
|
|||
currentImageVersion := nodeVersion.Spec.ImageVersion
|
||||
|
||||
if err := compatibility.IsValidUpgrade(currentImageVersion, newImageVersion); err != nil {
|
||||
return &InvalidUpgradeError{from: currentImageVersion, to: newImageVersion, innerErr: err}
|
||||
return err
|
||||
}
|
||||
|
||||
if imageUpgradeInProgress(nodeVersion) {
|
||||
|
|
@ -135,7 +118,7 @@ func (u *Upgrader) UpgradeK8s(ctx context.Context, newClusterVersion string, com
|
|||
}
|
||||
|
||||
if err := compatibility.IsValidUpgrade(nodeVersion.Spec.KubernetesClusterVersion, newClusterVersion); err != nil {
|
||||
return &InvalidUpgradeError{from: nodeVersion.Spec.KubernetesClusterVersion, to: newClusterVersion, innerErr: err}
|
||||
return err
|
||||
}
|
||||
|
||||
if k8sUpgradeInProgress(nodeVersion) {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
|
||||
"github.com/edgelesssys/constellation/v2/internal/compatibility"
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/edgelesssys/constellation/v2/internal/logger"
|
||||
"github.com/edgelesssys/constellation/v2/internal/versions/components"
|
||||
|
|
@ -48,7 +49,7 @@ func TestUpgradeK8s(t *testing.T) {
|
|||
newClusterVersion: "v1.2.3",
|
||||
wantErr: true,
|
||||
assertCorrectError: func(t *testing.T, err error) bool {
|
||||
target := &InvalidUpgradeError{}
|
||||
target := &compatibility.InvalidUpgradeError{}
|
||||
return assert.ErrorAs(t, err, &target)
|
||||
},
|
||||
},
|
||||
|
|
@ -57,7 +58,7 @@ func TestUpgradeK8s(t *testing.T) {
|
|||
newClusterVersion: "v1.2.2",
|
||||
wantErr: true,
|
||||
assertCorrectError: func(t *testing.T, err error) bool {
|
||||
target := &InvalidUpgradeError{}
|
||||
target := &compatibility.InvalidUpgradeError{}
|
||||
return assert.ErrorAs(t, err, &target)
|
||||
},
|
||||
},
|
||||
|
|
@ -156,7 +157,7 @@ func TestUpgradeImage(t *testing.T) {
|
|||
newImageVersion: "v1.2.2",
|
||||
wantErr: true,
|
||||
assertCorrectError: func(t *testing.T, err error) bool {
|
||||
target := &InvalidUpgradeError{}
|
||||
target := &compatibility.InvalidUpgradeError{}
|
||||
return assert.ErrorAs(t, err, &target)
|
||||
},
|
||||
},
|
||||
|
|
@ -165,7 +166,7 @@ func TestUpgradeImage(t *testing.T) {
|
|||
newImageVersion: "v1.2.1",
|
||||
wantErr: true,
|
||||
assertCorrectError: func(t *testing.T, err error) bool {
|
||||
target := &InvalidUpgradeError{}
|
||||
target := &compatibility.InvalidUpgradeError{}
|
||||
return assert.ErrorAs(t, err, &target)
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue