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: default to use a temporary directory for applying helm charts #4384

Merged
merged 2 commits into from
Jun 24, 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
31 changes: 30 additions & 1 deletion pkg/cmd/step/helm/step_helm_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type StepHelmApplyOptions struct {
Force bool
DisableHelmVersion bool
Vault bool
UseTempDir bool
}

var (
Expand Down Expand Up @@ -81,6 +82,7 @@ func NewCmdStepHelmApply(commonOpts *opts.CommonOptions) *cobra.Command {
cmd.Flags().BoolVarP(&options.Force, "force", "f", true, "Whether to to pass '--force' to helm to help deal with upgrading if a previous promote failed")
cmd.Flags().BoolVar(&options.DisableHelmVersion, "no-helm-version", false, "Don't set Chart version before applying")
cmd.Flags().BoolVarP(&options.Vault, "vault", "", false, "Helm secrets are stored in vault")
cmd.Flags().BoolVarP(&options.UseTempDir, "use-temp-dir", "", true, "Whether to build and apply the helm chart from a temporary directory - to avoid updating the local values.yaml file from the generated file as part of the apply which could get accidentally checked into git")

return cmd
}
Expand Down Expand Up @@ -155,8 +157,35 @@ func (o *StepHelmApplyOptions) Run() error {
}
}
}

info := util.ColorInfo

path, err := filepath.Abs(dir)
if err != nil {
return errors.Wrapf(err, "could not find absolute path of dir %s", dir)
}
dir = path

if o.UseTempDir {
rootTmpDir, err := ioutil.TempDir("", "jx-helm-apply-")
if err != nil {
return errors.Wrapf(err, "failed to create a temporary directory to apply the helm chart")
}
defer os.RemoveAll(rootTmpDir)

// lets use the same child dir name as the original as helm is quite particular about the name of the directory it runs from
_, name := filepath.Split(dir)
if name == "" {
return fmt.Errorf("could not find the relative name of the directory %s", dir)
}
tmpDir := filepath.Join(rootTmpDir, name)
log.Logger().Infof("Copying the helm source directory %s to a temporary location for building and applying %s\n", info(dir), info(tmpDir))

err = util.CopyDir(dir, tmpDir, false)
if err != nil {
return errors.Wrapf(err, "failed to copy helm dir %s to temporary dir %s", dir, tmpDir)
}
dir = tmpDir
}
log.Logger().Infof("Applying helm chart at %s as release name %s to namespace %s", info(dir), info(releaseName), info(ns))

o.Helm().SetCWD(dir)
Expand Down
2 changes: 1 addition & 1 deletion pkg/spring/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
OptionDependencyKind = "kind"
OptionType = "type"

startSpringURL = "http://start.spring.io"
startSpringURL = "https://start.spring.io"
)

var (
Expand Down