Skip to content

Commit

Permalink
feat: set local chart version using --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoltzsche committed Oct 18, 2022
1 parent 0d1b29e commit 2965850
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions e2e/cli-tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ teardown() {
--debug
}

@test "CLI should build local chart" {
docker run --rm -u $(id -u):$(id -g) -v "$OUT_DIR:/out" -v "$EXAMPLE_DIR/release-name:/chart" "$IMAGE" template /chart \
--version 1.2.3 \
--output /out/manifest.yaml \
--debug
ls -la "$OUT_DIR" "$OUT_DIR/manifest.yaml" >&2
cat "$OUT_DIR/manifest.yaml" | tee /dev/stdout /dev/stderr | grep -q 'chartVersion: 1.2.3'
}

@test "CLI should output kustomization" {
docker run --rm -u $(id -u):$(id -g) -v "$OUT_DIR:/out" -v "$EXAMPLE_DIR/namespace:/chart" "$IMAGE" template /chart \
--output /out/kdir/ \
Expand Down
1 change: 1 addition & 0 deletions example/release-name/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ metadata:
name: my-release-name
chart: .
kubeVersion: 1.17
version: 1.9.3
1 change: 1 addition & 0 deletions example/release-name/templates/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ metadata:
data:
key: b
k8sVersion: {{ .Capabilities.KubeVersion }}
chartVersion: {{ .Chart.Version }}
3 changes: 3 additions & 0 deletions pkg/helm/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func buildAndLoadLocalChart(ctx context.Context, cfg *config.ChartConfig, repos
return nil, errors.Wrapf(err, "failed reloading chart %s after dependency download", cfg.Chart)
}
}
if cfg.Version != "" {
chartRequested.Metadata.Version = cfg.Version
}
return chartRequested, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/helm/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestRender(t *testing.T) {
{"force-namespace", "example/force-namespace/generator.yaml", []string{"forced-namespace"}, " key: b", nil},
{"kubeVersion", "example/release-name/generator.yaml", []string{}, " k8sVersion: v1.17.0", nil},
{"release-name", "example/release-name/generator.yaml", []string{}, " name: my-release-name-config", nil},
{"chart-version", "example/release-name/generator.yaml", []string{}, " chartVersion: 1.9.3", nil},
{"exclude", "example/exclude/generator.yaml", []string{"cluster-role-binding-ns"}, " key: b", nil},
{"include", "example/include/generator.yaml", []string{}, " key: b", nil},
{"local-chart-with-local-dependency-and-transitive-remote", "example/localrefref/generator.yaml", []string{}, "rook-ceph-v0.9.3", nil},
Expand Down

0 comments on commit 2965850

Please sign in to comment.