Skip to content

Commit e2475ca

Browse files
Change custom component template suffix from .template to .tpl (#244)
Extract the template suffix into a central `TemplateSuffix` constant in `pkg/registry` and switch the default from `.template` to `.tpl`
1 parent a6d3b1c commit e2475ca

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

docs/usage/custom-ocm-components.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ But if your component is backed by an OCM component descriptor, you can benefit
99

1010
1. The component directory contains a file named `component-name` containing the OCM component name (e.g. `my.private-github.com/gardener/my-gardener-extension`).
1111
2. The custom component must be included in the OCM descriptor tree. This means it must be referenced by the root component descriptor or any component referenced directly or indirectly.
12-
3. The component directory contains template files with suffix `.template` (e.g. `my-extension-deployment.yaml.template`). It can reference values for resources or image vector overrides as extracted from the OCM component descriptor.
12+
3. The component directory contains template files with suffix `.tpl` (e.g. `my-extension-deployment.yaml.tpl`). It can reference values for resources or image vector overrides as extracted from the OCM component descriptor.
1313

1414
### How it works
1515

@@ -43,7 +43,7 @@ ocm:
4343
```
4444
components/my-gardener-extension
4545
├── component-name
46-
├── my-extension-deployment.yaml.template
46+
├── my-extension-deployment.yaml.tpl
4747
├── kustomization.yaml
4848
...
4949
```
@@ -60,7 +60,7 @@ glk resolve ocm -c landscapekitconfiguration.yaml --target-dir /path/to/landscap
6060

6161
4. Make use of the extracted resource information stored in the file `ocm-components.yaml`.
6262

63-
If your component is a gardener extension, the `my-extension-deployment.yaml.template` may look like this:
63+
If your component is a gardener extension, the `my-extension-deployment.yaml.tpl` may look like this:
6464
```yaml
6565
apiVersion: operator.gardener.cloud/v1alpha1
6666
kind: Extension

pkg/registry/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
const (
2020
// CustomComponentNameFilename is the filename containing a custom OCM component name.
2121
CustomComponentNameFilename = "component-name"
22+
// TemplateSuffix is the file extension used to identify custom component template files.
23+
TemplateSuffix = ".tpl"
2224
)
2325

2426
// Interface is the interface for a component registry.
@@ -92,7 +94,7 @@ func (r *registry) renderCustomComponents(ocmComponentName, componentDir string,
9294
if err != nil {
9395
return err
9496
}
95-
if info.IsDir() || !strings.HasSuffix(info.Name(), ".template") {
97+
if info.IsDir() || !strings.HasSuffix(info.Name(), TemplateSuffix) {
9698
return nil
9799
}
98100
content, err := opts.GetFilesystem().ReadFile(path)
@@ -107,7 +109,7 @@ func (r *registry) renderCustomComponents(ocmComponentName, componentDir string,
107109
if err != nil {
108110
return fmt.Errorf("error rendering template file %s for custom component %s: %w", path, ocmComponentName, err)
109111
}
110-
targetFile := strings.TrimSuffix(path, ".template")
112+
targetFile := strings.TrimSuffix(path, TemplateSuffix)
111113
if err := opts.GetFilesystem().WriteFile(targetFile, renderedContent, 0600); err != nil {
112114
return fmt.Errorf("error writing rendered template file %s for custom component %s: %w", targetFile, ocmComponentName, err)
113115
}

0 commit comments

Comments
 (0)