Skip to content

Test chart upgrades - #103

Merged
scottrigby merged 8 commits into
helm:masterfrom
jlegrone:feature/upgrade-testing
Mar 18, 2019
Merged

scottrigby merged 8 commits into
helm:masterfrom
jlegrone:feature/upgrade-testing

Conversation

@jlegrone

@jlegrone jlegrone commented Feb 12, 2019 •

Copy link
Copy Markdown
Member

What this PR does / why we need it:
This PR enables testing in-place upgrades of charts that have non-breaking changes according to the semver spec.

The desired behavior of this PR and further discussion can be found here: #25 (comment)

Which issue this PR fixes

closes #25
closes #19
closes #99
closes #100

Special notes for your reviewer:

Some TODOs:

  • Handle uncommitted changes in git repositories
  • Handle not being in a git repository
  • Add a config flag to opt out of upgrade testing
  • Consider the need for more tests (PR Add Helm/Kubernetes integration tests #120)
  • Change the Git interface to a "SCM" interface to avoid further tight coupling with git? (out of scope for this PR)

Known caveats:

  1. Only works with git
  2. If a chart has direct dependencies outside of its parent directory, helm dependency build may fail or not produce the same result as the previous revision

Run integration tests with go test -cover -tags=integration ./... (see #120)

@jlegrone
jlegrone force-pushed the feature/upgrade-testing branch from c9273e7 to c0a0da5 Compare February 12, 2019 22:30
@helm-bot helm-bot added size/L and removed size/L labels Feb 12, 2019
@jlegrone
jlegrone force-pushed the feature/upgrade-testing branch from 64765e5 to 58a66b0 Compare February 13, 2019 21:04
@helm-bot helm-bot added size/L and removed size/L labels Feb 13, 2019
@jlegrone
jlegrone force-pushed the feature/upgrade-testing branch from aa60f0f to ca2cc9e Compare February 13, 2019 21:30
@helm-bot helm-bot added size/L and removed size/L labels Feb 13, 2019
@jlegrone
jlegrone force-pushed the feature/upgrade-testing branch from c5ae478 to 35c8aad Compare February 13, 2019 22:31
@helm-bot helm-bot added size/L and removed size/L labels Feb 13, 2019
@jlegrone
jlegrone force-pushed the feature/upgrade-testing branch from 35c8aad to 1781e91 Compare February 14, 2019 23:06
@helm-bot helm-bot added size/L and removed size/L labels Feb 14, 2019
@jlegrone jlegrone changed the title [WIP] Test chart upgrades Test chart upgrades Feb 14, 2019
@jlegrone

Copy link
Copy Markdown
Member Author

@unguiculus I'd appreciate a first pass when you have a chance!

@unguiculus

Copy link
Copy Markdown
Member

Thanks. Please give me some time to review and test this. From quickly skimming over it: Have you thought about installing the previous version from the repo instead of checking out the merge base? Doing so, you assume the merge base reflects the previous release. This doesn't necessarily have to be the case.

@jlegrone

Copy link
Copy Markdown
Member Author

I did consider pulling the previous published revision, but I think there are a couple problems with that:

  1. We don't necessarily know where the charts have been published -- I suppose we could handle this with a new configuration flag.
  2. Not all teams publish their charts to a registry. It is a common use case to version a chart alongside your application source code and run helm commands using the local chart path.

Comment thread pkg/chart/chart.go Resolved
@helm-bot helm-bot removed the size/L label Feb 17, 2019

@unguiculus unguiculus 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.

I did a quick review across the code.

I'm still testing and debugging and trying to understand and validate the changes. We will also need documentation for this so the user understands what the tool does.

We don't necessarily know where the charts have been published -- I suppose we could handle this with a new configuration flag.

You can configure repos with --chart-repos. You can probably just install the latest version from the repo. This should IMO be the default with an option to use merge base.

Comment thread kind-config.yaml Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread ct/cmd/install.go Outdated
flags.String("helm-extra-args", "", heredoc.Doc(`
Additional arguments for Helm. Must be passed as a single quoted string
(e.g. "--timeout 500 --tiller-namespace tiller"`))
flags.Bool("upgrade", true, heredoc.Doc(`

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.

The default should be false in order to not break the existing behavior.

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.

I'm good with this, though I hope we can flip this to true in a release or two. It would be nice for end users to get all the benefits of ct out of the box without having to figure out which additional flags they need to enable.

Comment thread pkg/chart/chart.go Outdated
// Reset charts directory to last commit
t.git.CheckoutDir(dir, "HEAD")
// Schedule cleanup of untracked temp directory
defer t.git.CleanDir(prevRevisionDir)

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.

defer should not be used inside a loop.

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.

To me the defer feels more maintainable since we schedule the cleanup action right after creating the temp directory, and we would need to do some additional bookkeeping for handling early returns otherwise.

Memory overhead here should be very low since we're only keeping track of the prevRevisionDir string, and disk usage scales linearly (if disk is a concern we'll need to do a little additional refactoring).

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.

If I understand this correctly, when using defer inside a loop we should wrap it in either an anonymous or a named function. See my note about previous version(s) above… this may cause the loop to pile up a lot more.

@jlegrone
jlegrone force-pushed the feature/upgrade-testing branch from 3c47da8 to 36e09ce Compare February 22, 2019 21:59
@jlegrone
jlegrone force-pushed the feature/upgrade-testing branch from 36e09ce to 821aea2 Compare February 22, 2019 22:04
@unguiculus

Copy link
Copy Markdown
Member

@jlegrone Please don't rebase and amend commits but add additional ones on top. This makes it easier to review and GitHub can show you the changes. We squash upon merge anyways.

@jlegrone

Copy link
Copy Markdown
Member Author

@unguiculus sure thing. For this PR I was thinking it would make sense not to squash since the integration test changes are so massive, but up to you.

I'm working on adding a bit more documentation to the install command now. Regarding this comment:

You can configure repos with --chart-repos. You can probably just install the latest version from the repo. This should IMO be the default with an option to use merge base.

This would work a lot of the time, but especially as we move to a more decentralized model it won't be unheard of to have multiple custom repositories, each with different versions of the same chart name. There has also not been a requirement to add custom repositories so far, unless you are pulling dependencies in from those repositories.

For example, I could be pulling in the bitnami charts repository to take advantage of their memcached chart, while using ct to test my own nginx chart. Because the bitnami repository also publishes an nginx chart, how does ct tell which remote repository is correct for the chart under test?

We can definitely handle this case, and I'm interested in your thoughts on implementation. I think it would be best done as a future enhancement since this feature will likely need to introduce some new configuration options.

Aside from the above, IMO testing against merge base makes sense as the default since

  1. it is in line with how we already validate version bumps in Chart.yaml
  2. it is lower barrier to entry (doesn't require a standalone repository for publishing)
  3. it is a reasonable default for teams that are practicing continuous delivery, and is the only option for teams running helm commands against a chart directory from version control

@unguiculus

Copy link
Copy Markdown
Member

Makes sense. I haven't thought this through yet. Let's stick with merge-base for now which, I agree, is a reasonable default.

Re. squashing: We don't necessarily have to squash everything. In this case, I'd suggest to make the history nice once we're ready to merge. Alternatively, you could factor out integration tests into a separate PR as you suggested earlier.

@jlegrone

jlegrone commented Feb 28, 2019 •

Copy link
Copy Markdown
Member Author

@unguiculus sounds good, I'll rework the commit log once you give an initial approval and we can just do a merge commit. I'll remove the [WIP] tag when commits are in order.

@unguiculus

Copy link
Copy Markdown
Member

I talked with @scottrigby about it the other day. We agreed that it would be best to split out the integration tests into a separate PR.

@jlegrone

jlegrone commented Mar 1, 2019

Copy link
Copy Markdown
Member Author

@unguiculus I've opened a separate PR as requested (#120). I'll keep that changeset rebased on top of this PR to verify that integration tests continue to pass.

@scottrigby scottrigby 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.

Nice work @jlegrone! Only concern I have is – for each non-breaking change – we should be testing upgrade from every previous non-MAJOR release, not only the most recent one. I mentioned that here #25 (comment) but I should have reviewed this PR earlier (hopefully should not be too big a refactor). It will take longer for charts with lots of MINOR/PATCH versions… but it's common for users to skip versions during upgrade, and a chart may upgrade fine from the previous version but not the one before it.

Comment thread Gopkg.lock Resolved
Comment thread ct/cmd/install.go Resolved
Comment thread pkg/chart/chart.go Outdated
// Reset charts directory to last commit
t.git.CheckoutDir(dir, "HEAD")
// Schedule cleanup of untracked temp directory
defer t.git.CleanDir(prevRevisionDir)

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.

If I understand this correctly, when using defer inside a loop we should wrap it in either an anonymous or a named function. See my note about previous version(s) above… this may cause the loop to pile up a lot more.

jlegrone added 2 commits March 4, 2019 13:29
Upgrade testing will be run if the --upgrade flag is set (default true)
and chart version increment does not indicate a breaking change
according to the SemVer 2.0 spec.

Any releases associated with previous chart versions which fail to roll
out or for which an initial `helm test` fails will be ignored.

Signed-off-by: Jacob LeGrone <[email protected]>
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/util/util.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
Comment thread pkg/chart/chart.go Resolved
unguiculus and others added 2 commits March 12, 2019 11:15
Co-Authored-By: jlegrone <[email protected]>
Signed-off-by: Jacob LeGrone <[email protected]>
@unguiculus

Copy link
Copy Markdown
Member

LGTM but @scottrigby should also approve.

@scottrigby scottrigby 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.

@jlegrone @unguiculus I buried my comment in a resolved thread #103 (comment) - this looks good to me 👍

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

Labels

Projects

None yet

4 participants