Skip to content

Commit 7c311e2

Browse files
authored
add kustomize template function 'componentDigest' (#350)
1 parent c17db25 commit 7c311e2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/manifests/kustomize/generator.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func NewKustomizeGenerator(fsys fs.FS, kustomizationPath string, _ client.Client
161161
Funcs(templatex.FuncMapForTemplate(nil)).
162162
Funcs(templatex.FuncMapForLocalClient(nil)).
163163
Funcs(templatex.FuncMapForClient(nil)).
164-
Funcs(funcMapForGenerateContext(nil, nil, nil, nil, "", ""))
164+
Funcs(funcMapForGenerateContext(nil, nil, nil, nil, "", "", ""))
165165
} else {
166166
t = t.New(name)
167167
}
@@ -218,6 +218,10 @@ func (g *KustomizeGenerator) Generate(ctx context.Context, namespace string, nam
218218
if err != nil {
219219
return nil, err
220220
}
221+
componentDigest, err := component.ComponentDigestFromContext(ctx)
222+
if err != nil {
223+
return nil, err
224+
}
221225
component, err := component.ComponentFromContext(ctx)
222226
if err != nil {
223227
return nil, err
@@ -252,7 +256,7 @@ func (g *KustomizeGenerator) Generate(ctx context.Context, namespace string, nam
252256
Funcs(templatex.FuncMapForTemplate(t0)).
253257
Funcs(templatex.FuncMapForLocalClient(localClient)).
254258
Funcs(templatex.FuncMapForClient(clnt)).
255-
Funcs(funcMapForGenerateContext(g.files, serverVersion, serverGroupsWithResources, component, namespace, name))
259+
Funcs(funcMapForGenerateContext(g.files, serverVersion, serverGroupsWithResources, component, componentDigest, namespace, name))
256260
}
257261
var buf bytes.Buffer
258262
// TODO: templates (accidentally or intentionally) could modify data, or even some of the objects supplied through builtin functions;
@@ -311,14 +315,15 @@ func (g *KustomizeGenerator) Generate(ctx context.Context, namespace string, nam
311315
return objects, nil
312316
}
313317

314-
func funcMapForGenerateContext(files map[string][]byte, serverInfo *version.Info, serverGroupsWithResources []*metav1.APIResourceList, component component.Component, namespace string, name string) template.FuncMap {
318+
func funcMapForGenerateContext(files map[string][]byte, serverInfo *version.Info, serverGroupsWithResources []*metav1.APIResourceList, component component.Component, componentDigest string, namespace string, name string) template.FuncMap {
315319
return template.FuncMap{
316320
// TODO: maybe it would it be better to convert component to unstructured;
317321
// then calling methods would no longer be possible, and attributes would be in lowercase
318322
"listFiles": makeFuncListFiles(files),
319323
"existsFile": makeFuncExistsFile(files),
320324
"readFile": makeFuncReadFile(files),
321325
"component": makeFuncData(component),
326+
"componentDigest": func() string { return componentDigest },
322327
"namespace": func() string { return namespace },
323328
"name": func() string { return name },
324329
"kubernetesVersion": func() *version.Info { return serverInfo },

0 commit comments

Comments
 (0)