Skip to content

Commit

Permalink
platform: allow CLC templating for dynamic IP address insertion
Browse files Browse the repository at this point in the history
The tests that require coreos-metadata and CLC templating could not
run because for QEMU only a static replacement was done before the
CLC configuration was rendered.
Add support for the template variables by treating QEMU as a custom
platform for the transpiler, making use of a coreos-metadata service
that has the IP addresses hardcoded.
  • Loading branch information
pothos committed Apr 19, 2021
1 parent b4ef818 commit 6ddb597
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion platform/local/flight.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewLocalFlight(opts *platform.Options, platformName platform.Name) (*LocalF
}

nsdialer := network.NewNsDialer(nshandle)
bf, err := platform.NewBaseFlightWithDialer(opts, platformName, "", nsdialer)
bf, err := platform.NewBaseFlightWithDialer(opts, platformName, "custom", nsdialer)
if err != nil {
nshandle.Close()
return nil, fmt.Errorf("creating new base flight failed: %v", err)
Expand Down
16 changes: 14 additions & 2 deletions platform/machine/qemu/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,27 @@ func (qc *Cluster) NewMachineWithOptions(userdata *conf.UserData, options platfo
ip := strings.Split(netif.DHCPv4[0].String(), "/")[0]

conf, err := qc.RenderUserData(userdata, map[string]string{
"$public_ipv4": ip,
"$private_ipv4": ip,
"$public_ipv4": "${COREOS_CUSTOM_PUBLIC_IPV4}",
"$private_ipv4": "${COREOS_CUSTOM_PRIVATE_IPV4}",
})
if err != nil {
qc.mu.Unlock()
return nil, err
}
qc.mu.Unlock()

conf.AddSystemdUnit("coreos-metadata.service", `[Unit]
Description=QEMU metadata agent
After=nss-lookup.target
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
Environment=OUTPUT=/run/metadata/coreos
ExecStart=/usr/bin/mkdir --parent /run/metadata
ExecStart=/usr/bin/bash -c 'echo "COREOS_CUSTOM_PRIVATE_IPV4=` + ip + `\nCOREOS_CUSTOM_PUBLIC_IPV4=` + ip + `\n" > ${OUTPUT}'`, false)

var confPath string
if conf.IsIgnition() {
confPath = filepath.Join(dir, "ignition.json")
Expand Down

0 comments on commit 6ddb597

Please sign in to comment.