diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..38989cf Binary files /dev/null and b/.DS_Store differ diff --git a/cmd/main.go b/cmd/main.go index 857f038..f873668 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,9 +2,13 @@ package main import ( "context" + "net" "net/http" "os" + "os/signal" "strconv" + "strings" + "syscall" "github.com/sirupsen/logrus" "github.com/virtual-kubelet/virtual-kubelet/log" @@ -61,9 +65,35 @@ func main() { mutex.HandleFunc("/create", SidecarAPIs.CreateHandler) mutex.HandleFunc("/delete", SidecarAPIs.DeleteHandler) mutex.HandleFunc("/getLogs", SidecarAPIs.GetLogsHandler) - err = http.ListenAndServe(":"+interLinkConfig.Sidecarport, mutex) - if err != nil { - log.G(Ctx).Fatal(err) + if strings.HasPrefix(interLinkConfig.Socket, "unix://") { + // Create a Unix domain socket and listen for incoming connections. + socket, err := net.Listen("unix", strings.ReplaceAll(interLinkConfig.Socket, "unix://", "")) + if err != nil { + panic(err) + } + + // Cleanup the sockfile. + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + go func() { + <-c + os.Remove(strings.ReplaceAll(interLinkConfig.Socket, "unix://", "")) + os.Exit(1) + }() + server := http.Server{ + Handler: mutex, + } + + log.G(Ctx).Info(socket) + + if err := server.Serve(socket); err != nil { + log.G(Ctx).Fatal(err) + } + } else { + err = http.ListenAndServe(":"+interLinkConfig.Sidecarport, mutex) + if err != nil { + log.G(Ctx).Fatal(err) + } } } diff --git a/pkg/.DS_Store b/pkg/.DS_Store new file mode 100644 index 0000000..0c88851 Binary files /dev/null and b/pkg/.DS_Store differ diff --git a/pkg/common/types.go b/pkg/common/types.go index 0810681..a0b0ff2 100644 --- a/pkg/common/types.go +++ b/pkg/common/types.go @@ -48,6 +48,7 @@ type InterLinkConfig struct { Scancelpath string `yaml:"ScancelPath"` Squeuepath string `yaml:"SqueuePath"` Interlinkport string `yaml:"InterlinkPort"` + Socket string `yaml:"Socket"` Sidecarport string `yaml:"SidecarPort"` Commandprefix string `yaml:"CommandPrefix"` ExportPodData bool `yaml:"ExportPodData"`