diff --git a/pkg/embeddedcluster/upgrade.go b/pkg/embeddedcluster/upgrade.go index 918f0b2372..dae1f3b163 100644 --- a/pkg/embeddedcluster/upgrade.go +++ b/pkg/embeddedcluster/upgrade.go @@ -22,6 +22,7 @@ import ( dockerregistrytypes "github.com/replicatedhq/kots/pkg/docker/registry/types" "github.com/replicatedhq/kots/pkg/imageutil" "github.com/replicatedhq/kots/pkg/k8sutil" + "github.com/replicatedhq/kots/pkg/logger" registrytypes "github.com/replicatedhq/kots/pkg/registry/types" "github.com/replicatedhq/kots/pkg/util" kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1" @@ -75,6 +76,11 @@ func startClusterUpgrade( log.Printf("Starting cluster upgrade to version %s...", newcfg.Version) + // We cannot notify the upgrade started until the new install is created + if err := NotifyUpgradeStarted(ctx, license.Spec.Endpoint, newInstall, current); err != nil { + logger.Errorf("Failed to notify upgrade started: %v", err) + } + err = runClusterUpgrade(ctx, k8sClient, newInstall, registrySettings, license, versionLabel) if err != nil { return fmt.Errorf("run cluster upgrade: %w", err) diff --git a/pkg/upgradeservice/deploy/deploy.go b/pkg/upgradeservice/deploy/deploy.go index 427b3adba6..3bd84c42d7 100644 --- a/pkg/upgradeservice/deploy/deploy.go +++ b/pkg/upgradeservice/deploy/deploy.go @@ -133,10 +133,6 @@ func Deploy(opts DeployOptions) error { defer close(finishedCh) tasks.StartTicker(task.GetID(opts.Params.AppSlug), finishedCh) - if err := notifyUpgradeStarted(context.Background(), kbClient, opts); err != nil { - logger.Errorf("Failed to notify upgrade started: %v", err) - } - if err := embeddedcluster.StartClusterUpgrade(context.Background(), opts.KotsKinds, opts.RegistrySettings); err != nil { return errors.Wrap(err, "failed to start cluster upgrade") } @@ -158,31 +154,6 @@ func Deploy(opts DeployOptions) error { return nil } -// notifyUpgradeStarted sends a metrics event to the api that the upgrade started. -func notifyUpgradeStarted(ctx context.Context, kbClient kbclient.Client, opts DeployOptions) error { - ins, err := embeddedcluster.GetCurrentInstallation(ctx, kbClient) - if err != nil { - return fmt.Errorf("failed to get current installation: %w", err) - } - - if ins.Spec.AirGap { - return nil - } - - prev, err := embeddedcluster.GetPreviousInstallation(ctx, kbClient) - if err != nil { - return errors.Wrap(err, "failed to get previous installation") - } else if prev == nil { - return errors.New("previous installation not found") - } - - err = embeddedcluster.NotifyUpgradeStarted(ctx, opts.KotsKinds.License.Spec.Endpoint, ins, prev) - if err != nil { - return errors.Wrap(err, "failed to send event") - } - 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 { ins, err := embeddedcluster.GetCurrentInstallation(ctx, kbClient)