Skip to content

Commit

Permalink
fix(application): fix sync app from release bug (tkestack#1979)
Browse files Browse the repository at this point in the history
Co-authored-by: xdonggao <xdonggao@tencent.com>
  • Loading branch information
GaoXiaodong and xdonggao committed Sep 14, 2022
1 parent 0e6af17 commit 52c0acb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/application/controller/app/app_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,6 @@ func (c *Controller) syncAppFromRelease(ctx context.Context, cachedApp *cachedAp
metrics.GaugeApplicationSyncFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
return c.updateStatus(ctx, app, &app.Status, newStatus)
}
app.Spec.Chart.ChartVersion = rel.Chart.Metadata.Version
_, err = c.client.ApplicationV1().Apps(app.Namespace).Update(ctx, app, metav1.UpdateOptions{})
if err != nil {
return app, fmt.Errorf("update chart version failed %v", err)
}

newStatus.Phase = applicationv1.AppPhaseSucceeded
newStatus.Message = ""
Expand All @@ -419,6 +414,16 @@ func (c *Controller) syncAppFromRelease(ctx context.Context, cachedApp *cachedAp
newStatus.ObservedGeneration = app.Generation
// clean revision
newStatus.RollbackRevision = 0
if app.Status.Phase == applicationv1.AppPhaseRolledBack && app.Spec.Chart.ChartVersion != rel.Chart.Metadata.Version {
newObj := app.DeepCopy()
newObj.Spec.Chart.ChartVersion = rel.Chart.Metadata.Version
newObj.Status = *newStatus
_, err = c.client.ApplicationV1().Apps(app.Namespace).Update(ctx, newObj, metav1.UpdateOptions{})
if err != nil {
return app, fmt.Errorf("update chart version failed %v", err)
}
return app, err
}
return c.updateStatus(ctx, app, &app.Status, newStatus)
}

Expand Down

0 comments on commit 52c0acb

Please sign in to comment.