Skip to content

fix(tiller): upgrade last deployed release - #3097

Merged
adamreese merged 1 commit into
helm:masterfrom
adamreese:fix/2437-upgrade-release
Nov 7, 2017
Merged

adamreese merged 1 commit into
helm:masterfrom
adamreese:fix/2437-upgrade-release

Conversation

@adamreese

Copy link
Copy Markdown
Member

Fixes #2437

Two bugs were causing this behavior

  • Tiller was marking the previous release superseded when an upgrade
    failed.
  • Upgrade was diffing against failed releases

@adamreese adamreese added this to the 2.7.1 - Bugfix milestone Nov 3, 2017
@adamreese adamreese self-assigned this Nov 3, 2017
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 3, 2017
@bacongobbler

Copy link
Copy Markdown
Member

Do you think this might also fix #3068, #2341 and #2346 or are those separate issues?

@bacongobbler bacongobbler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A unit test would be great, but the code looks clear enough to me on its intent and we can write tests for it later.

// finds the non-deleted release with the given name
currentRelease, err := s.env.Releases.Last(req.Name)
// finds the deployed release with the given name
currentRelease, err := s.env.Releases.Deployed(req.Name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a unit test to cover this case if possible? :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to the existing tests captures this change. Let me know if you have a different strategy in mind.

@adamreese
adamreese force-pushed the fix/2437-upgrade-release branch from 7c73cb7 to 7d7e97b Compare November 3, 2017 21:55
Fixes helm#2437

Two bugs were causing this behavior

- Tiller was marking the previous release superseded when an upgrade
failed.
- Upgrade was diffing against failed releases
@adamreese
adamreese force-pushed the fix/2437-upgrade-release branch from 7d7e97b to 82ef751 Compare November 3, 2017 21:57
@bacongobbler

Copy link
Copy Markdown
Member

After a 🍐 session with Adam, it does look like this fixes all four issues. The only edge case this may introduce is when a user deploys a release that initially fails then tries to upgrade to fix it, but if a chart is in that state it should be removed and re-deployed.

This is a FANTASTIC change. Nice catch, @adamreese.

@bacongobbler

bacongobbler commented Nov 3, 2017 •

Copy link
Copy Markdown
Member

This also appears to fix #2832. The only other bug that this does not fix is #2941 but it's still yet to be determined how a release ledger can get into a state where there are two DEPLOYED releases.

A possible future fix for that would be to mark all previous deployed releases as SUPERCEDED. We did the same for Deis Workflow's release ledger IIRC and that seemed to be a good fix, if a bit hacky.

@SlickNik SlickNik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from me. As Matt said, a unit test would be nice to have. Good catch, and thanks for the fix, Adam! 👍

@bacongobbler

Copy link
Copy Markdown
Member

@adamreese merge when you feel like it

@kiich

kiich commented Nov 7, 2017

Copy link
Copy Markdown
Contributor

Can't wait to try this fix - nice one guys!

@blakebarnett

Copy link
Copy Markdown

Thanks for this fix! Now if we can just get 3-way merge for current, new, and actual resources all our helm woes will be gone.

@bacongobbler

Copy link
Copy Markdown
Member

@blakebarnett awesome to hear. Is that an open ticket somewhere or would you mind re-opening a new ticket to track that? I recall that being in a comment but I don't think we have a ticket yet. :)

@blakebarnett

Copy link
Copy Markdown

Yeah, that's actually what the original problem was in #2346 I believe, as mentioned here: #2341 (comment)

So I guess 2 separate issues, yeah, I'll make a new one.

@blakebarnett

Copy link
Copy Markdown

ref: #3118

if err := s.ReleaseModule.Update(originalRelease, updatedRelease, req, s.env); err != nil {
msg := fmt.Sprintf("Upgrade %q failed: %s", updatedRelease.Name, err)
s.Log("warning: %s", msg)
originalRelease.Info.Status.Code = release.Status_SUPERSEDED

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the old release still be superceeded?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the release failed and was never deployed, the previous release is still deployed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right; this is the error handling case. This change is correct then.

// finds the non-deleted release with the given name
currentRelease, err := s.env.Releases.Last(req.Name)
// finds the deployed release with the given name
currentRelease, err := s.env.Releases.Deployed(req.Name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no "deployed" last release (ie: failed) then won't this prevent the code below from running? It seems the error handling should check for some "doesn't exist error" and if it doesn't exist, it should skip the reuseValues block, but otherwise continue.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking up what is live in the cluster to perform a diff of what needs to be installed/deleted/modified. The code below is to calculate the incremented release number

@redbaron

Copy link
Copy Markdown
Contributor

Using release as a reference point for diffing is to coarse and there still failure scenarios even after this fix. Tracking success state of each individual resource is the only option I see to solve it properly. Moving reference point, but leaving it on release level is not enough.

Here is a failure scenario for new behavior. For resources A and B applied in the same order:

Re;ease  number: resources in chart -> release status by helm [resources in cluster]
1: B0 -> success [B0]
2. A0, B1(error) -> failure [A0,B0]
3. A0, B2(fix for the error) -> failure due to "Can't create A, already exist" [A0, B0]
4. B2 -> success  [A0, B2]

At the end we have "lost" resource A0 in the cluster. which user have no way of knowing about except they go and check everything manually, despite total success reported by Helm.

@evescorp

Copy link
Copy Markdown

Hi! From now on we can't re-deploy successfully a release that previously had failed because it will fail again with the error "UPGRADE FAILED: "app" has no deployed releases". It seems that the only solution is to delete the release and relaunch it again. However, the problem in this case is: by deleting the release, the current running pods will disappear until relaunch the new one. Then, we will have an outage of the service.
Provided that one of the advantages of the Kubernetes platform is the performing of rolling updates in order to prevent an outage of the service, I think there should be another method (more automatic and clean) that performs this task when we attempt to upgrade a previously failed release.
It seems that the unique solution so far is to launch another release with different name and change external references to that new release and then delete the original failed release. Apart from the "painful" of this solution, it's not too consistent, considering that we will lose the history of the original release.
What do you think?

@chancez

chancez commented Nov 28, 2017

Copy link
Copy Markdown

I agree with @redbaron, comparing to previous releases for diffing seems wrong; helm should just use the built in k8s functionality to patch and if nothing actually changes than it will effectively be a no-op. Helm shouldn't decide when to apply a diff; it should always submit to the API IMO. It would prevent this class of bugs entirely.

@bacongobbler

Copy link
Copy Markdown
Member

Let's file an issue to track that proposal for Helm 3.

@stealthybox

stealthybox commented Jan 25, 2018 •

Copy link
Copy Markdown
Contributor

@bacongobbler I'm testing through our pipeline and running into the issue where you can't upgrade a release that initially fails.
As you can imagine with a PR, this happens pretty often.

This feels like a regression in behavior.
If anything, it's at least a major change that deserves a detailed release note.

I would be in favor of a patch for constructive behavior in this case.

@redbaron

Copy link
Copy Markdown
Contributor

This introduces major regression in usability, where failed releases are rolled back by CI by deploying previous known good version and NOT using helm rollback command. Previously it worked fine, now with reference point moved to last succesfull release all CI jobs report instant success and no real rollback happening in the cluster, because diff'ing to latest good release produces zero patch.

This was last straw which caused be to strip off last uses of helm and replace with ksonnet.io generated resources combined with kubectl apply --prune.

@kiich

kiich commented Jan 25, 2018

Copy link
Copy Markdown
Contributor

interesting @redbaron - how are you now handling rollbacks of your deploys?

@stealthybox

stealthybox commented Jan 25, 2018 •

Copy link
Copy Markdown
Contributor

If anybody needs to downgrade helm, here's a quick way to install v2.7.0

( this change made it into both the 2.8.0 release and the patch release for 2.7.1 )

Downgrade local client: (Helm install script)

curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash /dev/stdin --version v2.7.0

Downgrade local client: (Mac using brew)

brew uninstall --force kubernetes-helm  &&  brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/808c2bb9f51ddd2fe310852a6089a877d380b2a3/Formula/kubernetes-helm.rb

Downgrade tiller (helm server):

helm init --upgrade  # using the 2.7 client will downgrade

helm version
Client: &version.Version{SemVer:"v2.7.0", GitCommit:"08c1144f5eb3e3b636d9775617287cc26e53dba4", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.7.0", GitCommit:"08c1144f5eb3e3b636d9775617287cc26e53dba4", GitTreeState:"clean"}

@chancez

chancez commented Jan 25, 2018

Copy link
Copy Markdown

@kiich I think most people just rollforward. If something fails, instead of a rollback, you can instead run another upgrade with the values from before, if using git, this is just a a git revert/git checkout, and re-running helm upgrade. This is why this behavior is such a huge regression, I honestly doubt many people use rollbacks, but instead just rollforward with old values.

@bacongobbler

Copy link
Copy Markdown
Member

@stealthybox thank you for the feedback. I noted that we could fix that up in another comment in a different thread by saying "if no deploys have been successful, assume a vanilla install". I'm concerned around the edge cases around that scenario such as the case where users have been always deploying failed releases, but I think that it's a good suggestion point. That might handle most of the cases being brought up here.

What do you think about that idea?

@stealthybox

stealthybox commented Jan 26, 2018 •

Copy link
Copy Markdown
Contributor

@bacongobbler yep -- I believe that change would satisfy a lot of the need for the idempotent install/upgrade.

I can see what you mean about how things might be weird in the case where a user is using the side-effects of failed deployments.

Our CI pipeline reports failure to the user, but it intentionally does not clean up results so that the potentially broken environment can be studied.

@mumoshu

mumoshu commented Aug 30, 2018

Copy link
Copy Markdown
Contributor

@redbaron So, to bring back your (and my) use-case, perhaps we need to script an automated rollback immediately after an install/upgrade failure, like what @whereisaaron suggested in an another issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.