diff --git a/pkg/embeddedcluster/upgrade.go b/pkg/embeddedcluster/upgrade.go index 796ba22f56..2868d0cc33 100644 --- a/pkg/embeddedcluster/upgrade.go +++ b/pkg/embeddedcluster/upgrade.go @@ -76,13 +76,16 @@ func startClusterUpgrade( log.Printf("Starting cluster upgrade to version %s...", newcfg.Version) - // We cannot notify the upgrade started until the new install is created + // We cannot notify the upgrade started until the new install is available if err := NotifyUpgradeStarted(ctx, license.Spec.Endpoint, newInstall, current, versionLabel); err != nil { logger.Errorf("Failed to notify upgrade started: %v", err) } err = runClusterUpgrade(ctx, k8sClient, newInstall, registrySettings, license, versionLabel) if err != nil { + if err := NotifyUpgradeFailed(ctx, license.Spec.Endpoint, newInstall, current, err.Error()); err != nil { + logger.Errorf("Failed to notify upgrade failed: %v", err) + } return fmt.Errorf("run cluster upgrade: %w", err) } diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index e5def5d443..2e750b5ef8 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -1052,14 +1052,14 @@ func (o *Operator) waitForClusterUpgrade(appID string, appSlug string) error { } if embeddedcluster.InstallationSucceeded(ctx, ins) { logger.Infof("Cluster upgrade succeeded") - if err := o.notifyUpgradeSucceeded(ctx, kbClient, ins, appID); err != nil { + if err := o.notifyClusterUpgradeSucceeded(ctx, kbClient, ins, appID); err != nil { logger.Errorf("Failed to notify upgrade succeeded: %v", err) } return nil } if embeddedcluster.InstallationFailed(ctx, ins) { logger.Infof("Cluster upgrade failed") - if err := o.notifyUpgradeFailed(ctx, kbClient, ins, appID); err != nil { + if err := o.notifyClusterUpgradeFailed(ctx, kbClient, ins, appID); err != nil { logger.Errorf("Failed to notify upgrade failed: %v", err) } if err := upgradeservicetask.SetStatusUpgradeFailed(appSlug, ins.Status.Reason); err != nil { @@ -1074,8 +1074,8 @@ func (o *Operator) waitForClusterUpgrade(appID string, appSlug string) error { } } -// notifyUpgradeSucceeded sends a metrics event to the api that the upgrade succeeded. -func (o *Operator) notifyUpgradeSucceeded(ctx context.Context, kbClient kbclient.Client, ins *embeddedclusterv1beta1.Installation, appID string) error { +// notifyClusterUpgradeSucceeded sends a metrics event to the api that the upgrade succeeded. +func (o *Operator) notifyClusterUpgradeSucceeded(ctx context.Context, kbClient kbclient.Client, ins *embeddedclusterv1beta1.Installation, appID string) error { if ins.Spec.AirGap { return nil } @@ -1099,8 +1099,8 @@ func (o *Operator) notifyUpgradeSucceeded(ctx context.Context, kbClient kbclient return nil } -// notifyUpgradeFailed sends a metrics event to the api that the upgrade failed. -func (o *Operator) notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Client, ins *embeddedclusterv1beta1.Installation, appID string) error { +// notifyClusterUpgradeFailed sends a metrics event to the api that the upgrade failed. +func (o *Operator) notifyClusterUpgradeFailed(ctx context.Context, kbClient kbclient.Client, ins *embeddedclusterv1beta1.Installation, appID string) error { if ins.Spec.AirGap { return nil } diff --git a/pkg/upgradeservice/deploy/deploy.go b/pkg/upgradeservice/deploy/deploy.go index 3bd84c42d7..6ca7b3d7da 100644 --- a/pkg/upgradeservice/deploy/deploy.go +++ b/pkg/upgradeservice/deploy/deploy.go @@ -120,9 +120,6 @@ func Deploy(opts DeployOptions) error { go func() (finalError error) { defer func() { if finalError != nil { - if err := notifyUpgradeFailed(context.Background(), kbClient, opts, finalError.Error()); err != nil { - logger.Errorf("Failed to notify upgrade failed: %v", err) - } if err := task.SetStatusUpgradeFailed(opts.Params.AppSlug, finalError.Error()); err != nil { logger.Error(errors.Wrap(err, "failed to set task status to upgrade failed")) } @@ -145,6 +142,9 @@ func Deploy(opts DeployOptions) error { tgzArchiveKey: tgzArchiveKey, requiresClusterUpgrade: true, }); err != nil { + if err := notifyClusterUpgradeFailed(context.Background(), kbClient, opts, finalError.Error()); err != nil { + logger.Errorf("Failed to notify upgrade failed: %v", err) + } return errors.Wrap(err, "failed to create deployment") } @@ -154,8 +154,8 @@ func Deploy(opts DeployOptions) error { return nil } -// notifyUpgradeFailed sends a metrics event to the api that the upgrade failed. -func notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Client, opts DeployOptions, reason string) error { +// notifyClusterUpgradeFailed sends a metrics event to the api that the upgrade failed. +func notifyClusterUpgradeFailed(ctx context.Context, kbClient kbclient.Client, opts DeployOptions, reason string) error { ins, err := embeddedcluster.GetCurrentInstallation(ctx, kbClient) if err != nil { return fmt.Errorf("failed to get current installation: %w", err)