Files
podman/pkg/machine/applehv/ignition.go
Brent Baude a45ba06d02 Refactor key machine objects
In #20538, I was asked to consider refactoring the new OCI pull code
from within the generic machine directory.  This is something I had
tried when originally coding it but it became apparent that a much
larger refactor to prevent circular deps was needed.  Because I did not
want to pollute the initial PR with that refactor, I asked for the PR to
merge first.  This is the refactor that needed to be done.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-11-07 08:30:44 -06:00

41 lines
1.0 KiB
Go

//go:build darwin
// +build darwin
package applehv
import (
"net"
"net/http"
"github.com/containers/podman/v4/pkg/machine/define"
"github.com/sirupsen/logrus"
)
// serveIgnitionOverSock allows podman to open a small httpd instance on the vsock between the host
// and guest to inject the ignitionfile into fcos
func (m *MacMachine) serveIgnitionOverSock(ignitionSocket *define.VMFile) error {
logrus.Debugf("reading ignition file: %s", m.IgnitionFile.GetPath())
ignFile, err := m.IgnitionFile.Read()
if err != nil {
return err
}
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write(ignFile)
if err != nil {
logrus.Error("failed to serve ignition file: %v", err)
}
})
listener, err := net.Listen("unix", ignitionSocket.GetPath())
if err != nil {
return err
}
logrus.Debugf("ignition socket device: %s", ignitionSocket.GetPath())
defer func() {
if err := listener.Close(); err != nil {
logrus.Error(err)
}
}()
return http.Serve(listener, mux)
}