Skip to content

Commit

Permalink
chore: add skip_crds parameter to helm functions
Browse files Browse the repository at this point in the history
Signed-off-by: kahirokunn <[email protected]>
  • Loading branch information
kahirokunn committed Jul 27, 2023
1 parent 15d2387 commit 6b08e0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/tiltfile/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def kustomize(pathToDir: str, kustomize_bin: str = None, flags: List[str] = [])
"""
pass

def helm(pathToChartDir: str, name: str = "", namespace: str = "", values: Union[str, List[str]]=[], set: Union[str, List[str]]=[], kube_version: str = "") -> Blob:
def helm(pathToChartDir: str, name: str = "", namespace: str = "", values: Union[str, List[str]]=[], set: Union[str, List[str]]=[], kube_version: str = "", skip_crds: bool = False) -> Blob:
"""Run `helm template <https://docs.helm.sh/helm/#helm-template>`_ on a given directory that contains a chart and return the fully rendered YAML as a Blob
Chart directory is watched (See ``watch_file``).
Expand All @@ -734,6 +734,7 @@ def helm(pathToChartDir: str, name: str = "", namespace: str = "", values: Union
values: Specify one or more values files (in addition to the `values.yaml` file in the chart). Equivalent to the Helm ``--values`` or ``-f`` flags (`see docs <https://helm.sh/docs/chart_template_guide/#values-files>`_).
set: Specify one or more values. Equivalent to the Helm ``--set`` flag.
kube_version: Specify for which kubernetes version template will be generated. Equivalent to the Helm ``--kube-version`` flag.
skip_crds: If set, no CRDs will be installed. By default, CRDs are installed.
"""
pass

Expand Down
10 changes: 7 additions & 3 deletions internal/tiltfile/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func (s *tiltfileState) helm(thread *starlark.Thread, fn *starlark.Builtin, args
var valueFiles value.StringOrStringList
var set value.StringOrStringList
var kubeVersion string
var skip_crds bool

err := s.unpackArgs(fn.Name(), args, kwargs,
"paths", &path,
Expand All @@ -204,6 +205,7 @@ func (s *tiltfileState) helm(thread *starlark.Thread, fn *starlark.Builtin, args
"values?", &valueFiles,
"set?", &set,
"kube_version?", &kubeVersion,
"skip_crds?", &skip_crds,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -251,9 +253,7 @@ func (s *tiltfileState) helm(thread *starlark.Thread, fn *starlark.Builtin, args
name = "chart"
}

if version == helmV3_1andAbove {
cmd = []string{"helm", "template", name, localPath, "--include-crds"}
} else if version == helmV3_0 {
if version == helmV3_0 || version == helmV3_1andAbove {
cmd = []string{"helm", "template", name, localPath}
} else {
cmd = []string{"helm", "template", localPath, "--name", name}
Expand All @@ -267,6 +267,10 @@ func (s *tiltfileState) helm(thread *starlark.Thread, fn *starlark.Builtin, args
cmd = append(cmd, "--kube-version", kubeVersion)
}

if !skip_crds && version == helmV3_1andAbove {
cmd = append(cmd, "--include-crds")
}

for _, valueFile := range valueFiles.Values {
cmd = append(cmd, "--values", valueFile)
err := tiltfile_io.RecordReadPath(thread, tiltfile_io.WatchFileOnly, starkit.AbsPath(thread, valueFile))
Expand Down

0 comments on commit 6b08e0d

Please sign in to comment.