mirror of
https://github.com/containers/podman.git
synced 2025-06-22 01:48:54 +08:00
consolidate ignition ready socket unit
consolidated ignition ready unit file content into one function. [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -267,7 +267,7 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
readyUnitFile, err := createReadyUnitFile()
|
readyUnitFile, err := ignition.CreateReadyUnitFile(define.AppleHvVirt, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -286,13 +286,6 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) {
|
|||||||
return err == nil, err
|
return err == nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createReadyUnitFile() (string, error) {
|
|
||||||
readyUnit := ignition.DefaultReadyUnitFile()
|
|
||||||
readyUnit.Add("Unit", "Requires", "dev-virtio\\x2dports-vsock.device")
|
|
||||||
readyUnit.Add("Service", "ExecStart", "/bin/sh -c '/usr/bin/echo Ready | socat - VSOCK-CONNECT:2:1025'")
|
|
||||||
return readyUnit.ToString()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MacMachine) removeSystemConnections() error {
|
func (m *MacMachine) removeSystemConnections() error {
|
||||||
return machine.RemoveConnections(m.Name, fmt.Sprintf("%s-root", m.Name))
|
return machine.RemoveConnections(m.Name, fmt.Sprintf("%s-root", m.Name))
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,8 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
readyUnitFile, err := createReadyUnit(m.ReadyHVSock.Port)
|
readyOpts := ignition.ReadyUnitOpts{Port: m.ReadyHVSock.Port}
|
||||||
|
readyUnitFile, err := ignition.CreateReadyUnitFile(define.HyperVVirt, &readyOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -293,13 +294,6 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) {
|
|||||||
return err == nil, err
|
return err == nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createReadyUnit(readyPort uint64) (string, error) {
|
|
||||||
readyUnit := ignition.DefaultReadyUnitFile()
|
|
||||||
readyUnit.Add("Unit", "After", "systemd-user-sessions.service")
|
|
||||||
readyUnit.Add("Service", "ExecStart", fmt.Sprintf("/bin/sh -c '/usr/bin/echo Ready | socat - VSOCK-CONNECT:2:%d'", readyPort))
|
|
||||||
return readyUnit.ToString()
|
|
||||||
}
|
|
||||||
|
|
||||||
func createNetworkUnit(netPort uint64) (string, error) {
|
func createNetworkUnit(netPort uint64) (string, error) {
|
||||||
netUnit := parser.NewUnitFile()
|
netUnit := parser.NewUnitFile()
|
||||||
netUnit.Add("Unit", "Description", "vsock_network")
|
netUnit.Add("Unit", "Description", "vsock_network")
|
||||||
|
39
pkg/machine/ignition/ready.go
Normal file
39
pkg/machine/ignition/ready.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package ignition
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/containers/podman/v4/pkg/machine/define"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadyUnitOpts are options for creating the ready unit that reports back to podman
|
||||||
|
// when the system is booted
|
||||||
|
type ReadyUnitOpts struct {
|
||||||
|
Port uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateReadyUnitFile makes a the ready unit to report back to the host that the system is running
|
||||||
|
func CreateReadyUnitFile(provider define.VMType, opts *ReadyUnitOpts) (string, error) {
|
||||||
|
readyUnit := DefaultReadyUnitFile()
|
||||||
|
switch provider {
|
||||||
|
case define.QemuVirt:
|
||||||
|
readyUnit.Add("Unit", "Requires", "dev-virtio\\x2dports-vport1p1.device")
|
||||||
|
readyUnit.Add("Unit", "After", "systemd-user-sessions.service")
|
||||||
|
readyUnit.Add("Service", "ExecStart", "/bin/sh -c '/usr/bin/echo Ready >/dev/vport1p1'")
|
||||||
|
case define.AppleHvVirt:
|
||||||
|
readyUnit.Add("Unit", "Requires", "dev-virtio\\x2dports-vsock.device")
|
||||||
|
readyUnit.Add("Service", "ExecStart", "/bin/sh -c '/usr/bin/echo Ready | socat - VSOCK-CONNECT:2:1025'")
|
||||||
|
case define.HyperVVirt:
|
||||||
|
if opts == nil || opts.Port == 0 {
|
||||||
|
return "", errors.New("no port provided for hyperv ready unit")
|
||||||
|
}
|
||||||
|
readyUnit.Add("Unit", "After", "systemd-user-sessions.service")
|
||||||
|
readyUnit.Add("Service", "ExecStart", fmt.Sprintf("/bin/sh -c '/usr/bin/echo Ready | socat - VSOCK-CONNECT:2:%d'", opts.Port))
|
||||||
|
case define.WSLVirt: // WSL does not use ignition
|
||||||
|
return "", nil
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf("unable to generate ready unit for provider %q", provider.String())
|
||||||
|
}
|
||||||
|
return readyUnit.ToString()
|
||||||
|
}
|
@ -213,7 +213,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
readyUnitFile, err := createReadyUnitFile()
|
readyUnitFile, err := ignition.CreateReadyUnitFile(define.QemuVirt, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -230,14 +230,6 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
|
|||||||
return err == nil, err
|
return err == nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createReadyUnitFile() (string, error) {
|
|
||||||
readyUnit := ignition.DefaultReadyUnitFile()
|
|
||||||
readyUnit.Add("Unit", "Requires", "dev-virtio\\x2dports-vport1p1.device")
|
|
||||||
readyUnit.Add("Unit", "After", "systemd-user-sessions.service")
|
|
||||||
readyUnit.Add("Service", "ExecStart", "/bin/sh -c '/usr/bin/echo Ready >/dev/vport1p1'")
|
|
||||||
return readyUnit.ToString()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *MachineVM) removeSystemConnections() error {
|
func (v *MachineVM) removeSystemConnections() error {
|
||||||
return machine.RemoveConnections(v.Name, fmt.Sprintf("%s-root", v.Name))
|
return machine.RemoveConnections(v.Name, fmt.Sprintf("%s-root", v.Name))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user