Skip to content

Commit 823716b

Browse files
authored
Merge pull request #56 from puzzle/enhance-lint
Assure all dependencies are present before linting
2 parents 12aa1da + c56879e commit 823716b

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

helm/main.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,14 @@ func (h *Helm) Lint(
187187
// +optional
188188
args []string,
189189
) (string, error) {
190-
c := h.createContainer(directory)
190+
var c *dagger.Container
191+
192+
if h.hasMissingDependencies(ctx, directory) {
193+
c = h.createContainer(directory).WithMountedDirectory("./charts", h.dependencyUpdate(directory))
194+
} else {
195+
c = h.createContainer(directory)
196+
}
197+
191198
out, err := c.WithExec([]string{"sh", "-c", fmt.Sprintf("%s %s", "helm lint", strings.Join(args, " "))}).Stdout(ctx)
192199
if err != nil {
193200
return "", err
@@ -196,6 +203,24 @@ func (h *Helm) Lint(
196203
return out, nil
197204
}
198205

206+
func (h *Helm) hasMissingDependencies(
207+
// method call context
208+
ctx context.Context,
209+
// directory that contains the Helm Chart
210+
directory *dagger.Directory,
211+
) bool {
212+
_, err := h.createContainer(directory).WithExec([]string{"sh", "-c", "helm dep list | grep missing"}).Stdout(ctx)
213+
return err == nil
214+
}
215+
216+
func (h *Helm) dependencyUpdate(
217+
// directory that contains the Helm Chart
218+
directory *dagger.Directory,
219+
) *dagger.Directory {
220+
c := h.createContainer(directory)
221+
return c.WithExec([]string{"sh", "-c", "helm dep update"}).Directory("charts")
222+
}
223+
199224
func (h *Helm) createContainer(
200225
// directory that contains the Helm Chart
201226
directory *dagger.Directory,

tests/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func (m *Go) All(ctx context.Context) error {
1919
p.Go(m.HelmLint)
2020
p.Go(m.HelmLintWithArg)
2121
p.Go(m.HelmLintWithArgs)
22+
p.Go(m.HelmLintWithMissingDependencies)
2223

2324
return p.Wait()
2425
}
@@ -123,3 +124,17 @@ func (m *Go) HelmLintWithArgs(
123124

124125
return nil
125126
}
127+
128+
func (m *Go) HelmLintWithMissingDependencies(
129+
// method call context
130+
ctx context.Context,
131+
) error {
132+
directory := dag.CurrentModule().Source().Directory("./testdata/mydependentchart/")
133+
_, err := dag.Helm().Lint(ctx, directory)
134+
135+
if err != nil {
136+
return err
137+
}
138+
139+
return nil
140+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: v2
2+
name: dagger-module-helm-test
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.1
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"
25+
26+
# This is an optional list containing all dependencies.
27+
dependencies:
28+
- name: dependency-track
29+
version: 1.8.1
30+
repository: https://puzzle.github.io/dependencytrack-helm/

0 commit comments

Comments
 (0)