Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config/types/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
package types

import (
"strings"

ignTypes "github.com/coreos/ignition/config/v2_0/types"
"github.com/coreos/ignition/config/validate"
"github.com/coreos/ignition/config/validate/report"

"github.com/coreos/container-linux-config-transpiler/config/templating"
)

type Systemd struct {
Expand All @@ -40,6 +44,13 @@ type SystemdUnitDropIn struct {
func init() {
register2_0(func(in Config, ast validate.AstNode, out ignTypes.Config, platform string) (ignTypes.Config, report.Report, validate.AstNode) {
for _, unit := range in.Systemd.Units {
if templating.HasTemplating([]string{unit.Contents}) {
contents, err := templating.PerformTemplating(platform, []string{unit.Contents})
if err != nil {
return out, report.Report{}, ast
}
unit.Contents = strings.Join(contents, "\n")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If templating is used, the units must also have:

Requires=coreos-metadata.service
After=coreos-metadata.service
EnvironmentFile=/run/metadata/coreos

Here's where these lines are added for the generated units:

out.Unit.Add("Requires=coreos-metadata.service")

Unfortunately users may have added these lines themselves to their units, so you should probably check for those. Maybe modify types/util/UnitSection.Add to check for preexisting matching keys, and to blow them away before appending the new value.

newUnit := ignTypes.SystemdUnit{
Name: ignTypes.SystemdUnitName(unit.Name),
Enable: unit.Enable,
Expand All @@ -48,6 +59,13 @@ func init() {
}

for _, dropIn := range unit.DropIns {
if templating.HasTemplating([]string{dropIn.Contents}) {
contents, err := templating.PerformTemplating(platform, []string{dropIn.Contents})
if err != nil {
return out, report.Report{}, ast
}
dropIn.Contents = strings.Join(contents, "\n")
}
newUnit.DropIns = append(newUnit.DropIns, ignTypes.SystemdUnitDropIn{
Name: ignTypes.SystemdUnitDropInName(dropIn.Name),
Contents: dropIn.Contents,
Expand Down