Skip to content

Commit e21fcad

Browse files
committed
chore: tests and cleaning up code
1 parent 115cef8 commit e21fcad

File tree

6 files changed

+985
-17
lines changed

6 files changed

+985
-17
lines changed

cmd/installer/cli/upgrade.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
1818
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1919
"github.com/replicatedhq/embedded-cluster/pkg-new/replicatedapi"
20+
"github.com/replicatedhq/embedded-cluster/pkg-new/validation"
2021
"github.com/replicatedhq/embedded-cluster/pkg/airgap"
2122
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
2223
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
@@ -25,7 +26,6 @@ import (
2526
"github.com/replicatedhq/embedded-cluster/pkg/release"
2627
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
2728
rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
28-
"github.com/replicatedhq/embedded-cluster/pkg/validation"
2929
"github.com/replicatedhq/embedded-cluster/pkg/versions"
3030
"github.com/replicatedhq/embedded-cluster/web"
3131
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
@@ -114,7 +114,7 @@ func UpgradeCmd(ctx context.Context, appSlug, appTitle string) *cobra.Command {
114114
if err := preRunUpgrade(ctx, flags, &upgradeConfig, existingRC, kcli, appSlug); err != nil {
115115
return err
116116
}
117-
if err := verifyAndPromptUpgrade(ctx, flags, upgradeConfig, prompts.New(), kcli, appSlug); err != nil {
117+
if err := verifyAndPromptUpgrade(ctx, flags, upgradeConfig, prompts.New(), kcli); err != nil {
118118
return err
119119
}
120120

@@ -352,7 +352,7 @@ func preRunUpgrade(ctx context.Context, flags UpgradeCmdFlags, upgradeConfig *up
352352
return nil
353353
}
354354

355-
func verifyAndPromptUpgrade(ctx context.Context, flags UpgradeCmdFlags, upgradeConfig upgradeConfig, prompt prompts.Prompt, kcli client.Client, appSlug string) error {
355+
func verifyAndPromptUpgrade(ctx context.Context, flags UpgradeCmdFlags, upgradeConfig upgradeConfig, prompt prompts.Prompt, kcli client.Client) error {
356356
isAirgap := flags.airgapBundle != ""
357357

358358
err := verifyChannelRelease("upgrade", isAirgap, flags.assumeYes)
@@ -367,9 +367,13 @@ func verifyAndPromptUpgrade(ctx context.Context, flags UpgradeCmdFlags, upgradeC
367367
}
368368
}
369369

370-
// Validate release deployability
371-
if err := validateReleaseDeployability(ctx, upgradeConfig, kcli, appSlug, isAirgap); err != nil {
372-
return fmt.Errorf("upgrade validation failed: %w", err)
370+
// Validate release upgradable
371+
if err := validateIsReleaseUpgradable(ctx, upgradeConfig, kcli, isAirgap); err != nil {
372+
if validation.IsValidationError(err) {
373+
// This is a validation error that prevents the upgrade from proceeding, expose the error directly
374+
return err
375+
}
376+
return fmt.Errorf("upgrade validation execution failed: %w", err)
373377
}
374378

375379
if !isAirgap {
@@ -561,8 +565,8 @@ func checkRequiresInfraUpgrade(ctx context.Context) (bool, error) {
561565
return !bytes.Equal(currentJSON, targetJSON), nil
562566
}
563567

564-
// validateReleaseDeployability validates that the target release can be safely deployed
565-
func validateReleaseDeployability(ctx context.Context, upgradeConfig upgradeConfig, kcli client.Client, appSlug string, isAirgap bool) error {
568+
// validateIsReleaseUpgradable validates that the target release can be safely deployed
569+
func validateIsReleaseUpgradable(ctx context.Context, upgradeConfig upgradeConfig, kcli client.Client, isAirgap bool) error {
566570
// Get current installation for version information
567571
currentInstallation, err := kubeutils.GetLatestInstallation(ctx, kcli)
568572
if err != nil {
@@ -609,7 +613,7 @@ func validateReleaseDeployability(ctx context.Context, upgradeConfig upgradeConf
609613
opts.TargetAppSequence = channelRelease.ChannelSequence
610614

611615
// For online upgrades, add the replicated API client and channel ID
612-
if !isAirgap && upgradeConfig.replicatedAPIClient != nil {
616+
if upgradeConfig.replicatedAPIClient != nil {
613617
opts.ReplicatedAPI = upgradeConfig.replicatedAPIClient
614618
opts.ChannelID = channelRelease.ChannelID
615619
}

0 commit comments

Comments
 (0)