Skip to content

Commit

Permalink
[release-0.4] [CPS-7395]fix(update): post update release (#158)
Browse files Browse the repository at this point in the history
* fix(update): post update release

* chore: add fixme comment

Co-authored-by: Lisheng Zheng <[email protected]>
  • Loading branch information
caicloud-bot and Lisheng Zheng authored Jun 28, 2020
1 parent 67124bc commit f8949ab
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/release/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (rc *releaseContext) applyRelease(backend storage.ReleaseStorage, release *
release = release.DeepCopy()

var manifests []string
var postUpdate bool
if release.Spec.RollbackTo != nil {
glog.V(4).Infof("Rollback release %s/%s to %v", release.Namespace, release.Name, release.Spec.RollbackTo.Version)
// Rollback.
Expand Down Expand Up @@ -109,15 +110,10 @@ func (rc *releaseContext) applyRelease(backend storage.ReleaseStorage, release *

manifests = carrier.Resources()
release.Status.Manifest = render.MergeResources(manifests)

glog.V(4).Infof("Update manifest of release %s/%s for version %d", release.Namespace, release.Name, release.Status.Version)
_, err = backend.Update(release)
if err != nil {
glog.Errorf("Failed to update release %s/%s: %v", release.Namespace, release.Name, err)
return recordError(backend, err)
}

postUpdate = true
}
// FIXME: when the number of failure larger than 3 which set int function handler, the resource will apply failed and the
// resource can not be consistent with the Spec.Config
// Apply resources.
if err := rc.client.Apply(release.Namespace, manifests, kube.ApplyOptions{
OwnerReferences: referencesForRelease(release),
Expand All @@ -126,6 +122,18 @@ func (rc *releaseContext) applyRelease(backend storage.ReleaseStorage, release *
glog.Infof("Failed to apply resources for release %s/%s: %v", release.Namespace, release.Name, err)
return recordError(backend, err)
}

// Updates release after applying the manifests, otherwise the resource applied by manifests
// can not be consistent with the manifests when release updated successfully and apply failed.
if postUpdate {
glog.V(4).Infof("Update manifest of release %s/%s for version %d", release.Namespace, release.Name, release.Status.Version)
_, err := backend.Update(release)
if err != nil {
glog.Errorf("Failed to update release %s/%s: %v", release.Namespace, release.Name, err)
return recordError(backend, err)
}
}

_, err := backend.FlushConditions(storage.Condition(storage.ReleaseReasonAvailable, ""))
if err != nil {
return err
Expand Down

0 comments on commit f8949ab

Please sign in to comment.