Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Nov 20, 2024
1 parent 7bef478 commit d37d3ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion pkg/embeddedcluster/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
"github.com/replicatedhq/kots/pkg/logger"
)

// UpgradeStartedEvent is send back home when the upgrade starts.
Expand Down Expand Up @@ -46,14 +47,15 @@ func NotifyUpgradeStarted(ctx context.Context, baseURL string, ins, prev *embedd
}

// NotifyUpgradeFailed notifies the metrics server that an upgrade has failed.
func NotifyUpgradeFailed(ctx context.Context, baseURL string, ins, prev *embeddedclusterv1beta1.Installation) error {
func NotifyUpgradeFailed(ctx context.Context, baseURL string, ins, prev *embeddedclusterv1beta1.Installation, reason string) error {
if ins.Spec.AirGap {
return nil
}
return sendEvent(ctx, "UpgradeFailed", baseURL, UpgradeFailedEvent{
ClusterID: ins.Spec.ClusterID,
TargetVersion: ins.Spec.Config.Version,
InitialVersion: prev.Spec.Config.Version,
Reason: reason,
})
}

Expand All @@ -73,6 +75,8 @@ func NotifyUpgradeSucceeded(ctx context.Context, baseURL string, ins, prev *embe
func sendEvent(ctx context.Context, evname, baseURL string, ev interface{}) error {
url := fmt.Sprintf("%s/embedded_cluster_metrics/%s", baseURL, evname)

logger.Infof("Sending event %s to %s", evname, url)

body := map[string]interface{}{"event": ev}
buf := bytes.NewBuffer(nil)
if err := json.NewEncoder(buf).Encode(body); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,19 +1044,21 @@ func (o *Operator) waitForClusterUpgrade(appID string, appSlug string) error {
if err != nil {
return errors.Wrap(err, "failed to get kube client")
}
logger.Infof("waiting for cluster upgrade to finish")
logger.Infof("Waiting for cluster upgrade to finish")
for {
ins, err := embeddedcluster.GetCurrentInstallation(ctx, kbClient)
if err != nil {
return errors.Wrap(err, "failed to wait for embedded cluster installation")
}
if embeddedcluster.InstallationSucceeded(ctx, ins) {
logger.Infof("Cluster upgrade succeeded")
if err := o.notifyUpgradeSucceeded(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 {
logger.Errorf("Failed to notify upgrade failed: %v", err)
}
Expand Down Expand Up @@ -1115,7 +1117,7 @@ func (o *Operator) notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Cl
return errors.New("previous installation not found")
}

err = embeddedcluster.NotifyUpgradeFailed(ctx, license.Spec.Endpoint, ins, prev)
err = embeddedcluster.NotifyUpgradeFailed(ctx, license.Spec.Endpoint, ins, prev, ins.Status.Reason)
if err != nil {
return errors.Wrap(err, "failed to send event")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/upgradeservice/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func Deploy(opts DeployOptions) error {
go func() (finalError error) {
defer func() {
if finalError != nil {
if err := notifyUpgradeFailed(context.Background(), kbClient, opts); err != 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 {
Expand Down Expand Up @@ -184,7 +184,7 @@ func notifyUpgradeStarted(ctx context.Context, kbClient kbclient.Client, opts De
}

// notifyUpgradeFailed sends a metrics event to the api that the upgrade failed.
func notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Client, opts DeployOptions) error {
func notifyUpgradeFailed(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)
Expand All @@ -201,7 +201,7 @@ func notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Client, opts Dep
return errors.New("previous installation not found")
}

err = embeddedcluster.NotifyUpgradeFailed(ctx, opts.KotsKinds.License.Spec.Endpoint, ins, prev)
err = embeddedcluster.NotifyUpgradeFailed(ctx, opts.KotsKinds.License.Spec.Endpoint, ins, prev, reason)
if err != nil {
return errors.Wrap(err, "failed to send event")
}
Expand Down

0 comments on commit d37d3ed

Please sign in to comment.