Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow defining a custom dir for each Helm Chart #706

Merged
merged 5 commits into from
Jun 1, 2022

Conversation

julienduchesne
Copy link
Member

This allows a chartfile to contain multiple versions of the same chart.

Example:

directory: charts
repositories:
- name: flagger
  url: https://flagger.app
requires:
- chart: flagger/flagger
  directory: flagger-1.16.1
  version: 1.16.1
- chart: flagger/flagger
  directory: flagger-1.21.0
  version: 1.21.0
version: 1

This allows a chartfile to contain multiple versions of the same chart.

Example:

```yaml
directory: charts
repositories:
- name: flagger
  url: https://flagger.app
requires:
- chart: flagger/flagger
  directory: flagger-1.16.1
  version: 1.16.1
- chart: flagger/flagger
  directory: flagger-1.21.0
  version: 1.21.0
version: 1
```
@julienduchesne julienduchesne requested review from Duologic, sh0rez and a team May 31, 2022 11:17
@@ -40,18 +26,33 @@ func TestAddRepos(t *testing.T) {
}

func TestAdd(t *testing.T) {
c, err := InitChartfile(filepath.Join(t.TempDir(), Filename))
tempDir := t.TempDir()
Copy link
Member Author

Choose a reason for hiding this comment

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

The tests now depend on actual helm pulling the prometheus chart. Since the helm pull behavior is a bit unusual, I believe that a full test is better than mocking the Helm process

@julienduchesne julienduchesne force-pushed the julienduchesne/helm-dir branch 4 times, most recently from 0a2a1f6 to ba8b817 Compare May 31, 2022 11:34
@julienduchesne julienduchesne removed request for a team, Duologic and sh0rez May 31, 2022 11:34
@julienduchesne julienduchesne marked this pull request as draft May 31, 2022 11:34
@julienduchesne julienduchesne force-pushed the julienduchesne/helm-dir branch 2 times, most recently from 4ae3fe5 to 6351ce4 Compare May 31, 2022 11:36
@julienduchesne julienduchesne marked this pull request as ready for review May 31, 2022 11:38
@julienduchesne julienduchesne requested review from sh0rez, a team and Duologic May 31, 2022 11:38
@julienduchesne julienduchesne changed the title Allow defining a custom dir for Helm Charts Allow defining a custom dir for each Helm Chart May 31, 2022
Copy link
Contributor

@jvrplmlmn jvrplmlmn left a comment

Choose a reason for hiding this comment

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

Just a quick first round, will circle back later.

pkg/helm/helm.go Outdated Show resolved Hide resolved
Comment on lines +82 to +83
// It is not possible to tell `helm pull` to extract to a specific directory
// so we extract to a temp dir and then move the files to the destination
Copy link
Contributor

Choose a reason for hiding this comment

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

This is my complete ignorance in regards with Helm, but would --untardir help for this purpose?

Copy link
Member Author

@julienduchesne julienduchesne May 31, 2022

Choose a reason for hiding this comment

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

It does not. It just appends the directory and the untardir together and then also appends the chart's name. Which is completely weird IMO, untardir serves no purpose at all. And it's one of the reasons I decided to actually use Helm in the tests, it tests the unexpected behaviors of the helm CLI like this

@jvrplmlmn
Copy link
Contributor

For completeness, I have checked out this branch and run a couple of manual tests, this is pretty neat 👍

✅ Vendoring 2 different versions of the same chart to 2 different locations:

tk tool charts init
tk tool charts add-repo flagger https://flagger.app
tk tool charts add flagger/flagger@1.16.1:flagger-1.16.1
tk tool charts add flagger/flagger@1.21.0:flagger-1.21.0
tk tool charts vendor

✅ Vendoring the same version of a chart to the default and a custom locations:

tk tool charts init
tk tool charts add-repo flagger https://flagger.app
tk tool charts add flagger/flagger@1.16.1
tk tool charts add flagger/flagger@1.16.1:flagger-1.16.1
tk tool charts vendor

@julienduchesne
Copy link
Member Author

For completeness, I have checked out this branch and run a couple of manual tests, this is pretty neat 👍

✅ Vendoring 2 different versions of the same chart to 2 different locations:

tk tool charts init
tk tool charts add-repo flagger https://flagger.app
tk tool charts add flagger/flagger@1.16.1:flagger-1.16.1
tk tool charts add flagger/flagger@1.21.0:flagger-1.21.0
tk tool charts vendor

✅ Vendoring the same version of a chart to the default and a custom locations:

tk tool charts init
tk tool charts add-repo flagger https://flagger.app
tk tool charts add flagger/flagger@1.16.1
tk tool charts add flagger/flagger@1.16.1:flagger-1.16.1
tk tool charts vendor

👍
There's still the bug that you can vendor to the same directory twice, but that's pre-existing. I plan to fix that in another PR and then add a prune setting and we'll have a full reconciling command that we can call in CI to check if we're up-to-date

Copy link
Contributor

@jvrplmlmn jvrplmlmn left a comment

Choose a reason for hiding this comment

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

A suggestion for pkg/helm/charts.go (lines 117 and 120 on the new diff):

log.Printf(" %s@%s exists", r.Chart, r.Version.String())
log.Printf("Removing %s@%s", r.Chart, r.Version.String())

Could we include there r.Directory?

Currently, on the second scenario described here: #706 (comment)

You get:

$ tk tool charts vendor
Pulling Charts ...
 flagger/flagger@1.16.1 exists
 flagger/flagger@1.16.1 exists

so is not clear to which one is referring to.

@julienduchesne julienduchesne requested a review from a team June 1, 2022 10:40
Copy link
Contributor

@jvrplmlmn jvrplmlmn left a comment

Choose a reason for hiding this comment

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

LG2M

pkg/helm/spec.go Outdated
@@ -64,6 +66,14 @@ type Requirement struct {
Directory string `json:"directory,omitempty"`
}

func (r Requirement) String() string {
s := r.Chart + "@" + r.Version.String()
if r.Directory != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We are building Requirement via parseReq, which already splits the repo/name from the version. If Requirement would have RepoName and ChartName instead of Chart, we could also infer here the default directory (is ChartName).

directory: charts
repositories:
- name: stable
  url: https://charts.helm.sh/stable
- name: flagger
  url: https://flagger.app
requires:
- chart: flagger/flagger
  version: 1.16.1
version: 1

crates the chart under charts/flagger

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, also the call to helm show I was doing just to get the chart name was unnecessary. Thanks

The chart name is the second part of the chart (repo/name)
@julienduchesne julienduchesne merged commit 0428803 into main Jun 1, 2022
@julienduchesne julienduchesne deleted the julienduchesne/helm-dir branch June 1, 2022 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants