mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-22 09:39:39 +02:00
Add the ability to specify a lock file (#432)
Allow configuring the lockfile in the state. This makes it possible for example maintain a lock per environment. Signed-off-by: Lassi Pölönen <lassi.polonen@iki.fi> Signed-off-by: Lassi Pölönen <lassi.polonen@iki.fi>
This commit is contained in:
@@ -134,13 +134,8 @@ func TestHelmfileTemplateWithBuildCommand(t *testing.T) {
|
||||
if !c.IsDir() {
|
||||
t.Fatalf("%s is not a directory", c)
|
||||
}
|
||||
chartName, chartVersion := execHelmShowChart(t, chartPath)
|
||||
tgzFile := execHelmPackage(t, chartPath)
|
||||
|
||||
// Extract chart version from the name of chart package archival
|
||||
chartName := c.Name()
|
||||
chartNameWithVersion := strings.TrimSuffix(filepath.Base(tgzFile), filepath.Ext(tgzFile))
|
||||
chartVersion := strings.TrimPrefix(chartNameWithVersion, fmt.Sprintf("%s-", chartName))
|
||||
|
||||
chartDigest, err := execHelmPush(t, tgzFile, fmt.Sprintf("oci://localhost:%d/myrepo", hostPort))
|
||||
require.NoError(t, err, "Unable to run helm push to local registry: %v", err)
|
||||
|
||||
@@ -235,6 +230,23 @@ func execDocker(t *testing.T, args ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
func execHelmShowChart(t *testing.T, localChart string) (string, string) {
|
||||
t.Helper()
|
||||
|
||||
name, version := "", ""
|
||||
out := execHelm(t, "show", "chart", localChart)
|
||||
sc := bufio.NewScanner(strings.NewReader(out))
|
||||
for sc.Scan() {
|
||||
if strings.HasPrefix(sc.Text(), "name:") {
|
||||
name = strings.TrimPrefix(sc.Text(), "name: ")
|
||||
}
|
||||
if strings.HasPrefix(sc.Text(), "version:") {
|
||||
version = strings.TrimPrefix(sc.Text(), "version: ")
|
||||
}
|
||||
}
|
||||
return name, version
|
||||
}
|
||||
|
||||
func execHelmPackage(t *testing.T, localChart string) string {
|
||||
t.Helper()
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
apiVersion: v2
|
||||
name: raw
|
||||
description: A Helm chart for Kubernetes
|
||||
type: application
|
||||
version: 0.0.1
|
||||
appVersion: "1.16.0"
|
||||
@@ -0,0 +1 @@
|
||||
A copy of chart ../raw, but older version to test locking.
|
||||
@@ -0,0 +1 @@
|
||||
*.tgz
|
||||
@@ -0,0 +1,23 @@
|
||||
# Patterns to ignore when building packages.
|
||||
# This supports shell glob matching, relative path matching, and
|
||||
# negation (prefixed with !). Only one pattern per line.
|
||||
.DS_Store
|
||||
# Common VCS dirs
|
||||
.git/
|
||||
.gitignore
|
||||
.bzr/
|
||||
.bzrignore
|
||||
.hg/
|
||||
.hgignore
|
||||
.svn/
|
||||
# Common backup files
|
||||
*.swp
|
||||
*.bak
|
||||
*.tmp
|
||||
*.orig
|
||||
*~
|
||||
# Various IDEs
|
||||
.project
|
||||
.idea/
|
||||
*.tmproj
|
||||
.vscode/
|
||||
@@ -0,0 +1,6 @@
|
||||
{{- range $i, $r := $.Values.templates }}
|
||||
{{- if gt $i 0 }}
|
||||
---
|
||||
{{- end }}
|
||||
{{- (tpl $r $) }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,48 @@
|
||||
templates: []
|
||||
|
||||
##
|
||||
## Example: Uncomment the below and run `helm template ./`:
|
||||
##
|
||||
#
|
||||
# templates:
|
||||
# - |
|
||||
# apiVersion: v1
|
||||
# kind: ConfigMap
|
||||
# metadata:
|
||||
# name: {{ .Release.Name }}-1
|
||||
# namespace: {{ .Release.Namespace }}
|
||||
# data:
|
||||
# foo: {{ .Values.foo }}
|
||||
# - |
|
||||
# apiVersion: v1
|
||||
# kind: ConfigMap
|
||||
# metadata:
|
||||
# name: {{ .Release.Name }}-2
|
||||
# namespace: {{ .Release.Namespace }}
|
||||
# data:
|
||||
# foo: {{ .Values.foo }}
|
||||
# values:
|
||||
# foo: FOO
|
||||
#
|
||||
##
|
||||
## Expected Output:
|
||||
##
|
||||
#
|
||||
# ---
|
||||
# # Source: raw/templates/resources.yaml
|
||||
# apiVersion: v1
|
||||
# kind: ConfigMap
|
||||
# metadata:
|
||||
# name: release-name-1
|
||||
# namespace: default
|
||||
# data:
|
||||
# foo:
|
||||
# ---
|
||||
# # Source: raw/templates/resources.yaml
|
||||
# apiVersion: v1
|
||||
# kind: ConfigMap
|
||||
# metadata:
|
||||
# name: release-name-2
|
||||
# namespace: default
|
||||
# data:
|
||||
# foo:
|
||||
@@ -4,7 +4,7 @@ repositories:
|
||||
|
||||
releases:
|
||||
- name: foo
|
||||
chart: ../../charts/raw
|
||||
chart: ../../charts/raw-0.1.0
|
||||
values:
|
||||
- templates:
|
||||
- |
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ repositories:
|
||||
|
||||
releases:
|
||||
- name: foo
|
||||
chart: ../../charts/raw
|
||||
chart: ../../charts/raw-0.1.0
|
||||
values:
|
||||
- templates:
|
||||
- |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
releases:
|
||||
- name: foo
|
||||
chart: ../../charts/raw
|
||||
chart: ../../charts/raw-0.1.0
|
||||
values:
|
||||
- templates:
|
||||
- |
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
localChartRepoServer:
|
||||
enabled: true
|
||||
port: 18080
|
||||
chartifyTempDir: temp1
|
||||
helmfileArgs:
|
||||
- --environment
|
||||
- prod
|
||||
- template
|
||||
@@ -0,0 +1,18 @@
|
||||
repositories:
|
||||
- name: myrepo
|
||||
url: http://localhost:18080/
|
||||
|
||||
environments:
|
||||
prod:
|
||||
staging:
|
||||
|
||||
---
|
||||
lockFilePath: test-lock-file-{{ .Environment.Name }}
|
||||
|
||||
releases:
|
||||
- name: raw
|
||||
chart: myrepo/raw
|
||||
values:
|
||||
- templates:
|
||||
- |
|
||||
chartVersion: {{`{{ .Chart.Version }}`}}
|
||||
@@ -0,0 +1,8 @@
|
||||
Adding repo myrepo http://localhost:18080/
|
||||
"myrepo" has been added to your repositories
|
||||
|
||||
Templating release=raw, chart=myrepo/raw
|
||||
---
|
||||
# Source: raw/templates/resources.yaml
|
||||
chartVersion: 0.0.1
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
version: 0.0.0-dev
|
||||
dependencies:
|
||||
- name: raw
|
||||
repository: http://localhost:18080/
|
||||
version: 0.0.1
|
||||
digest: sha256:5401817b653c4eeb186cbfbb8d77dda6b72f84a548fc9cd128cbd478d5b2e705
|
||||
generated: "2022-10-12T20:17:15.98786845+03:00"
|
||||
Reference in New Issue
Block a user