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

fix(cmd/deps): make helmfile deps to work w/ helm 3.0.0-beta.3 #842

Merged
merged 1 commit into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions pkg/state/chart_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,31 @@ func (m *chartDependencyManager) lockFileName() string {
}

func (m *chartDependencyManager) Update(shell helmexec.DependencyUpdater, wd string, unresolved *UnresolvedDependencies) (*ResolvedDependencies, error) {
if isHelm3() {
return m.updateHelm3(shell, wd, unresolved)
}
return m.updateHelm2(shell, wd, unresolved)
}

func (m *chartDependencyManager) updateHelm3(shell helmexec.DependencyUpdater, wd string, unresolved *UnresolvedDependencies) (*ResolvedDependencies, error) {
// Generate `Chart.yaml` of the temporary local chart
chartMetaContent := fmt.Sprintf("name: %s\nversion: 1.0.0\n", m.Name)

// Generate `requirements.yaml` of the temporary local chart from the helmfile state
reqsContent, err := yaml.Marshal(unresolved.ToChartRequirements())
if err != nil {
return nil, err
}
if err := m.writeBytes(filepath.Join(wd, "Chart.yaml"), []byte(chartMetaContent+string(reqsContent))); err != nil {
return nil, err
}

return m.doUpdate("Chart.lock", unresolved, shell, wd)
}

func (m *chartDependencyManager) updateHelm2(shell helmexec.DependencyUpdater, wd string, unresolved *UnresolvedDependencies) (*ResolvedDependencies, error) {
// Generate `Chart.yaml` of the temporary local chart
if err := m.writeBytes(filepath.Join(wd, "Chart.yaml"), []byte(fmt.Sprintf("name: %s\n", m.Name))); err != nil {
if err := m.writeBytes(filepath.Join(wd, "Chart.yaml"), []byte(fmt.Sprintf("name: %s\nversion: 1.0.0\n", m.Name))); err != nil {
return nil, err
}

Expand All @@ -292,6 +315,11 @@ func (m *chartDependencyManager) Update(shell helmexec.DependencyUpdater, wd str
return nil, err
}

return m.doUpdate("requirements.lock", unresolved, shell, wd)
}

func (m *chartDependencyManager) doUpdate(chartLockFile string, unresolved *UnresolvedDependencies, shell helmexec.DependencyUpdater, wd string) (*ResolvedDependencies, error) {

// Generate `requirements.lock` of the temporary local chart by coping `<basename>.lock`
lockFile := m.lockFileName()

Expand All @@ -301,7 +329,7 @@ func (m *chartDependencyManager) Update(shell helmexec.DependencyUpdater, wd str
}

if lockFileContent != nil {
if err := m.writeBytes(filepath.Join(wd, "requirements.lock"), lockFileContent); err != nil {
if err := m.writeBytes(filepath.Join(wd, chartLockFile), lockFileContent); err != nil {
return nil, err
}
}
Expand All @@ -311,7 +339,7 @@ func (m *chartDependencyManager) Update(shell helmexec.DependencyUpdater, wd str
return nil, err
}

updatedLockFileContent, err := m.readBytes(filepath.Join(wd, "requirements.lock"))
updatedLockFileContent, err := m.readBytes(filepath.Join(wd, chartLockFile))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ func (st *HelmState) DeleteReleases(affectedReleases *AffectedReleases, helm hel
}

flags := []string{}
if purge && !st.isHelm3() {
if purge && !isHelm3() {
flags = append(flags, "--purge")
}
flags = st.appendConnectionFlags(flags, &release)
Expand Down Expand Up @@ -931,7 +931,7 @@ func (st *HelmState) TestReleases(helm helmexec.Interface, cleanup bool, timeout
flags = append(flags, "--cleanup")
}
duration := strconv.Itoa(timeout)
if st.isHelm3() {
if isHelm3() {
duration += "s"
}
flags = append(flags, "--timeout", duration)
Expand All @@ -941,7 +941,7 @@ func (st *HelmState) TestReleases(helm helmexec.Interface, cleanup bool, timeout
})
}

func (st *HelmState) isHelm3() bool {
func isHelm3() bool {
return os.Getenv("HELMFILE_HELM3") != ""
}

Expand Down