Skip to content

Commit 52a73e3

Browse files
committed
Allow for relocation of values without set 'registry' and 'tag'
A lot of established helm charts: - Do not separate image refs into 'registry' and 'repository' - Use '.Chart.appVersion' by default if 'tag' is not specified For example, see Helm charts for: cert-manager, external-dns, opentelemetry-operator This change should allow for relocating values files for charts that use 'repository' as a complete image ref. I.e. 'repository: quay.io/jetstack/cert-manager-cainjector'
1 parent 55b97d0 commit 52a73e3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/bin/
22
/dist/
33
/examples/
4+
/.vscode/
45
**~
56
**.tgz
67
/out/

pkg/chartutils/values.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"path/filepath"
7+
"slices"
78

89
"github.com/google/go-containerregistry/pkg/name"
910
"github.com/vmware-labs/distribution-tooling-for-helm/pkg/utils"
@@ -123,8 +124,12 @@ func (v *ValuesImageElement) Relocate(prefix string) error {
123124
return fmt.Errorf("failed to parse relocated URL: %v", err)
124125
}
125126

126-
v.Registry = newRef.Context().Registry.RegistryStr()
127-
v.Repository = newRef.Context().RepositoryStr()
127+
if slices.Contains(v.foundFields, "registry") {
128+
v.Registry = newRef.Context().Registry.RegistryStr()
129+
v.Repository = newRef.Context().RepositoryStr()
130+
} else {
131+
v.Repository = newRef.Context().Name()
132+
}
128133
return nil
129134
}
130135

@@ -185,6 +190,14 @@ func parseValuesImageElement(data map[string]interface{}) *ValuesImageElement {
185190
if k == "digest" {
186191
continue
187192
}
193+
// repository element might contain registry url
194+
if k == "registry" {
195+
continue
196+
}
197+
// tag may be implicitly set to .Chart.appVersion
198+
if k == "tag" {
199+
continue
200+
}
188201
return nil
189202
}
190203
vStr, ok := v.(string)

0 commit comments

Comments
 (0)